Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify functions in preparation for PartiQL-PATH #1530

Merged
merged 7 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ import org.partiql.plan.Rex
import org.partiql.plan.Statement
import org.partiql.plan.debug.PlanPrinter
import org.partiql.plan.visitor.PlanBaseVisitor
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.FnExperimental
import org.partiql.planner.internal.fn.Agg
import org.partiql.types.PType
import org.partiql.value.PartiQLValueExperimental
import java.lang.IllegalStateException
Expand Down Expand Up @@ -179,7 +178,6 @@ internal class Compiler(
return RelAggregate(input, groups, calls)
}

@OptIn(FnExperimental::class)
override fun visitRelOpAggregateCall(node: Rel.Op.Aggregate.Call, ctx: PType?): Operator.Aggregation {
val args = node.args.map { visitRex(it, it.type).modeHandled() }
val setQuantifier: Operator.Aggregation.SetQuantifier = when (node.setQuantifier) {
Expand Down Expand Up @@ -212,7 +210,6 @@ internal class Compiler(
return ExprPathIndex(root, index)
}

@OptIn(FnExperimental::class)
override fun visitRexOpCallStatic(node: Rex.Op.Call.Static, ctx: PType?): Operator {
val fn = symbols.getFn(node.fn)
val args = node.args.map { visitRex(it, ctx) }.toTypedArray()
Expand All @@ -225,7 +222,6 @@ internal class Compiler(
}
}

@OptIn(FnExperimental::class)
override fun visitRexOpCallDynamic(node: Rex.Op.Call.Dynamic, ctx: PType?): Operator {
val args = node.args.map { visitRex(it, ctx).modeHandled() }.toTypedArray()
// Check candidate list size
Expand Down
23 changes: 10 additions & 13 deletions partiql-eval/src/main/kotlin/org/partiql/eval/internal/Symbols.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:OptIn(FnExperimental::class)

package org.partiql.eval.internal

Expand All @@ -7,30 +6,30 @@ import org.partiql.eval.internal.operator.rex.ExprVarGlobal
import org.partiql.plan.Catalog
import org.partiql.plan.PartiQLPlan
import org.partiql.plan.Ref
import org.partiql.spi.connector.ConnectorAggProvider
import org.partiql.planner.internal.fn.Agg
import org.partiql.planner.internal.fn.Fn
import org.partiql.planner.internal.fn.SqlFnProvider
import org.partiql.spi.connector.ConnectorBindings
import org.partiql.spi.connector.ConnectorFnProvider
import org.partiql.spi.connector.ConnectorPath
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.Fn
import org.partiql.spi.fn.FnExperimental

/**
*
*
* @property catalogs
*/
@OptIn(FnExperimental::class)

internal class Symbols private constructor(private val catalogs: Array<C>) {

private class C(
val name: String,
val bindings: ConnectorBindings,
val functions: ConnectorFnProvider,
val aggregations: ConnectorAggProvider,
val items: Array<Catalog.Item>,
) {

// TEMPORARY FOR DEPENDENCY REASONS
fun getFn(path: ConnectorPath, specific: String): Fn? = SqlFnProvider.getFn(specific)
fun getAgg(path: ConnectorPath, specific: String): Agg? = SqlFnProvider.getAgg(specific)

override fun toString(): String = name
}

Expand All @@ -52,7 +51,7 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
}
// Lookup in connector
val path = ConnectorPath(item.path)
return catalog.functions.getFn(path, item.specific)
return catalog.getFn(path, item.specific)
?: error("Catalog `$catalog` has no entry for function $item")
}

Expand All @@ -64,7 +63,7 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
}
// Lookup in connector
val path = ConnectorPath(item.path)
return catalog.aggregations.getAgg(path, item.specific)
return catalog.getAgg(path, item.specific)
?: error("Catalog `$catalog` has no entry for aggregation function $item")
}

Expand All @@ -85,8 +84,6 @@ internal class Symbols private constructor(private val catalogs: Array<C>) {
C(
name = it.name,
bindings = connector.getBindings(),
functions = connector.getFunctions(),
aggregations = connector.getAggregations(),
items = it.items.toTypedArray()
)
}.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package org.partiql.eval.internal.operator
import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.Record
import org.partiql.eval.value.Datum
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.FnExperimental
import org.partiql.value.PartiQLValueExperimental
import org.partiql.planner.internal.fn.Agg

internal sealed interface Operator {

Expand All @@ -14,7 +12,6 @@ internal sealed interface Operator {
*/
interface Expr : Operator {

@OptIn(PartiQLValueExperimental::class)
fun eval(env: Environment): Datum
}

Expand All @@ -30,7 +27,6 @@ internal sealed interface Operator {

interface Aggregation : Operator {

@OptIn(FnExperimental::class)
val delegate: Agg

val args: List<Expr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.Record
import org.partiql.eval.internal.operator.Operator
import org.partiql.eval.value.Datum
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.FnExperimental
import org.partiql.planner.internal.fn.Agg
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType
Expand Down Expand Up @@ -51,13 +50,13 @@ internal class RelAggregate(
*
* @property seen maintains which values have already been seen. If null, we accumulate all values coming through.
*/
class AccumulatorWrapper @OptIn(PartiQLValueExperimental::class, FnExperimental::class) constructor(
class AccumulatorWrapper @OptIn(PartiQLValueExperimental::class) constructor(
val delegate: Agg.Accumulator,
val args: List<Operator.Expr>,
val seen: TreeSet<List<PartiQLValue>>?
)

@OptIn(PartiQLValueExperimental::class, FnExperimental::class)
@OptIn(PartiQLValueExperimental::class)
override fun open(env: Environment) {
input.open(env)
for (inputRecord in input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.operator.Operator
import org.partiql.eval.value.Datum
import org.partiql.plan.Ref
import org.partiql.spi.fn.Fn
import org.partiql.spi.fn.FnExperimental
import org.partiql.planner.internal.fn.Fn
import org.partiql.types.PType
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
Expand All @@ -20,7 +19,7 @@ import org.partiql.value.PartiQLValueType
* [ExprCallStatic]'s. By doing this, this implementation can evaluate ([eval]) the input [Record], execute and gather the
* arguments, and pass the [PartiQLValue]s directly to the [Candidate.eval].
*/
@OptIn(PartiQLValueExperimental::class, FnExperimental::class)
@OptIn(PartiQLValueExperimental::class)
internal class ExprCallDynamic(
private val name: String,
private val candidates: Array<Candidate>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package org.partiql.eval.internal.operator.rex
import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.operator.Operator
import org.partiql.eval.value.Datum
import org.partiql.spi.fn.Fn
import org.partiql.spi.fn.FnExperimental
import org.partiql.planner.internal.fn.Fn
import org.partiql.value.PartiQLValueExperimental

@OptIn(FnExperimental::class, PartiQLValueExperimental::class)
@OptIn(PartiQLValueExperimental::class)
internal class ExprCallStatic(
private val fn: Fn,
private val inputs: Array<Operator.Expr>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ class PartiQLEngineDefaultTest {

internal fun assert() {
val statement = parser.parse(input).root
val catalogBuilder = MemoryCatalog.PartiQL().name("memory")
val catalogBuilder = MemoryCatalog.builder().name("memory")
globals.forEach { global ->
catalogBuilder.define(global.name, global.type, loader.loadSingleElement(global.value))
}
Expand Down Expand Up @@ -1344,7 +1344,7 @@ class PartiQLEngineDefaultTest {

private fun run(mode: PartiQLEngine.Mode): Pair<PartiQLValue, PartiQLPlan> {
val statement = parser.parse(input).root
val catalog = MemoryCatalog.PartiQL().name("memory").build()
val catalog = MemoryCatalog.builder().name("memory").build()
val connector = MemoryConnector(catalog)
val connectorSession = object : ConnectorSession {
override fun getQueryId(): String = "q"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import org.partiql.eval.value.Datum.boolValue
import org.partiql.eval.value.Datum.int32Value
import org.partiql.eval.value.Datum.listValue
import org.partiql.eval.value.Datum.stringValue
import org.partiql.spi.fn.Fn
import org.partiql.spi.fn.FnExperimental
import org.partiql.spi.fn.FnParameter
import org.partiql.spi.fn.FnSignature
import org.partiql.planner.internal.fn.Fn
import org.partiql.planner.internal.fn.FnParameter
import org.partiql.planner.internal.fn.FnSignature
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType
Expand Down Expand Up @@ -64,7 +63,7 @@ class ExprCallDynamicTest {
PartiQLValueType.ANY to PartiQLValueType.ANY, // Index 12
)

@OptIn(FnExperimental::class, PartiQLValueExperimental::class)
@OptIn(PartiQLValueExperimental::class)
internal val candidates = params.mapIndexed { index, it ->
ExprCallDynamic.Candidate(
fn = object : Fn {
Expand Down
84 changes: 84 additions & 0 deletions partiql-planner/api/partiql-planner.api
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,87 @@ public final class org/partiql/planner/catalog/Table$Handle {
public fun <init> (Lorg/partiql/planner/catalog/Name;Lorg/partiql/planner/catalog/Table;)V
}

public abstract interface class org/partiql/planner/internal/fn/Agg {
public abstract fun accumulator ()Lorg/partiql/planner/internal/fn/Agg$Accumulator;
public abstract fun getSignature ()Lorg/partiql/planner/internal/fn/AggSignature;
}

public abstract interface class org/partiql/planner/internal/fn/Agg$Accumulator {
public abstract fun next ([Lorg/partiql/value/PartiQLValue;)V
public abstract fun value ()Lorg/partiql/value/PartiQLValue;
}

public final class org/partiql/planner/internal/fn/AggSignature {
public final field description Ljava/lang/String;
public final field isDecomposable Z
public final field isNullable Z
public final field name Ljava/lang/String;
public final field parameters Ljava/util/List;
public final field returns Lorg/partiql/types/PType;
public fun <init> (Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZ)V
public synthetic fun <init> (Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lorg/partiql/value/PartiQLValueType;Ljava/util/List;Ljava/lang/String;ZZ)V
public synthetic fun <init> (Ljava/lang/String;Lorg/partiql/value/PartiQLValueType;Ljava/util/List;Ljava/lang/String;ZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun equals (Ljava/lang/Object;)Z
public final fun getSpecific ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public abstract interface class org/partiql/planner/internal/fn/Fn {
public abstract fun getSignature ()Lorg/partiql/planner/internal/fn/FnSignature;
public abstract fun invoke ([Lorg/partiql/value/PartiQLValue;)Lorg/partiql/value/PartiQLValue;
}

public final class org/partiql/planner/internal/fn/FnParameter {
public fun <init> (Ljava/lang/String;Lorg/partiql/types/PType;)V
public fun <init> (Ljava/lang/String;Lorg/partiql/value/PartiQLValueType;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lorg/partiql/types/PType;
public final fun copy (Ljava/lang/String;Lorg/partiql/types/PType;)Lorg/partiql/planner/internal/fn/FnParameter;
public static synthetic fun copy$default (Lorg/partiql/planner/internal/fn/FnParameter;Ljava/lang/String;Lorg/partiql/types/PType;ILjava/lang/Object;)Lorg/partiql/planner/internal/fn/FnParameter;
public fun equals (Ljava/lang/Object;)Z
public final fun getName ()Ljava/lang/String;
public final fun getType ()Lorg/partiql/types/PType;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/planner/internal/fn/FnSignature {
public final field description Ljava/lang/String;
public final field isDeterministic Z
public final field isMissable Z
public final field isMissingCall Z
public final field isNullCall Z
public final field isNullable Z
public final field name Ljava/lang/String;
public final field parameters Ljava/util/List;
public final field returns Lorg/partiql/types/PType;
public fun <init> (Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZZZZ)V
public synthetic fun <init> (Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Lorg/partiql/value/PartiQLValueType;Ljava/util/List;Ljava/lang/String;ZZZZZ)V
public synthetic fun <init> (Ljava/lang/String;Lorg/partiql/value/PartiQLValueType;Ljava/util/List;Ljava/lang/String;ZZZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Lorg/partiql/types/PType;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Z
public final fun component6 ()Z
public final fun component7 ()Z
public final fun component8 ()Z
public final fun component9 ()Z
public final fun copy (Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZZZZ)Lorg/partiql/planner/internal/fn/FnSignature;
public static synthetic fun copy$default (Lorg/partiql/planner/internal/fn/FnSignature;Ljava/lang/String;Lorg/partiql/types/PType;Ljava/util/List;Ljava/lang/String;ZZZZZILjava/lang/Object;)Lorg/partiql/planner/internal/fn/FnSignature;
public fun equals (Ljava/lang/Object;)Z
public final fun getSpecific ()Ljava/lang/String;
public fun hashCode ()I
public final fun sql ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
}

public final class org/partiql/planner/internal/fn/SqlFnProvider {
public static final field INSTANCE Lorg/partiql/planner/internal/fn/SqlFnProvider;
public final fun getAgg (Ljava/lang/String;)Lorg/partiql/planner/internal/fn/Agg;
public final fun getFn (Ljava/lang/String;)Lorg/partiql/planner/internal/fn/Fn;
}

1 change: 0 additions & 1 deletion partiql-planner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ tasks.register<Exec>("codegen") {
"--poems", "builder",
"--poems", "util",
"--opt-in", "org.partiql.value.PartiQLValueExperimental",
"--opt-in", "org.partiql.spi.fn.FnExperimental",
"./src/main/resources/partiql_plan_internal.ion"
)
}
Expand Down
Loading
Loading