diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt index 6a4d785492..106818a701 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt @@ -22,7 +22,6 @@ import com.amazon.ionelement.api.loadAllElements import org.partiql.cli.io.Format import org.partiql.cli.pipeline.Pipeline import org.partiql.cli.shell.Shell -import org.partiql.eval.PartiQLResult import org.partiql.plugins.memory.MemoryCatalog import org.partiql.plugins.memory.MemoryTable import org.partiql.spi.catalog.Catalog @@ -171,17 +170,9 @@ internal class MainCommand : Runnable { // TODO add format support checkFormat(format) - - when (result) { - is PartiQLResult.Error -> { - error(result.cause.stackTrace) - } - is PartiQLResult.Value -> { - val writer = PartiQLValueTextWriter(System.out) - writer.append(result.value.toPartiQLValue()) // TODO: Create a Datum writer - println() - } - } + val writer = PartiQLValueTextWriter(System.out) + writer.append(result.toPartiQLValue()) // TODO: Create a Datum writer + println() } private fun session() = Session.builder() diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/Pipeline.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/Pipeline.kt index 3761b9fc38..43683a07d8 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/Pipeline.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/Pipeline.kt @@ -4,23 +4,23 @@ import org.partiql.ast.Statement import org.partiql.errors.Problem import org.partiql.errors.ProblemCallback import org.partiql.errors.ProblemSeverity -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.PartiQLResult +import org.partiql.eval.compiler.PartiQLCompiler import org.partiql.parser.PartiQLParser import org.partiql.plan.Plan import org.partiql.planner.PartiQLPlanner import org.partiql.spi.catalog.Session +import org.partiql.spi.value.Datum internal class Pipeline private constructor( private val parser: PartiQLParser, private val planner: PartiQLPlanner, - private val engine: PartiQLEngine, + private val compiler: PartiQLCompiler, ) { /** * TODO replace with the ResultSet equivalent? */ - fun execute(statement: String, session: Session): PartiQLResult { + fun execute(statement: String, session: Session): Datum { val ast = parse(statement) val plan = plan(ast, session) return execute(plan, session) @@ -41,7 +41,7 @@ internal class Pipeline private constructor( TODO("Add V1 planner to the CLI") } - private fun execute(plan: Plan, session: Session): PartiQLResult { + private fun execute(plan: Plan, session: Session): Datum { // val statement = engine.prepare(plan, session.mode, session.planner()) // return engine.execute(statement) TODO("Add V1 planner to the CLI") @@ -61,15 +61,15 @@ internal class Pipeline private constructor( fun default(): Pipeline { val parser = PartiQLParser.standard() val planner = PartiQLPlanner.standard() - val engine = PartiQLEngine.standard() - return Pipeline(parser, planner, engine) + val evaluator = PartiQLCompiler.standard() + return Pipeline(parser, planner, evaluator) } fun strict(): Pipeline { val parser = PartiQLParser.standard() val planner = PartiQLPlanner.builder().signal().build() - val engine = PartiQLEngine.standard() - return Pipeline(parser, planner, engine) + val evaluator = PartiQLCompiler.standard() + return Pipeline(parser, planner, evaluator) } } } diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt index c990290ca5..9d5f1a5027 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt @@ -30,7 +30,6 @@ import org.jline.utils.AttributedStyle.BOLD import org.jline.utils.InfoCmp import org.joda.time.Duration import org.partiql.cli.pipeline.Pipeline -import org.partiql.eval.PartiQLResult import org.partiql.spi.catalog.Session import org.partiql.value.PartiQLValueExperimental import org.partiql.value.io.PartiQLValueTextWriter @@ -264,16 +263,11 @@ internal class Shell( } } else { val result = pipeline.execute(line, session) - when (result) { - is PartiQLResult.Error -> throw result.cause - is PartiQLResult.Value -> { - val writer = PartiQLValueTextWriter(out) - writer.append(result.value.toPartiQLValue()) // TODO: Create a Datum writer - out.appendLine() - out.appendLine() - out.info("OK!") - } - } + val writer = PartiQLValueTextWriter(out) + writer.append(result.toPartiQLValue()) // TODO: Create a Datum writer + out.appendLine() + out.appendLine() + out.info("OK!") } } } catch (ex: Exception) { diff --git a/partiql-eval/api/partiql-eval.api b/partiql-eval/api/partiql-eval.api index f7a7077f15..5b00ba3de0 100644 --- a/partiql-eval/api/partiql-eval.api +++ b/partiql-eval/api/partiql-eval.api @@ -1,54 +1,56 @@ -public abstract interface class org/partiql/eval/PartiQLEngine { - public static final field Companion Lorg/partiql/eval/PartiQLEngine$Companion; - public static fun builder ()Lorg/partiql/eval/builder/PartiQLEngineBuilder; - public abstract fun prepare (Lorg/partiql/plan/Plan;Lorg/partiql/eval/PartiQLEngine$Mode;Lorg/partiql/spi/catalog/Session;)Lorg/partiql/eval/PartiQLStatement; - public static fun standard ()Lorg/partiql/eval/PartiQLEngine; +public class org/partiql/eval/Environment { + public fun ()V + public fun get (II)Lorg/partiql/spi/value/Datum; + public fun push (Lorg/partiql/eval/Row;)Lorg/partiql/eval/Environment; + public fun toString ()Ljava/lang/String; } -public final class org/partiql/eval/PartiQLEngine$Companion { - public final fun builder ()Lorg/partiql/eval/builder/PartiQLEngineBuilder; - public final fun standard ()Lorg/partiql/eval/PartiQLEngine; +public abstract interface class org/partiql/eval/Expr { } -public final class org/partiql/eval/PartiQLEngine$Mode : java/lang/Enum { - public static final field PERMISSIVE Lorg/partiql/eval/PartiQLEngine$Mode; - public static final field STRICT Lorg/partiql/eval/PartiQLEngine$Mode; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/eval/PartiQLEngine$Mode; - public static fun values ()[Lorg/partiql/eval/PartiQLEngine$Mode; +public abstract interface class org/partiql/eval/ExprRelation : java/lang/AutoCloseable, java/util/Iterator, org/partiql/eval/Expr { + public abstract fun close ()V + public abstract fun hasNext ()Z + public synthetic fun next ()Ljava/lang/Object; + public abstract fun next ()Lorg/partiql/eval/Row; + public abstract fun open (Lorg/partiql/eval/Environment;)V + public fun remove ()V } -public abstract interface class org/partiql/eval/PartiQLResult { +public abstract interface class org/partiql/eval/ExprValue : org/partiql/eval/Expr { + public abstract fun eval (Lorg/partiql/eval/Environment;)Lorg/partiql/spi/value/Datum; } -public final class org/partiql/eval/PartiQLResult$Error : org/partiql/eval/PartiQLResult { - public fun (Ljava/lang/Throwable;)V - public final fun component1 ()Ljava/lang/Throwable; - public final fun copy (Ljava/lang/Throwable;)Lorg/partiql/eval/PartiQLResult$Error; - public static synthetic fun copy$default (Lorg/partiql/eval/PartiQLResult$Error;Ljava/lang/Throwable;ILjava/lang/Object;)Lorg/partiql/eval/PartiQLResult$Error; - public fun equals (Ljava/lang/Object;)Z - public final fun getCause ()Ljava/lang/Throwable; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; +public class org/partiql/eval/Mode { + public static final field PERMISSIVE I + public static final field STRICT I + public static fun PERMISSIVE ()Lorg/partiql/eval/Mode; + public static fun STRICT ()Lorg/partiql/eval/Mode; + public fun code ()I } -public final class org/partiql/eval/PartiQLResult$Value : org/partiql/eval/PartiQLResult { - public fun (Lorg/partiql/spi/value/Datum;)V - public final fun component1 ()Lorg/partiql/spi/value/Datum; - public final fun copy (Lorg/partiql/spi/value/Datum;)Lorg/partiql/eval/PartiQLResult$Value; - public static synthetic fun copy$default (Lorg/partiql/eval/PartiQLResult$Value;Lorg/partiql/spi/value/Datum;ILjava/lang/Object;)Lorg/partiql/eval/PartiQLResult$Value; +public class org/partiql/eval/Row { + public final field values [Lorg/partiql/spi/value/Datum; + public fun ()V + public fun ([Lorg/partiql/spi/value/Datum;)V + public fun concat (Lorg/partiql/eval/Row;)Lorg/partiql/eval/Row; public fun equals (Ljava/lang/Object;)Z - public final fun getValue ()Lorg/partiql/spi/value/Datum; public fun hashCode ()I + public static fun of ([Lorg/partiql/spi/value/Datum;)Lorg/partiql/eval/Row; public fun toString ()Ljava/lang/String; } -public abstract interface class org/partiql/eval/PartiQLStatement { - public abstract fun execute (Lorg/partiql/spi/catalog/Session;)Lorg/partiql/eval/PartiQLResult; +public abstract interface class org/partiql/eval/Statement { + public abstract fun execute ()Lorg/partiql/spi/value/Datum; } -public final class org/partiql/eval/builder/PartiQLEngineBuilder { - public fun ()V - public final fun build ()Lorg/partiql/eval/PartiQLEngine; +public abstract interface class org/partiql/eval/compiler/PartiQLCompiler { + public static fun builder ()Lorg/partiql/eval/compiler/PartiQLCompiler$Builder; + public abstract fun prepare (Lorg/partiql/plan/Plan;Lorg/partiql/eval/Mode;)Lorg/partiql/eval/Statement; + public static fun standard ()Lorg/partiql/eval/compiler/PartiQLCompiler; +} + +public class org/partiql/eval/compiler/PartiQLCompiler$Builder { + public fun build ()Lorg/partiql/eval/compiler/PartiQLCompiler; } diff --git a/partiql-eval/build.gradle.kts b/partiql-eval/build.gradle.kts index 3c4b338783..5d1097b8a1 100644 --- a/partiql-eval/build.gradle.kts +++ b/partiql-eval/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode + /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * @@ -36,7 +38,7 @@ dependencies { } kotlin { - explicitApi = null + explicitApi = ExplicitApiMode.Strict } tasks.shadowJar { @@ -53,7 +55,7 @@ components.withType(AdhocComponentWithVariants::class.java).forEach { c -> publish { artifactId = "partiql-eval" name = "PartiQL Lang Kotlin Evaluator" - description = "Experimental PartiQL plan-based evaluator" + description = "The PartiQL reference implementation evaluator." } tasks.processTestResources { diff --git a/partiql-eval/src/main/java/org/partiql/eval/Environment.java b/partiql-eval/src/main/java/org/partiql/eval/Environment.java new file mode 100644 index 0000000000..dee4d143f5 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/Environment.java @@ -0,0 +1,82 @@ +package org.partiql.eval; + +import org.partiql.spi.value.Datum; + +/** + * This class holds the evaluation environment. + *
+ * Developer Note: Attempts have been made at an interpreter stack, but has not worked well with nested lazy values. + * For example, an expression may return an inner lazy value (think subqueries), but the stack state may have changed + * BEFORE the inner lazy value is accessed. Here is my best attempt at illustrating this, + * + * 0: +-PUSH(row) + * 1: +--|----bag.eval() // lazy iterator (push/pop and eval variables) + * 2: | +-POP + * 3: | + * 4: +-- .next() // woah! we called bag.next() from line:1, but we popped on line:2 so line:1 is invalid! + * + *
+ * The most basic solution we have is to pass a new environment into each nested scope. + */ +public class Environment { + + private final Row[] stack; + + /** + * Default constructor with empty stack. + */ + public Environment() { + this.stack = new Row[]{}; + } + + /** + * Private constructor with given stack. + * @param stack + */ + private Environment(Row[] stack) { + this.stack = stack; + } + + /** + * Push a new row onto the stack. + */ + public Environment push(Row row) { + int n = stack.length; + Row[] next = new Row[n + 1]; + next[0] = row; + if (n > 0) { + System.arraycopy(stack, 0, next, 1, n); + } + return new Environment(next); + } + + /** + * Returns the variable at the specified depth and offset. + * + * @param depth Scope depth. + * @param offset Variable offset. + * @return Datum. + */ + public Datum get(int depth, int offset) { + try { + return stack[depth].values[offset]; + } catch (IndexOutOfBoundsException ex) { + throw new RuntimeException("Invalid variable reference [$depth:$offset]\n$this"); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("[stack]--------------\n"); + for (int i = 0; i < stack.length; i++) { + sb.append("$i: $row"); + sb.append("---------------------"); + } +// if (scope.isEmpty()) { +// appendLine("empty") +// appendLine("---------------------") +// } + return "stack"; + } +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/Expr.java b/partiql-eval/src/main/java/org/partiql/eval/Expr.java new file mode 100644 index 0000000000..b64afb0a89 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/Expr.java @@ -0,0 +1,6 @@ +package org.partiql.eval; + +/** + * Physical operators are implementations for one (or more) logical operators. + */ +public interface Expr {} diff --git a/partiql-eval/src/main/java/org/partiql/eval/ExprRelation.java b/partiql-eval/src/main/java/org/partiql/eval/ExprRelation.java new file mode 100644 index 0000000000..4796746c14 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/ExprRelation.java @@ -0,0 +1,25 @@ +package org.partiql.eval; + +import org.jetbrains.annotations.NotNull; + +import java.util.Iterator; + +/** + * ExprRelation is the interface for a expression which returns a "collection of binding tuples" aka iterator of rows. + */ +public interface ExprRelation extends Expr, AutoCloseable, Iterator { + + public void open(@NotNull Environment env); + + @NotNull + public Row next(); + + public boolean hasNext(); + + public void close(); + + @Override + default void remove() { + Iterator.super.remove(); + } +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/ExprValue.java b/partiql-eval/src/main/java/org/partiql/eval/ExprValue.java new file mode 100644 index 0000000000..2458e50a71 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/ExprValue.java @@ -0,0 +1,17 @@ +package org.partiql.eval; + +import org.partiql.spi.value.Datum; + +/** + * ExprValue is the interface for an expression (physical operator) that returns a value. + */ +public interface ExprValue extends Expr { + + /** + * Evaluate the expression for the given environment. + * + * @param env The current environment. + * @return The expression result. + */ + public Datum eval(Environment env); +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/Mode.java b/partiql-eval/src/main/java/org/partiql/eval/Mode.java new file mode 100644 index 0000000000..8a7f8943c9 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/Mode.java @@ -0,0 +1,38 @@ +package org.partiql.eval; + +/** + * PartiQL Execution Mode. + */ +public class Mode { + + /** + * Strict execution mode. + */ + public static final int STRICT = 0; + + /** + * Permissive execution mode. + */ + public static final int PERMISSIVE = 1; + + /** + * Internal enum code. + */ + private final int code; + + private Mode(int code) { + this.code = code; + } + + public int code() { + return this.code; + } + + public static Mode STRICT() { + return new Mode(STRICT); + } + + public static Mode PERMISSIVE() { + return new Mode(PERMISSIVE); + } +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/Row.java b/partiql-eval/src/main/java/org/partiql/eval/Row.java new file mode 100644 index 0000000000..e1832b6679 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/Row.java @@ -0,0 +1,82 @@ +package org.partiql.eval; + +import org.partiql.spi.value.Datum; + +import java.util.Arrays; +import java.util.Objects; + +/** + * A record is an ordered collection of values e.g. tuple. + */ +public class Row { + + /** + * TODO internalize values. + */ + public final Datum[] values; + + /** + * TODO keep ?? + * + * @param values the values + * @return the record + */ + public static Row of(Datum... values) { + return new Row(values); + } + + /** + * Create an empty record. + */ + public Row() { + this.values = new Datum[]{}; + } + + /** + * Create a record with the given values. + * + * @param values the values + */ + public Row(Datum[] values) { + this.values = values; + } + + /** + * Concatenates this record with another record. + * + * @param other the other record + * @return the concatenated record + */ + public Row concat(Row other) { + Datum[] result = Arrays.copyOf(this.values, this.values.length + other.values.length); + System.arraycopy(other.values, 0, result, this.values.length, other.values.length); + return new Row(result); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Row)) return false; + Row row = (Row) o; + return Objects.deepEquals(values, row.values); + } + + @Override + public int hashCode() { + return Arrays.hashCode(values); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("<"); + for (int i = 0; i < values.length; i++) { + sb.append(i).append(": ").append(values[i]); + if (i < values.length - 1) { + sb.append(", "); + } + } + sb.append(">"); + return sb.toString(); + } +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/Statement.java b/partiql-eval/src/main/java/org/partiql/eval/Statement.java new file mode 100644 index 0000000000..eaadf7ad7d --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/Statement.java @@ -0,0 +1,18 @@ +package org.partiql.eval; + +import org.jetbrains.annotations.NotNull; +import org.partiql.spi.value.Datum; + +/** + * An executable statement. + */ +public interface Statement { + + /** + * Executes the prepared statement. + * + * @return Datum execution result. + */ + @NotNull + public Datum execute(); +} diff --git a/partiql-eval/src/main/java/org/partiql/eval/compiler/PartiQLCompiler.java b/partiql-eval/src/main/java/org/partiql/eval/compiler/PartiQLCompiler.java new file mode 100644 index 0000000000..490bcb57c8 --- /dev/null +++ b/partiql-eval/src/main/java/org/partiql/eval/compiler/PartiQLCompiler.java @@ -0,0 +1,54 @@ +package org.partiql.eval.compiler; + +import org.jetbrains.annotations.NotNull; +import org.partiql.eval.Mode; +import org.partiql.eval.internal.compiler.StandardCompiler; +import org.partiql.eval.Statement; +import org.partiql.plan.Plan; + +/** + * TODO JAVADOC + */ +public interface PartiQLCompiler { + + /** + * Prepares the given plan into an executable PartiQL statement. + * + * @param plan The plan to compile. + * @return The prepared statement. + */ + @NotNull + public Statement prepare(@NotNull Plan plan, @NotNull Mode mode); + + /** + * @return A new [PartiQLCompilerBuilder]. + */ + @NotNull + public static Builder builder() { + return new Builder(); + } + + /** + * @return A new [PartiQLCompiler]. + */ + public static PartiQLCompiler standard() { + return new StandardCompiler(); + } + + /** + * Builder class for the [PartiQLCompiler] interface. + */ + public static class Builder { + + private Builder() { + // empty + } + + /** + * @return A new [PartiQLCompiler]. + */ + public PartiQLCompiler build() { + return new StandardCompiler(); + } + } +} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt deleted file mode 100644 index 546667dcc8..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt +++ /dev/null @@ -1,45 +0,0 @@ -package org.partiql.eval - -import org.partiql.eval.builder.PartiQLEngineBuilder -import org.partiql.plan.Plan -import org.partiql.spi.catalog.Session - -/** - * PartiQL's Experimental Engine. - * - * It represents the execution of queries and does NOT represent the - * maintenance of an individual's session. For example, by the time the engine is invoked, all functions - * should be resolved via the SQL Path (which takes into consideration the user's current catalog/schema). - * - * This is in contrast to an actual application of PartiQL. Applications of PartiQL should instantiate a - * [org.partiql.planner.PartiQLPlanner] and should pass in a user's session. This engine has no idea what the session is. - * It assumes that the [org.partiql.plan.Plan] has been resolved to accommodate session specifics. - * - * This engine also internalizes the mechanics of the engine itself. Internally, it creates a physical plan to operate on, - * and it executes directly on that plan. The limited number of APIs exposed in this library is intentional to allow for - * under-the-hood experimentation by the PartiQL Community. - * - * - * TODO rename PartiQLEngine to PartiQLCompiler as it produces the statement (statement holds its own execution logic). - */ -public interface PartiQLEngine { - - public fun prepare(plan: Plan, mode: Mode, session: Session): PartiQLStatement - - companion object { - - @JvmStatic - public fun builder(): PartiQLEngineBuilder = PartiQLEngineBuilder() - - @JvmStatic - fun standard() = PartiQLEngineBuilder().build() - } - - /** - * TODO move mode to the session ?? - */ - public enum class Mode { - PERMISSIVE, - STRICT // AKA, Type Checking Mode in the PartiQL Specification - } -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLResult.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLResult.kt deleted file mode 100644 index 5dcf941525..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLResult.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.partiql.eval - -import org.partiql.spi.value.Datum - -public sealed interface PartiQLResult { - - public data class Value(public val value: Datum) : PartiQLResult - - public data class Error(public val cause: Throwable) : PartiQLResult -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLStatement.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLStatement.kt deleted file mode 100644 index ab4de084f3..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLStatement.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.partiql.eval - -import org.partiql.spi.catalog.Session - -/** - * Represents a compiled PartiQL statement ready for execution. - */ -public interface PartiQLStatement { - - public fun execute(session: Session): PartiQLResult -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/builder/PartiQLEngineBuilder.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/builder/PartiQLEngineBuilder.kt deleted file mode 100644 index b625ceef33..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/builder/PartiQLEngineBuilder.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.partiql.eval.builder - -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.internal.SqlEngine - -class PartiQLEngineBuilder { - - /** - * Build the builder, return an implementation of a [PartiQLEngine] - * - * @return - */ - public fun build(): PartiQLEngine = SqlEngine() -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Environment.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Environment.kt deleted file mode 100644 index dc9c4e0f9d..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Environment.kt +++ /dev/null @@ -1,62 +0,0 @@ -package org.partiql.eval.internal - -import org.partiql.spi.value.Datum - -/** - * This class represents the Variables Environment defined in the PartiQL Specification. - */ -internal class Environment( - private val bindings: Record, - private val parent: Environment? = null -) { - - companion object { - @JvmStatic - val empty: Environment = Environment(Record.empty, null) - } - - operator fun get(index: Int): Datum { - try { - return this.bindings[index] - } catch (_: Throwable) { - throw IllegalStateException("Received error when searching for binding at index $index. Current bindings are: $this.") - } - } - - fun getOrNull(index: Int): Datum? { - return this.bindings.values.getOrNull(index) - } - - internal fun next(): Environment? { - return this.parent - } - - /** - * Returns a new [Environment] that contains the [record] and encloses the current [Environment]. This is used to: - * 1. Pass on a [Record] from a Rel to a Rex. Consider `SELECT a + 1 FROM t`. The PROJECT would likely grab the input - * record from the SCAN, [push] it into the current environment, and pass it to the Expr representing `a + 1`. - * 2. Create a nested scope. Consider `SELECT 1 + (SELECT t1.a + t2.b FROM t2 LIMIT 1) FROM t1`. Since the inner - * SELECT (ExprSubquery) is creating a "nested scope", it would invoke [push]. - * - * Here are the general rules to follow: - * 1. When evaluating Expressions from within a Relation, one should always use [push] to "push" onto the stack. - * 2. When evaluating Relations from within an Expression, one should always use [push] to "push" onto the stack. - * 3. When evaluating Expressions from within a Relation, there is no need to use [push]. - * 4. When evaluating Relations from within a Relation, one **might** want to use [push]. Consider the LATERAL JOIN, for instance. - * - * @see [org.partiql.eval.internal.operator.Operator.Expr] - * @see [org.partiql.eval.internal.operator.Operator.Relation] - * @see [org.partiql.eval.internal.operator.rex.ExprSubquery] - */ - internal fun push(record: Record): Environment = Environment( - record, - this - ) - - override fun toString(): String { - return when (parent) { - null -> bindings.toString() - else -> "$bindings --> $parent" - } - } -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Record.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Record.kt deleted file mode 100644 index 76a55c4da1..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/Record.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.partiql.eval.internal - -import org.partiql.spi.value.Datum - -internal class Record(val values: Array) { - - companion object { - val empty = Record(emptyArray()) - fun of(vararg values: Datum) = Record(arrayOf(*(values))) - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - other as Record - return values.contentEquals(other.values) - } - - override fun hashCode(): Int { - return values.contentHashCode() - } - - public operator fun plus(rhs: Record): Record { - return Record(this.values + rhs.values) - } - - public fun copy(): Record { - return Record(this.values.copyOf()) - } - - public operator fun get(index: Int): Datum { - return this.values[index] - } - - override fun toString(): String { - return buildString { - append("< ") - values.forEachIndexed { index, value -> - append("$index: $value") - if (index != values.lastIndex) { - append(", ") - } - } - append(" >") - } - } -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlEngine.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlEngine.kt deleted file mode 100644 index 787928c1d8..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlEngine.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.partiql.eval.internal - -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.PartiQLStatement -import org.partiql.eval.internal.statement.QueryStatement -import org.partiql.plan.Operation.Query -import org.partiql.plan.Plan -import org.partiql.spi.catalog.Session - -internal class SqlEngine : PartiQLEngine { - - override fun prepare(plan: Plan, mode: PartiQLEngine.Mode, session: Session): PartiQLStatement { - try { - val operation = plan.getOperation() - if (operation !is Query) { - throw IllegalArgumentException("Only query statements are supported") - } - val compiler = SqlCompiler(mode, session) - val root = compiler.compile(operation.getRex()) - return QueryStatement(root) - } catch (ex: Exception) { - // TODO wrap in some PartiQL Exception - throw ex - } - } -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlCompiler.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt similarity index 69% rename from partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlCompiler.kt rename to partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt index bc9ed14e39..2f9338453f 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/SqlCompiler.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt @@ -1,7 +1,13 @@ -package org.partiql.eval.internal - -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.internal.operator.Operator +package org.partiql.eval.internal.compiler + +import org.partiql.eval.Environment +import org.partiql.eval.Expr +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Mode +import org.partiql.eval.Statement +import org.partiql.eval.compiler.PartiQLCompiler +import org.partiql.eval.internal.operator.Aggregate import org.partiql.eval.internal.operator.rel.RelOpAggregate import org.partiql.eval.internal.operator.rel.RelOpDistinct import org.partiql.eval.internal.operator.rel.RelOpExceptAll @@ -53,6 +59,9 @@ import org.partiql.eval.internal.operator.rex.ExprTable import org.partiql.eval.internal.operator.rex.ExprVar import org.partiql.plan.Collation import org.partiql.plan.JoinType +import org.partiql.plan.Operation +import org.partiql.plan.Plan +import org.partiql.plan.Visitor import org.partiql.plan.rel.Rel import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelDistinct @@ -70,7 +79,6 @@ import org.partiql.plan.rel.RelScan import org.partiql.plan.rel.RelSort import org.partiql.plan.rel.RelUnion import org.partiql.plan.rel.RelUnpivot -import org.partiql.plan.rel.RelVisitor import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexArray import org.partiql.plan.rex.RexBag @@ -96,73 +104,87 @@ import org.partiql.plan.rex.RexSubqueryIn import org.partiql.plan.rex.RexSubqueryTest import org.partiql.plan.rex.RexTable import org.partiql.plan.rex.RexVar -import org.partiql.plan.rex.RexVisitor -import org.partiql.spi.catalog.Session -import org.partiql.spi.function.Aggregation import org.partiql.spi.value.Datum import org.partiql.types.PType /** - * This class is responsible for producing a tree of evaluable operators from a tree of logical operators. - * - * @property mode - * @property session + * This class is responsible for producing an executable statement from logical operators. */ -internal class SqlCompiler( - @JvmField var mode: PartiQLEngine.Mode, - @JvmField var session: Session, -) { +internal class StandardCompiler : PartiQLCompiler { + + override fun prepare(plan: Plan, mode: Mode): Statement = try { + val visitor = _Visitor(mode) + val operation = plan.getOperation() + val statement: Statement = when { + operation is Operation.Query -> visitor.compile(operation) + else -> throw IllegalArgumentException("Only query statements are supported") + } + statement + } catch (ex: Exception) { + // TODO wrap in some PartiQL Exception + throw ex + } - private val relCompiler = RelCompiler() + /** + * Transforms plan relation operators into the internal physical operators. + */ + @Suppress("ClassName") + private inner class _Visitor(mode: Mode) : Visitor { - private val rexCompiler = RexCompiler() + private val mode = mode.code() + private val unknown = PType.unknown() - fun compile(rex: Rex): Operator.Expr = compile(rex, Unit).catch() + /** + * Compile a query operation to a query statement. + */ + fun compile(operation: Operation.Query) = object : Statement { - private fun compile(rel: Rel, ctx: Unit): Operator.Relation = rel.accept(relCompiler, ctx) + // compile the query root + private val root = compile(operation.getRex(), Unit).catch() - private fun compile(rex: Rex, ctx: Unit): Operator.Expr = rex.accept(rexCompiler, ctx) + // execute with no parameters + override fun execute(): Datum = root.eval(Environment()) + } - /** - * Transforms plan relation operators into the internal physical operators. - */ - private inner class RelCompiler : RelVisitor { + private fun compile(rel: Rel, ctx: Unit): ExprRelation = rel.accept(this, ctx) as ExprRelation - override fun defaultReturn(rel: Rel, ctx: Unit): Operator.Relation { - TODO("Evaluation is not implemented for rel: ${rel::class.simpleName}") + private fun compile(rex: Rex, ctx: Unit): ExprValue = rex.accept(this, ctx) as ExprValue + + /** + * TODO apply custom strategies left-to-right, returning the first match. + * + * @param operator + * @param ctx + * @return + */ + override fun defaultReturn(operator: org.partiql.plan.Operator, ctx: Unit): Expr { + error("No compiler strategy matches the operator: ${operator::class.simpleName}") } - override fun visitError(rel: RelError, ctx: Unit): Operator.Relation { + override fun visitError(rel: RelError, ctx: Unit): ExprRelation { throw IllegalStateException(rel.message) } // OPERATORS - override fun visitAggregate(rel: RelAggregate, ctx: Unit): Operator.Relation { + override fun visitAggregate(rel: RelAggregate, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) - val keys = rel.getGroups().map { compile(it, ctx).catch() } val aggs = rel.getCalls().map { call -> val agg = call.getAgg() val args = call.getArgs().map { compile(it, ctx).catch() } - val setq = when (call.isDistinct()) { - true -> Operator.Aggregation.SetQuantifier.DISTINCT - else -> Operator.Aggregation.SetQuantifier.ALL - } - object : Operator.Aggregation { - override val delegate: Aggregation = agg - override val args: List = args - override val setQuantifier: Operator.Aggregation.SetQuantifier = setq - } + val distinct = call.isDistinct() + Aggregate(agg, args, distinct) } - return RelOpAggregate(input, keys, aggs) + val groups = rel.getGroups().map { compile(it, ctx).catch() } + return RelOpAggregate(input, aggs, groups) } - override fun visitDistinct(rel: RelDistinct, ctx: Unit): Operator.Relation { + override fun visitDistinct(rel: RelDistinct, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) return RelOpDistinct(input) } - override fun visitExcept(rel: RelExcept, ctx: Unit): Operator.Relation { + override fun visitExcept(rel: RelExcept, ctx: Unit): ExprRelation { val lhs = compile(rel.getLeft(), ctx) val rhs = compile(rel.getRight(), ctx) return when (rel.isAll()) { @@ -171,19 +193,19 @@ internal class SqlCompiler( } } - override fun visitExclude(rel: RelExclude, ctx: Unit): Operator.Relation { + override fun visitExclude(rel: RelExclude, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val paths = rel.getExclusions() return RelOpExclude(input, paths) } - override fun visitFilter(rel: RelFilter, ctx: Unit): Operator.Relation { + override fun visitFilter(rel: RelFilter, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val predicate = compile(rel.getPredicate(), ctx).catch() return RelOpFilter(input, predicate) } - override fun visitIntersect(rel: RelIntersect, ctx: Unit): Operator.Relation { + override fun visitIntersect(rel: RelIntersect, ctx: Unit): ExprRelation { val lhs = compile(rel.getLeft(), ctx) val rhs = compile(rel.getRight(), ctx) return when (rel.isAll()) { @@ -192,15 +214,16 @@ internal class SqlCompiler( } } - override fun visitIterate(rel: RelIterate, ctx: Unit): Operator.Relation { + override fun visitIterate(rel: RelIterate, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) return when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> RelOpIteratePermissive(input) - PartiQLEngine.Mode.STRICT -> RelOpIterate(input) + Mode.PERMISSIVE -> RelOpIteratePermissive(input) + Mode.STRICT -> RelOpIterate(input) + else -> throw IllegalStateException("Unsupported execution mode: $mode") } } - override fun visitJoin(rel: RelJoin, ctx: Unit): Operator.Relation { + override fun visitJoin(rel: RelJoin, ctx: Unit): ExprRelation { val lhs = compile(rel.getLeft(), ctx) val rhs = compile(rel.getRight(), ctx) val condition = rel.getCondition()?.let { compile(it, ctx) } ?: ExprLit(Datum.bool(true)) @@ -217,33 +240,34 @@ internal class SqlCompiler( } } - override fun visitLimit(rel: RelLimit, ctx: Unit): Operator.Relation { + override fun visitLimit(rel: RelLimit, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val limit = compile(rel.getLimit(), ctx) return RelOpLimit(input, limit) } - override fun visitOffset(rel: RelOffset, ctx: Unit): Operator.Relation { + override fun visitOffset(rel: RelOffset, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val offset = compile(rel.getOffset(), ctx) return RelOpOffset(input, offset) } - override fun visitProject(rel: RelProject, ctx: Unit): Operator.Relation { + override fun visitProject(rel: RelProject, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val projections = rel.getProjections().map { compile(it, ctx).catch() } return RelOpProject(input, projections) } - override fun visitScan(rel: RelScan, ctx: Unit): Operator.Relation { + override fun visitScan(rel: RelScan, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) return when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> RelOpScanPermissive(input) - PartiQLEngine.Mode.STRICT -> RelOpScan(input) + Mode.PERMISSIVE -> RelOpScanPermissive(input) + Mode.STRICT -> RelOpScan(input) + else -> throw IllegalStateException("Unsupported execution mode: $mode") } } - override fun visitSort(rel: RelSort, ctx: Unit): Operator.Relation { + override fun visitSort(rel: RelSort, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) val collations = rel.getCollations().map { val expr = compile(it.getRex(), ctx) @@ -254,7 +278,7 @@ internal class SqlCompiler( return RelOpSort(input, collations) } - override fun visitUnion(rel: RelUnion, ctx: Unit): Operator.Relation { + override fun visitUnion(rel: RelUnion, ctx: Unit): ExprRelation { val lhs = compile(rel.getLeft(), ctx) val rhs = compile(rel.getRight(), ctx) return when (rel.isAll()) { @@ -263,44 +287,32 @@ internal class SqlCompiler( } } - override fun visitUnpivot(rel: RelUnpivot, ctx: Unit): Operator.Relation { + override fun visitUnpivot(rel: RelUnpivot, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) return when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> RelOpUnpivot.Permissive(input) - PartiQLEngine.Mode.STRICT -> RelOpUnpivot.Strict(input) + Mode.PERMISSIVE -> RelOpUnpivot.Permissive(input) + Mode.STRICT -> RelOpUnpivot.Strict(input) + else -> throw IllegalStateException("Unsupported execution mode: $mode") } } - } - - /** - * Transforms plan expression operators into the internal physical expressions. - */ - private inner class RexCompiler : RexVisitor { - - // - private val unknown = PType.unknown() - override fun defaultReturn(rex: Rex, ctx: Unit): Operator.Expr { - TODO("Not yet implemented") - } - - override fun visitError(rex: RexError, ctx: Unit): Operator.Expr { + override fun visitError(rex: RexError, ctx: Unit): ExprValue { throw IllegalStateException(rex.getMessage()) } // OPERATORS - override fun visitArray(rex: RexArray, ctx: Unit): Operator.Expr { + override fun visitArray(rex: RexArray, ctx: Unit): ExprValue { val values = rex.getValues().map { compile(it, ctx).catch() } return ExprArray(values) } - override fun visitBag(rex: RexBag, ctx: Unit): Operator.Expr { + override fun visitBag(rex: RexBag, ctx: Unit): ExprValue { val values = rex.getValues().map { compile(it, ctx).catch() } return ExprBag(values) } - override fun visitCallDynamic(rex: RexCallDynamic, ctx: Unit): Operator.Expr { + override fun visitCallDynamic(rex: RexCallDynamic, ctx: Unit): ExprValue { // Check candidate arity for uniformity var arity: Int = -1 val name = rex.getName() @@ -328,17 +340,17 @@ internal class SqlCompiler( return ExprCallDynamic(name, candidates, args) } - override fun visitCall(rex: RexCall, ctx: Unit): Operator.Expr { + override fun visitCall(rex: RexCall, ctx: Unit): ExprValue { val func = rex.getFunction() val args = rex.getArgs() val catch = func.parameters.any { it.kind == PType.Kind.DYNAMIC } return when (catch) { - true -> ExprCall(func, Array(args.size) { i -> compile(args[i]).catch() }) - else -> ExprCall(func, Array(args.size) { i -> compile(args[i]) }) + true -> ExprCall(func, Array(args.size) { i -> compile(args[i], Unit).catch() }) + else -> ExprCall(func, Array(args.size) { i -> compile(args[i], Unit) }) } } - override fun visitCase(rex: RexCase, ctx: Unit): Operator.Expr { + override fun visitCase(rex: RexCase, ctx: Unit): ExprValue { if (rex.getMatch() != null) { TODO(" expression") } @@ -351,79 +363,81 @@ internal class SqlCompiler( return ExprCaseSearched(branches, default) } - override fun visitCast(rex: RexCast, ctx: Unit): Operator.Expr { + override fun visitCast(rex: RexCast, ctx: Unit): ExprValue { val operand = compile(rex.getOperand(), ctx) val target = rex.getTarget() return ExprCast(operand, target) } - override fun visitCoalesce(rex: RexCoalesce, ctx: Unit): Operator.Expr { + override fun visitCoalesce(rex: RexCoalesce, ctx: Unit): ExprValue { val args = rex.getArgs().map { compile(it, ctx) }.toTypedArray() return ExprCoalesce(args) } - override fun visitLit(rex: RexLit, ctx: Unit): Operator.Expr { + override fun visitLit(rex: RexLit, ctx: Unit): ExprValue { return ExprLit(rex.getValue()) } - override fun visitMissing(rex: RexMissing, ctx: Unit): Operator.Expr { + override fun visitMissing(rex: RexMissing, ctx: Unit): ExprValue { return ExprMissing(unknown) } - override fun visitNullIf(rex: RexNullIf, ctx: Unit): Operator.Expr { + override fun visitNullIf(rex: RexNullIf, ctx: Unit): ExprValue { val value = compile(rex.getV1(), ctx) val nullifier = compile(rex.getV2(), ctx) return ExprNullIf(value, nullifier) } - override fun visitPathIndex(rex: RexPathIndex, ctx: Unit): Operator.Expr { + override fun visitPathIndex(rex: RexPathIndex, ctx: Unit): ExprValue { val operand = compile(rex.getOperand(), ctx) val index = compile(rex.getIndex(), ctx) return ExprPathIndex(operand, index) } - override fun visitPathKey(rex: RexPathKey, ctx: Unit): Operator.Expr { + override fun visitPathKey(rex: RexPathKey, ctx: Unit): ExprValue { val operand = compile(rex.getOperand(), ctx) val key = compile(rex.getKey(), ctx) return ExprPathKey(operand, key) } - override fun visitPathSymbol(rex: RexPathSymbol, ctx: Unit): Operator.Expr { + override fun visitPathSymbol(rex: RexPathSymbol, ctx: Unit): ExprValue { val operand = compile(rex.getOperand(), ctx) val symbol = rex.getSymbol() return ExprPathSymbol(operand, symbol) } - override fun visitPivot(rex: RexPivot, ctx: Unit): Operator.Expr { + override fun visitPivot(rex: RexPivot, ctx: Unit): ExprValue { val input = compile(rex.getInput(), ctx) val key = compile(rex.getKey(), ctx) val value = compile(rex.getValue(), ctx) return when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> ExprPivotPermissive(input, key, value) - PartiQLEngine.Mode.STRICT -> ExprPivot(input, key, value) + Mode.PERMISSIVE -> ExprPivotPermissive(input, key, value) + Mode.STRICT -> ExprPivot(input, key, value) + else -> throw IllegalStateException("Unsupported execution mode: $mode") } } - override fun visitSelect(rex: RexSelect, ctx: Unit): Operator.Expr { + override fun visitSelect(rex: RexSelect, ctx: Unit): ExprValue { val input = compile(rex.getInput(), ctx) val constructor = compile(rex.getConstructor(), ctx).catch() val ordered = rex.getInput().isOrdered() return ExprSelect(input, constructor, ordered) } - override fun visitStruct(rex: RexStruct, ctx: Unit): Operator.Expr { + override fun visitStruct(rex: RexStruct, ctx: Unit): ExprValue { val fields = rex.getFields().map { val k = compile(it.getKey(), ctx) val v = compile(it.getValue(), ctx).catch() ExprStructField(k, v) } return when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> ExprStructPermissive(fields) - PartiQLEngine.Mode.STRICT -> ExprStructStrict(fields) + Mode.PERMISSIVE -> ExprStructPermissive(fields) + Mode.STRICT -> ExprStructStrict(fields) + else -> throw IllegalStateException("Unsupported execution mode: $mode") } } - override fun visitSubquery(rex: RexSubquery, ctx: Unit): Operator.Expr { + override fun visitSubquery(rex: RexSubquery, ctx: Unit): ExprValue { val rel = compile(rex.getRel(), ctx) val constructor = compile(rex.getConstructor(), ctx) return when (rex.asScalar()) { @@ -432,39 +446,40 @@ internal class SqlCompiler( } } - override fun visitSubqueryComp(rex: RexSubqueryComp, ctx: Unit): Operator.Expr { + override fun visitSubqueryComp(rex: RexSubqueryComp, ctx: Unit): ExprValue { TODO(" and ") } - override fun visitSubqueryIn(rex: RexSubqueryIn, ctx: Unit): Operator.Expr { + override fun visitSubqueryIn(rex: RexSubqueryIn, ctx: Unit): ExprValue { TODO("") } - override fun visitSubqueryTest(rex: RexSubqueryTest, ctx: Unit): Operator.Expr { + override fun visitSubqueryTest(rex: RexSubqueryTest, ctx: Unit): ExprValue { TODO(" and ") } - override fun visitSpread(rex: RexSpread, ctx: Unit): Operator.Expr { + override fun visitSpread(rex: RexSpread, ctx: Unit): ExprValue { val args = rex.getArgs().map { compile(it, ctx) }.toTypedArray() return ExprSpread(args) } - override fun visitTable(rex: RexTable, ctx: Unit): Operator.Expr { + override fun visitTable(rex: RexTable, ctx: Unit): ExprValue { return ExprTable(rex.getTable()) } - override fun visitVar(rex: RexVar, ctx: Unit): Operator.Expr { + override fun visitVar(rex: RexVar, ctx: Unit): ExprValue { val depth = rex.getDepth() val offset = rex.getOffset() return ExprVar(depth, offset) } - } - /** - * Some places "catch" an error and return the MISSING value. - */ - private fun Operator.Expr.catch(): Operator.Expr = when (mode) { - PartiQLEngine.Mode.PERMISSIVE -> ExprPermissive(this) - PartiQLEngine.Mode.STRICT -> this + /** + * Some places "catch" an error and return the MISSING value. + */ + private fun ExprValue.catch(): ExprValue = when (mode) { + Mode.PERMISSIVE -> ExprPermissive(this) + Mode.STRICT -> this + else -> throw IllegalStateException("Unsupported execution mode: $mode") + } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/DatumArrayComparator.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/DatumArrayComparator.kt similarity index 93% rename from partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/DatumArrayComparator.kt rename to partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/DatumArrayComparator.kt index e9d65aa802..a86b2aa039 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/DatumArrayComparator.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/DatumArrayComparator.kt @@ -1,4 +1,4 @@ -package org.partiql.eval.internal.operator.rel +package org.partiql.eval.internal.helpers import org.partiql.spi.value.Datum diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/RecordValueIterator.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/RecordValueIterator.kt index 72c01121c3..0000e4a3ae 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/RecordValueIterator.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/helpers/RecordValueIterator.kt @@ -1,18 +1,19 @@ package org.partiql.eval.internal.helpers -import org.partiql.eval.internal.Record +import org.partiql.eval.Row import org.partiql.spi.value.Datum /** - * An [Iterator] over an [Iterator] lazily producing [Record]s as you call [next]. + * An [Iterator] over an [Iterator] lazily producing [Row]s as you call [next]. */ internal class RecordValueIterator( collectionValue: Iterator -) : Iterator { +) : Iterator { private val collectionIter = collectionValue.iterator() override fun hasNext(): Boolean = collectionIter.hasNext() - override fun next(): Record = Record(Array(1) { collectionIter.next() }) + override fun next(): Row = + Row(Array(1) { collectionIter.next() }) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Aggregate.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Aggregate.kt new file mode 100644 index 0000000000..5699e6894b --- /dev/null +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Aggregate.kt @@ -0,0 +1,13 @@ +package org.partiql.eval.internal.operator + +import org.partiql.eval.ExprValue +import org.partiql.spi.function.Aggregation + +/** + * Simple data class to hold a compile aggregation call. + */ +internal class Aggregate( + val agg: Aggregation, + val args: List, + val distinct: Boolean +) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Operator.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Operator.kt deleted file mode 100644 index 4ca9febfc5..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/Operator.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.partiql.eval.internal.operator - -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.spi.value.Datum - -internal sealed interface Operator { - - /** - * Expr represents an evaluable expression tree which returns a value. - */ - interface Expr : Operator { - - fun eval(env: Environment): Datum - } - - /** - * Relation operator represents an evaluable collection of binding tuples. - */ - interface Relation : Operator, AutoCloseable, Iterator { - - fun open(env: Environment) - - override fun close() - } - - interface Aggregation : Operator { - - val delegate: org.partiql.spi.function.Aggregation - - val args: List - - val setQuantifier: SetQuantifier - - enum class SetQuantifier { - ALL, - DISTINCT - } - } -} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpAggregate.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpAggregate.kt index 1529dae559..083da5c4de 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpAggregate.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpAggregate.kt @@ -1,8 +1,11 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator +import org.partiql.eval.internal.operator.Aggregate import org.partiql.spi.function.Aggregation import org.partiql.spi.value.Datum import org.partiql.types.PType @@ -10,12 +13,12 @@ import java.util.TreeMap import java.util.TreeSet internal class RelOpAggregate( - val input: Operator.Relation, - private val keys: List, - private val functions: List -) : Operator.Relation { + private val input: ExprRelation, + private val aggregates: List, + private val groups: List, +) : ExprRelation { - private lateinit var records: Iterator + private lateinit var records: Iterator private val aggregationMap = TreeMap, List>(DatumArrayComparator) @@ -26,16 +29,18 @@ internal class RelOpAggregate( */ class AccumulatorWrapper( val delegate: Aggregation.Accumulator, - val args: List, + val args: List, val seen: TreeSet>? ) override fun open(env: Environment) { input.open(env) for (inputRecord in input) { + // Initialize the AggregationMap - val evaluatedGroupByKeys = Array(keys.size) { keyIndex -> - val key = keys[keyIndex].eval(env.push(inputRecord)) + val evaluatedGroupByKeys = Array(groups.size) { keyIndex -> + val env = env.push(inputRecord) + val key = groups[keyIndex].eval(env) when (key.isMissing) { true -> Datum.nullValue() false -> key @@ -46,14 +51,11 @@ internal class RelOpAggregate( val args: Array = emptyArray() val accumulators = aggregationMap.getOrPut(evaluatedGroupByKeys) { - functions.map { + aggregates.map { AccumulatorWrapper( - delegate = it.delegate.getAccumulator(args), + delegate = it.agg.getAccumulator(args), args = it.args, - seen = when (it.setQuantifier) { - Operator.Aggregation.SetQuantifier.DISTINCT -> TreeSet(DatumArrayComparator) - Operator.Aggregation.SetQuantifier.ALL -> null - } + seen = if (it.distinct) TreeSet(DatumArrayComparator) else null ) } } @@ -74,23 +76,25 @@ internal class RelOpAggregate( } accumulators[index].delegate.next(arguments) } + + // TODO env.pop() which happens automatically because the variable is dropped. } // No Aggregations Created - if (keys.isEmpty() && aggregationMap.isEmpty()) { + if (groups.isEmpty() && aggregationMap.isEmpty()) { val record = mutableListOf() - functions.forEach { function -> - val accumulator = function.delegate.getAccumulator(args = emptyArray()) + aggregates.forEach { function -> + val accumulator = function.agg.getAccumulator(args = emptyArray()) record.add(accumulator.value()) } - records = iterator { yield(Record.of(*record.toTypedArray())) } + records = iterator { yield(Row(record.toTypedArray())) } return } records = iterator { aggregationMap.forEach { (keysEvaluated, accumulators) -> val recordValues = accumulators.map { acc -> acc.delegate.value() } + keysEvaluated - yield(Record.of(*recordValues.toTypedArray())) + yield(Row(recordValues.toTypedArray())) } } } @@ -99,7 +103,7 @@ internal class RelOpAggregate( return records.hasNext() } - override fun next(): Record { + override fun next(): Row { return records.next() } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpDistinct.kt index b47b6bf5fd..fc90d3eb2c 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpDistinct.kt @@ -1,13 +1,12 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import java.util.TreeSet -internal class RelOpDistinct( - val input: Operator.Relation -) : RelOpPeeking() { +internal class RelOpDistinct(private val input: ExprRelation) : RelOpPeeking() { private val seen = TreeSet(DatumArrayComparator) @@ -15,7 +14,7 @@ internal class RelOpDistinct( input.open(env) } - override fun peek(): Record? { + override fun peek(): Row? { for (next in input) { val transformed = Array(next.values.size) { next.values[it] } if (seen.contains(transformed).not()) { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptAll.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptAll.kt index 7fc567c853..832a376f44 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptAll.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptAll.kt @@ -1,15 +1,16 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import java.util.TreeMap internal class RelOpExceptAll( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, + private val lhs: ExprRelation, + private val rhs: ExprRelation, ) : RelOpPeeking() { private val seen = TreeMap, Int>(DatumArrayComparator) @@ -22,7 +23,7 @@ internal class RelOpExceptAll( seen.clear() } - override fun peek(): Record? { + override fun peek(): Row? { if (!init) { seed() } @@ -33,7 +34,7 @@ internal class RelOpExceptAll( seen[row.values] = remaining - 1 continue } - return Record(row.values) + return Row(row.values) } return null } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptDistinct.kt index 3471502be9..f212db4279 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExceptDistinct.kt @@ -1,9 +1,10 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator import java.util.TreeSet /** @@ -13,8 +14,8 @@ import java.util.TreeSet * @property rhs */ internal class RelOpExceptDistinct( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, + private val lhs: ExprRelation, + private val rhs: ExprRelation, ) : RelOpPeeking() { private var seen = TreeSet(DatumArrayComparator) @@ -26,14 +27,14 @@ internal class RelOpExceptDistinct( init = false } - override fun peek(): Record? { + override fun peek(): Row? { if (!init) { seed() } for (row in lhs) { row.values.coerceMissing() if (!seen.contains(row.values)) { - return Record(row.values) + return Row(row.values) } } return null diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt index 4ad5deb216..db6f6a048b 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpExclude.kt @@ -1,8 +1,8 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row import org.partiql.plan.Exclusion import org.partiql.spi.value.Datum import org.partiql.spi.value.Field @@ -16,9 +16,9 @@ import org.partiql.value.PartiQLValueType * Consider more memoization, use arrays, combine coll/struct exclusions in one method, ano others! */ internal class RelOpExclude( - private val input: Operator.Relation, + private val input: ExprRelation, private val exclusions: List, -) : Operator.Relation { +) : ExprRelation { override fun open(env: Environment) { input.open(env) @@ -28,7 +28,7 @@ internal class RelOpExclude( return input.hasNext() } - override fun next(): Record { + override fun next(): Row { val record = input.next() exclusions.forEach { exclusion -> // TODO memoize offsets and steps (i.e. don't call getVar(), getOffset(), and getItems() every time). diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpFilter.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpFilter.kt index d0d9451031..ed865a2787 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpFilter.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpFilter.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.isTrue -import org.partiql.eval.internal.operator.Operator internal class RelOpFilter( - val input: Operator.Relation, - val expr: Operator.Expr + val input: ExprRelation, + val expr: ExprValue ) : RelOpPeeking() { private lateinit var env: Environment @@ -17,7 +18,7 @@ internal class RelOpFilter( input.open(env) } - override fun peek(): Record? { + override fun peek(): Row? { for (inputRecord in input) { if (conditionIsTrue(inputRecord, expr)) { return inputRecord @@ -30,8 +31,8 @@ internal class RelOpFilter( input.close() } - private fun conditionIsTrue(record: Record, expr: Operator.Expr): Boolean { - val condition = expr.eval(env.push(record)) + private fun conditionIsTrue(row: Row, expr: ExprValue): Boolean { + val condition = expr.eval(env.push(row)) return condition.isTrue() } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectAll.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectAll.kt index dcaf696220..975c34fe73 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectAll.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectAll.kt @@ -1,15 +1,16 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import java.util.TreeMap internal class RelOpIntersectAll( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, + private val lhs: ExprRelation, + private val rhs: ExprRelation, ) : RelOpPeeking() { private val seen = TreeMap, Int>(DatumArrayComparator) @@ -22,7 +23,7 @@ internal class RelOpIntersectAll( seen.clear() } - override fun peek(): Record? { + override fun peek(): Row? { if (!init) { seed() } @@ -31,7 +32,7 @@ internal class RelOpIntersectAll( val remaining = seen[row.values] ?: 0 if (remaining > 0) { seen[row.values] = remaining - 1 - return Record(row.values) + return Row(row.values) } } return null diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectDistinct.kt index b3de829ace..95233b81a7 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIntersectDistinct.kt @@ -1,14 +1,15 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator import java.util.TreeSet internal class RelOpIntersectDistinct( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, + private val lhs: ExprRelation, + private val rhs: ExprRelation, ) : RelOpPeeking() { private val seen = TreeSet(DatumArrayComparator) @@ -21,14 +22,14 @@ internal class RelOpIntersectDistinct( seen.clear() } - override fun peek(): Record? { + override fun peek(): Row? { if (!init) { seed() } for (row in rhs) { row.values.coerceMissing() if (seen.remove(row.values)) { - return Record(row.values) + return Row(row.values) } } return null diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt index 1573895df4..577dd8bd47 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIterate.kt @@ -1,21 +1,22 @@ package org.partiql.eval.internal.operator.rel import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.spi.value.Datum import org.partiql.types.PType internal class RelOpIterate( - private val expr: Operator.Expr -) : Operator.Relation { + private val expr: ExprValue +) : ExprRelation { private lateinit var iterator: Iterator private var index: Long = 0 override fun open(env: Environment) { - val r = expr.eval(env.push(Record.empty)) + val r = expr.eval(env.push(Row())) index = 0 iterator = when (r.type.kind) { PType.Kind.BAG -> { @@ -34,11 +35,11 @@ internal class RelOpIterate( return iterator.hasNext() } - override fun next(): Record { + override fun next(): Row { val i = index val v = iterator.next() index += 1 - return Record.of(v, Datum.bigint(i)) + return Row(arrayOf(v, Datum.bigint(i))) } override fun close() {} diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt index 0b331a3c6b..350cbf8db4 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpIteratePermissive.kt @@ -1,21 +1,22 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.spi.value.Datum import org.partiql.types.PType internal class RelOpIteratePermissive( - private val expr: Operator.Expr -) : Operator.Relation { + private val expr: ExprValue +) : ExprRelation { private lateinit var iterator: Iterator private var index: Long = 0 private var isIndexable: Boolean = true override fun open(env: Environment) { - val r = expr.eval(env.push(Record.empty)) + val r = expr.eval(env.push(Row())) index = 0 iterator = when (r.type.kind) { PType.Kind.BAG -> { @@ -34,15 +35,15 @@ internal class RelOpIteratePermissive( return iterator.hasNext() } - override fun next(): Record { + override fun next(): Row { val v = iterator.next() return when (isIndexable) { true -> { val i = index index += 1 - Record.of(v, Datum.bigint(i)) + Row(arrayOf(v, Datum.bigint(i))) } - false -> Record.of(v, Datum.missing()) + false -> Row(arrayOf(v, Datum.missing())) } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinInner.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinInner.kt index e3af5c4859..020ea92ea1 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinInner.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinInner.kt @@ -1,10 +1,10 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.isTrue -import org.partiql.eval.internal.operator.Operator -import org.partiql.value.PartiQLValueExperimental /** * Inner Join returns all joined records from the [lhs] and [rhs] when the [condition] evaluates to true. @@ -13,13 +13,13 @@ import org.partiql.value.PartiQLValueExperimental * (lateral vs non-lateral) may be separated for performance improvements. */ internal class RelOpJoinInner( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, - private val condition: Operator.Expr, + private val lhs: ExprRelation, + private val rhs: ExprRelation, + private val condition: ExprValue, ) : RelOpPeeking() { private lateinit var env: Environment - private lateinit var iterator: Iterator + private lateinit var iterator: Iterator override fun openPeeking(env: Environment) { this.env = env @@ -27,7 +27,7 @@ internal class RelOpJoinInner( iterator = implementation() } - override fun peek(): Record? { + override fun peek(): Row? { return when (iterator.hasNext()) { true -> iterator.next() false -> null @@ -37,7 +37,7 @@ internal class RelOpJoinInner( override fun closePeeking() { lhs.close() rhs.close() - iterator = emptyList().iterator() + iterator = emptyList().iterator() } /** @@ -54,15 +54,14 @@ internal class RelOpJoinInner( * * Development Note: The non-lateral version wouldn't need to push to the current environment. */ - @OptIn(PartiQLValueExperimental::class) private fun implementation() = iterator { for (lhsRecord in lhs) { rhs.open(env.push(lhsRecord)) for (rhsRecord in rhs) { - val input = lhsRecord + rhsRecord + val input = lhsRecord.concat(rhsRecord) val result = condition.eval(env.push(input)) if (result.isTrue()) { - yield(lhsRecord + rhsRecord) + yield(lhsRecord.concat(rhsRecord)) } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterFull.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterFull.kt index 84d66ad371..062d18234b 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterFull.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterFull.kt @@ -1,9 +1,10 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.isTrue -import org.partiql.eval.internal.operator.Operator import org.partiql.plan.rel.RelType import org.partiql.spi.value.Datum @@ -15,9 +16,9 @@ import org.partiql.spi.value.Datum * Full Outer Join cannot be lateral according to PartiQL Specification Section 5.5. */ internal class RelOpJoinOuterFull( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, - private val condition: Operator.Expr, + private val lhs: ExprRelation, + private val rhs: ExprRelation, + private val condition: ExprValue, lhsType: RelType, rhsType: RelType, ) : RelOpPeeking() { @@ -25,11 +26,13 @@ internal class RelOpJoinOuterFull( // TODO BETTER MECHANISM FOR NULL PADDING private val r = rhsType.getFields().toTypedArray() private val l = lhsType.getFields().toTypedArray() - private val lhsPadded: Record = Record(l.indices.map { Datum.nullValue(l[it].type) }.toTypedArray()) - private val rhsPadded: Record = Record(r.indices.map { Datum.nullValue(r[it].type) }.toTypedArray()) + private val lhsPadded: Row = + Row(l.indices.map { Datum.nullValue(l[it].type) }.toTypedArray()) + private val rhsPadded: Row = + Row(r.indices.map { Datum.nullValue(r[it].type) }.toTypedArray()) private lateinit var env: Environment - private lateinit var iterator: Iterator + private lateinit var iterator: Iterator override fun openPeeking(env: Environment) { this.env = env @@ -37,7 +40,7 @@ internal class RelOpJoinOuterFull( iterator = implementation() } - override fun peek(): Record? { + override fun peek(): Row? { return when (iterator.hasNext()) { true -> iterator.next() false -> null @@ -47,7 +50,7 @@ internal class RelOpJoinOuterFull( override fun closePeeking() { lhs.close() rhs.close() - iterator = emptyList().iterator() + iterator = emptyList().iterator() } /** @@ -84,12 +87,12 @@ internal class RelOpJoinOuterFull( for ((lhsIndex, lhsRecord) in lhs.withIndex()) { rhs.open(env) for ((rhsIndex, rhsRecord) in rhs.withIndex()) { - val input = lhsRecord + rhsRecord + val input = lhsRecord.concat(rhsRecord) val result = condition.eval(env.push(input)) if (result.isTrue()) { lhsMatches.add(lhsIndex) rhsMatches.add(rhsIndex) - yield(lhsRecord + rhsRecord) + yield(lhsRecord.concat(rhsRecord)) } } rhs.close() @@ -98,14 +101,14 @@ internal class RelOpJoinOuterFull( lhs.open(env) for ((lhsIndex, lhsRecord) in lhs.withIndex()) { if (!lhsMatches.contains(lhsIndex)) { - yield(lhsRecord + rhsPadded) + yield(lhsRecord.concat(rhsPadded)) } } lhs.close() rhs.open(env) for ((rhsIndex, rhsRecord) in rhs.withIndex()) { if (!rhsMatches.contains(rhsIndex)) { - yield(lhsPadded + rhsRecord) + yield(lhsPadded.concat(rhsRecord)) } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterLeft.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterLeft.kt index b347f7bdef..f13710a493 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterLeft.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterLeft.kt @@ -1,9 +1,10 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.isTrue -import org.partiql.eval.internal.operator.Operator import org.partiql.plan.rel.RelType import org.partiql.spi.value.Datum @@ -15,17 +16,21 @@ import org.partiql.spi.value.Datum * (lateral vs non-lateral) may be separated for performance improvements. */ internal class RelOpJoinOuterLeft( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, - private val condition: Operator.Expr, + private val lhs: ExprRelation, + private val rhs: ExprRelation, + private val condition: ExprValue, rhsType: RelType, ) : RelOpPeeking() { // TODO BETTER MECHANISM FOR NULL PADDING - private val rhsPadded = Record(rhsType.getFields().map { Datum.nullValue(it.type) }.toTypedArray()) + private val rhsPadded = + Row( + rhsType.getFields().map { Datum.nullValue(it.type) } + .toTypedArray() + ) private lateinit var env: Environment - private lateinit var iterator: Iterator + private lateinit var iterator: Iterator override fun openPeeking(env: Environment) { this.env = env @@ -33,7 +38,7 @@ internal class RelOpJoinOuterLeft( iterator = implementation() } - override fun peek(): Record? { + override fun peek(): Row? { return when (iterator.hasNext()) { true -> iterator.next() false -> null @@ -43,7 +48,7 @@ internal class RelOpJoinOuterLeft( override fun closePeeking() { lhs.close() rhs.close() - iterator = emptyList().iterator() + iterator = emptyList().iterator() } /** @@ -67,16 +72,16 @@ internal class RelOpJoinOuterLeft( var lhsMatched = false rhs.open(env.push(lhsRecord)) for (rhsRecord in rhs) { - val input = lhsRecord + rhsRecord + val input = lhsRecord.concat(rhsRecord) val result = condition.eval(env.push(input)) if (result.isTrue()) { lhsMatched = true - yield(lhsRecord + rhsRecord) + yield(lhsRecord.concat(rhsRecord)) } } rhs.close() if (!lhsMatched) { - yield(lhsRecord + rhsPadded) + yield(lhsRecord.concat(rhsPadded)) } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterRight.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterRight.kt index 00acadf81c..8d55d356d7 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterRight.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpJoinOuterRight.kt @@ -1,9 +1,10 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.isTrue -import org.partiql.eval.internal.operator.Operator import org.partiql.plan.rel.RelType import org.partiql.spi.value.Datum @@ -14,17 +15,21 @@ import org.partiql.spi.value.Datum * Right Outer Join cannot be lateral according to PartiQL Specification Section 5.5. */ internal class RelOpJoinOuterRight( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, - private val condition: Operator.Expr, + private val lhs: ExprRelation, + private val rhs: ExprRelation, + private val condition: ExprValue, lhsType: RelType ) : RelOpPeeking() { // TODO BETTER MECHANISM FOR NULL PADDING - private val lhsPadded = Record(lhsType.getFields().map { Datum.nullValue(it.type) }.toTypedArray()) + private val lhsPadded = + Row( + lhsType.getFields().map { Datum.nullValue(it.type) } + .toTypedArray() + ) private lateinit var env: Environment - private lateinit var iterator: Iterator + private lateinit var iterator: Iterator override fun openPeeking(env: Environment) { this.env = env @@ -32,7 +37,7 @@ internal class RelOpJoinOuterRight( iterator = implementation() } - override fun peek(): Record? { + override fun peek(): Row? { return when (iterator.hasNext()) { true -> iterator.next() false -> null @@ -42,7 +47,7 @@ internal class RelOpJoinOuterRight( override fun closePeeking() { lhs.close() rhs.close() - iterator = emptyList().iterator() + iterator = emptyList().iterator() } /** @@ -64,16 +69,16 @@ internal class RelOpJoinOuterRight( var rhsMatched = false lhs.open(env) for (lhsRecord in lhs) { - val input = lhsRecord + rhsRecord + val input = lhsRecord.concat(rhsRecord) val result = condition.eval(env.push(input)) if (result.isTrue()) { rhsMatched = true - yield(lhsRecord + rhsRecord) + yield(lhsRecord.concat(rhsRecord)) } } lhs.close() if (!rhsMatched) { - yield(lhsPadded + rhsRecord) + yield(lhsPadded.concat(rhsRecord)) } } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpLimit.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpLimit.kt index 16ddc73c14..cff7853c7f 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpLimit.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpLimit.kt @@ -1,17 +1,16 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.getBigIntCoerced -import org.partiql.eval.internal.operator.Operator -import org.partiql.value.PartiQLValueExperimental import java.math.BigInteger -@OptIn(PartiQLValueExperimental::class) internal class RelOpLimit( - private val input: Operator.Relation, - private val limit: Operator.Expr, -) : Operator.Relation { + private val input: ExprRelation, + private val limit: ExprValue, +) : ExprRelation { private var _seen: BigInteger = BigInteger.ZERO private var _limit: BigInteger = BigInteger.ZERO @@ -20,7 +19,7 @@ internal class RelOpLimit( input.open(env) _seen = BigInteger.ZERO - val l = limit.eval(env.push(Record.empty)) + val l = limit.eval(env.push(Row())) _limit = l.getBigIntCoerced() // TODO: The planner should handle the coercion } @@ -28,7 +27,7 @@ internal class RelOpLimit( return _seen < _limit && input.hasNext() } - override fun next(): Record { + override fun next(): Row { val row = input.next() _seen = _seen.add(BigInteger.ONE) return row diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpOffset.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpOffset.kt index 53b2721376..4caf0fd0cd 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpOffset.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpOffset.kt @@ -1,17 +1,16 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.ValueUtility.getBigIntCoerced -import org.partiql.eval.internal.operator.Operator -import org.partiql.value.PartiQLValueExperimental import java.math.BigInteger -@OptIn(PartiQLValueExperimental::class) internal class RelOpOffset( - private val input: Operator.Relation, - private val offset: Operator.Expr, -) : Operator.Relation { + private val input: ExprRelation, + private val offset: ExprValue, +) : ExprRelation { private var init = false private var _seen: BigInteger = BigInteger.ZERO @@ -22,7 +21,7 @@ internal class RelOpOffset( init = false _seen = BigInteger.ZERO - val o = offset.eval(env.push(Record.empty)) + val o = offset.eval(env.push(Row())) _offset = o.getBigIntCoerced() // TODO: The planner should handle the coercion } @@ -40,7 +39,7 @@ internal class RelOpOffset( return input.hasNext() } - override fun next(): Record { + override fun next(): Row { return input.next() } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpPeeking.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpPeeking.kt index 2bec83ab91..ea36dea2cb 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpPeeking.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpPeeking.kt @@ -1,15 +1,15 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.IteratorPeeking -import org.partiql.eval.internal.operator.Operator /** - * For [Operator.Relation]'s that MUST materialize data in order to execute [hasNext], this abstract class caches the + * For [ExprRelation]'s that MUST materialize data in order to execute [hasNext], this abstract class caches the * result of [peek] to implement both [hasNext] and [next]. */ -internal abstract class RelOpPeeking : Operator.Relation, IteratorPeeking() { +internal abstract class RelOpPeeking : ExprRelation, IteratorPeeking() { /** * This shall have the same functionality as [open]. Implementers of [RelOpPeeking] shall not override [open]. diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpProject.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpProject.kt index ead09dae08..8a9e043bdd 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpProject.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpProject.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row internal class RelOpProject( - private val input: Operator.Relation, - private val projections: List -) : Operator.Relation { + private val input: ExprRelation, + private val projections: List +) : ExprRelation { private lateinit var env: Environment @@ -20,10 +21,10 @@ internal class RelOpProject( return input.hasNext() } - override fun next(): Record { + override fun next(): Row { val r = input.next() val p = projections.map { it.eval(env.push(r)) }.toTypedArray() - return Record(p) + return Row(p) } override fun close() { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt index fc37b051a9..613b1d4d8d 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScan.kt @@ -1,20 +1,21 @@ package org.partiql.eval.internal.operator.rel import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.RecordValueIterator -import org.partiql.eval.internal.operator.Operator import org.partiql.types.PType internal class RelOpScan( - private val expr: Operator.Expr -) : Operator.Relation { + private val expr: ExprValue +) : ExprRelation { - private lateinit var records: Iterator + private lateinit var records: Iterator override fun open(env: Environment) { - val r = expr.eval(env.push(Record.empty)) + val r = expr.eval(env.push(Row())) records = when (r.type.kind) { PType.Kind.ARRAY, PType.Kind.BAG, PType.Kind.SEXP -> RecordValueIterator(r.iterator()) else -> { @@ -26,7 +27,7 @@ internal class RelOpScan( override fun hasNext(): Boolean = records.hasNext() - override fun next(): Record { + override fun next(): Row { return records.next() } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt index 4c023b28a9..986752c712 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpScanPermissive.kt @@ -1,22 +1,23 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.RecordValueIterator -import org.partiql.eval.internal.operator.Operator import org.partiql.types.PType internal class RelOpScanPermissive( - private val expr: Operator.Expr -) : Operator.Relation { + private val expr: ExprValue +) : ExprRelation { - private lateinit var records: Iterator + private lateinit var records: Iterator override fun open(env: Environment) { - val r = expr.eval(env.push(Record.empty)) + val r = expr.eval(env.push(Row())) records = when (r.type.kind) { PType.Kind.BAG, PType.Kind.ARRAY, PType.Kind.SEXP -> RecordValueIterator(r.iterator()) - else -> iterator { yield(Record.of(r)) } + else -> iterator { yield(Row(arrayOf(r))) } } } @@ -24,7 +25,7 @@ internal class RelOpScanPermissive( return records.hasNext() } - override fun next(): Record { + override fun next(): Row { return records.next() } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpSort.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpSort.kt index a830c332a8..027022a2fb 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpSort.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpSort.kt @@ -1,16 +1,17 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.spi.value.Datum import java.util.Collections internal class RelOpSort( - private val input: Operator.Relation, + private val input: ExprRelation, private val collations: List, -) : Operator.Relation { - private var records: Iterator = Collections.emptyIterator() +) : ExprRelation { + private var records: Iterator = Collections.emptyIterator() private var init: Boolean = false private val nullsFirstComparator = Datum.comparator(true) @@ -25,8 +26,8 @@ internal class RelOpSort( records = Collections.emptyIterator() } - private val comparator = object : Comparator { - override fun compare(l: Record, r: Record): Int { + private val comparator = object : Comparator { + override fun compare(l: Row, r: Row): Int { collations.forEach { spec -> // TODO: Write comparator for PQLValue val lVal = spec.expr.eval(env.push(l)) @@ -51,18 +52,18 @@ internal class RelOpSort( override fun hasNext(): Boolean { if (!init) { - val sortedRecords = mutableListOf() + val sortedRows = mutableListOf() for (row in input) { - sortedRecords.add(row) + sortedRows.add(row) } - sortedRecords.sortWith(comparator) - records = sortedRecords.iterator() + sortedRows.sortWith(comparator) + records = sortedRows.iterator() init = true } return records.hasNext() } - override fun next(): Record { + override fun next(): Row { return records.next() } @@ -79,7 +80,7 @@ internal class RelOpSort( * @property last True iff NULLS LAST sort, otherwise NULLS FIRST. */ class Collation( - @JvmField var expr: Operator.Expr, + @JvmField var expr: ExprValue, @JvmField var desc: Boolean, @JvmField var last: Boolean, ) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionAll.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionAll.kt index bf59b2d25b..1af099b58c 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionAll.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionAll.kt @@ -1,14 +1,14 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator internal class RelOpUnionAll( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, -) : Operator.Relation { + private val lhs: ExprRelation, + private val rhs: ExprRelation, +) : ExprRelation { override fun open(env: Environment) { lhs.open(env) @@ -19,7 +19,7 @@ internal class RelOpUnionAll( return lhs.hasNext() || rhs.hasNext() } - override fun next(): Record { + override fun next(): Row { return when (lhs.hasNext()) { true -> { val record = lhs.next() diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionDistinct.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionDistinct.kt index d17b772af7..c91dfd58ef 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionDistinct.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnionDistinct.kt @@ -1,20 +1,21 @@ package org.partiql.eval.internal.operator.rel -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.Row +import org.partiql.eval.internal.helpers.DatumArrayComparator import org.partiql.eval.internal.helpers.IteratorChain import org.partiql.eval.internal.helpers.RecordUtility.coerceMissing -import org.partiql.eval.internal.operator.Operator import java.util.TreeSet internal class RelOpUnionDistinct( - private val lhs: Operator.Relation, - private val rhs: Operator.Relation, + private val lhs: ExprRelation, + private val rhs: ExprRelation, ) : RelOpPeeking() { private val seen = TreeSet(DatumArrayComparator) - private lateinit var input: Iterator + private lateinit var input: Iterator override fun openPeeking(env: Environment) { lhs.open(env) @@ -23,12 +24,12 @@ internal class RelOpUnionDistinct( input = IteratorChain(arrayOf(lhs, rhs)) } - override fun peek(): Record? { + override fun peek(): Row? { for (record in input) { record.values.coerceMissing() if (!seen.contains(record.values)) { seen.add(record.values) - return Record(record.values) + return Row(record.values) } } return null diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnpivot.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnpivot.kt index 19e24ba9fb..6f19bc8dd1 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnpivot.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rel/RelOpUnpivot.kt @@ -1,9 +1,10 @@ package org.partiql.eval.internal.operator.rel import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.Record -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue +import org.partiql.eval.Row import org.partiql.spi.value.Datum import org.partiql.spi.value.Field import org.partiql.types.PType @@ -14,7 +15,7 @@ import org.partiql.types.PType * Input: { k_0: v_0, ..., k_i: v_i } * Output: [ k_0, v_0 ] ... [ k_i, v_i ] */ -internal sealed class RelOpUnpivot : Operator.Relation { +internal sealed class RelOpUnpivot : ExprRelation { /** * Iterator of the struct fields. @@ -40,11 +41,11 @@ internal sealed class RelOpUnpivot : Operator.Relation { return _iterator.hasNext() } - override fun next(): Record { + override fun next(): Row { val f = _iterator.next() val k = Datum.string(f.name) val v = f.value - return Record.of(k, v) + return Row.of(k, v) } override fun close() {} @@ -54,10 +55,10 @@ internal sealed class RelOpUnpivot : Operator.Relation { * * @property expr */ - class Strict(private val expr: Operator.Expr) : RelOpUnpivot() { + class Strict(private val expr: ExprValue) : RelOpUnpivot() { override fun struct(): Datum { - val v = expr.eval(env.push(Record.empty)) + val v = expr.eval(env.push(Row())) if (v.type.kind != PType.Kind.STRUCT && v.type.kind != PType.Kind.ROW) { throw TypeCheckException() } @@ -74,10 +75,10 @@ internal sealed class RelOpUnpivot : Operator.Relation { * * @property expr */ - class Permissive(private val expr: Operator.Expr) : RelOpUnpivot() { + class Permissive(private val expr: ExprValue) : RelOpUnpivot() { override fun struct(): Datum { - val v = expr.eval(env.push(Record.empty)) + val v = expr.eval(env.push(Row())) if (v.isMissing) { return Datum.struct(emptyList()) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprArray.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprArray.kt index ab174f9a46..c1b66658fd 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprArray.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprArray.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum /** * Creates an array by evaluating each input value expression. */ -internal class ExprArray(values: List) : Operator.Expr { +internal class ExprArray(values: List) : + ExprValue { // DO NOT USE FINAL private var _values = values diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprBag.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprBag.kt index d811eb3d0f..fc4b4c03c6 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprBag.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprBag.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum /** * Creates a bag by evaluating each input value expression. */ -internal class ExprBag(values: List) : Operator.Expr { +internal class ExprBag(values: List) : + ExprValue { // DO NOT USE FINAL private var _values = values diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCall.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCall.kt index c3d8a6febb..21ec750c04 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCall.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCall.kt @@ -1,7 +1,7 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.function.Function import org.partiql.spi.value.Datum @@ -13,8 +13,8 @@ import org.partiql.spi.value.Datum */ internal class ExprCall( private var function: Function.Instance, - private var args: Array, -) : Operator.Expr { + private var args: Array, +) : ExprValue { private var isNullCall: Boolean = function.isNullCall private var isMissingCall: Boolean = function.isMissingCall diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt index b15cdd0949..e3ec8a5915 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamic.kt @@ -1,8 +1,12 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue +import org.partiql.eval.Row +import org.partiql.eval.internal.operator.rex.ExprCallDynamic.Candidate +import org.partiql.eval.internal.operator.rex.ExprCallDynamic.CoercionFamily.DYNAMIC +import org.partiql.eval.internal.operator.rex.ExprCallDynamic.CoercionFamily.UNKNOWN import org.partiql.spi.function.Function import org.partiql.spi.value.Datum import org.partiql.types.PType @@ -18,7 +22,7 @@ import org.partiql.value.PartiQLValue * 2. Evaluate the input arguments. * 3. Lookup the candidate to dispatch to and invoke. * - * This implementation can evaluate ([eval]) the input [Record], execute and gather the + * This implementation can evaluate ([eval]) the input [Row], execute and gather the * arguments, and pass the [PartiQLValue]s directly to the [Candidate.eval]. * * This implementation also caches previously resolved candidates. @@ -28,8 +32,8 @@ import org.partiql.value.PartiQLValue internal class ExprCallDynamic( private val name: String, private val functions: Array, - private val args: Array -) : Operator.Expr { + private val args: Array +) : ExprValue { /** * @property paramIndices the indices of the [args] diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCase.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCase.kt index c866fa4e07..fd8ec5bae6 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCase.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCase.kt @@ -1,14 +1,14 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.types.PType internal class ExprCase( - private val branches: List>, - private val default: Operator.Expr -) : Operator.Expr { + private val branches: List>, + private val default: ExprValue +) : ExprValue { override fun eval(env: Environment): Datum { branches.forEach { branch -> diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseBranch.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseBranch.kt index 0809d7d631..478106b10e 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseBranch.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseBranch.kt @@ -1,7 +1,7 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.types.PType @@ -11,7 +11,7 @@ import org.partiql.types.PType * @param value * @param result */ -internal class ExprCaseBranch(value: Operator.Expr, result: Operator.Expr) { +internal class ExprCaseBranch(value: ExprValue, result: ExprValue) { // DO NOT USE FINAL private var _value = value diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseSearched.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseSearched.kt index 8d24d87410..ec79551d63 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseSearched.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCaseSearched.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum /** * Implementation of the expression. */ -internal class ExprCaseSearched(branches: List, default: Operator.Expr?) : Operator.Expr { +internal class ExprCaseSearched(branches: List, default: ExprValue?) : + ExprValue { // DO NOT USE FINAL private var _branches = branches diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCast.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCast.kt index 6c47ed53ee..c6494e8fa5 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCast.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCast.kt @@ -1,7 +1,7 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.types.PType @@ -14,7 +14,8 @@ import org.partiql.types.PType * @param operand * @param target */ -internal class ExprCast(operand: Operator.Expr, target: PType) : Operator.Expr { +internal class ExprCast(operand: ExprValue, target: PType) : + ExprValue { // DO NOT USE FINAL private var _operand = operand diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCoalesce.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCoalesce.kt index fd3482854e..96f84b0163 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCoalesce.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprCoalesce.kt @@ -1,13 +1,13 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.value.PartiQLValueExperimental internal class ExprCoalesce( - private val args: Array -) : Operator.Expr { + private val args: Array +) : ExprValue { @PartiQLValueExperimental override fun eval(env: Environment): Datum { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprLit.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprLit.kt index 1bcb2ae795..fd7e6e1be4 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprLit.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprLit.kt @@ -1,13 +1,13 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum /** * Literal expression. */ -internal class ExprLit(value: Datum) : Operator.Expr { +internal class ExprLit(value: Datum) : ExprValue { // DO NOT USE FINAL private var _value = value diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprMissing.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprMissing.kt index f1c05c78e3..4c7d4d83e3 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprMissing.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprMissing.kt @@ -1,13 +1,13 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.types.PType internal class ExprMissing( private val type: PType -) : Operator.Expr { +) : ExprValue { override fun eval(env: Environment): Datum { return Datum.missing(type) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprNullIf.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprNullIf.kt index 0226ffa2d9..17f2a2a86d 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprNullIf.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprNullIf.kt @@ -1,13 +1,13 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum internal class ExprNullIf( - private val valueExpr: Operator.Expr, - private val nullifierExpr: Operator.Expr -) : Operator.Expr { + private val valueExpr: ExprValue, + private val nullifierExpr: ExprValue +) : ExprValue { private val comparator = Datum.comparator() diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt index d8c54acde0..7735791c80 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathIndex.kt @@ -1,16 +1,16 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.getInt32Coerced -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.types.PType internal class ExprPathIndex( - @JvmField val root: Operator.Expr, - @JvmField val key: Operator.Expr, -) : Operator.Expr { + @JvmField val root: ExprValue, + @JvmField val key: ExprValue, +) : ExprValue { override fun eval(env: Environment): Datum { val input = root.eval(env) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathKey.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathKey.kt index 6ae5e88789..6a99487de8 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathKey.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathKey.kt @@ -1,17 +1,17 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.check -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType internal class ExprPathKey( - @JvmField val root: Operator.Expr, - @JvmField val key: Operator.Expr -) : Operator.Expr { + @JvmField val root: ExprValue, + @JvmField val key: ExprValue +) : ExprValue { @OptIn(PartiQLValueExperimental::class) override fun eval(env: Environment): Datum { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathSymbol.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathSymbol.kt index ee52ba1288..5b3cda14b5 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathSymbol.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPathSymbol.kt @@ -1,17 +1,17 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.check -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType internal class ExprPathSymbol( - @JvmField val root: Operator.Expr, + @JvmField val root: ExprValue, @JvmField val symbol: String, -) : Operator.Expr { +) : ExprValue { @OptIn(PartiQLValueExperimental::class) override fun eval(env: Environment): Datum { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPermissive.kt index bebb3000e2..60abd3df93 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPermissive.kt @@ -3,11 +3,12 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.CardinalityViolation import org.partiql.errors.DataException import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum -internal class ExprPermissive(private var expr: Operator.Expr) : Operator.Expr { +internal class ExprPermissive(private var expr: ExprValue) : + ExprValue { override fun eval(env: Environment): Datum { return try { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivot.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivot.kt index 3d81f308a7..fd9471b5fc 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivot.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivot.kt @@ -1,16 +1,17 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.getText -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.spi.value.Field internal class ExprPivot( - private val input: Operator.Relation, - private val key: Operator.Expr, - private val value: Operator.Expr, -) : Operator.Expr { + private val input: ExprRelation, + private val key: ExprValue, + private val value: ExprValue, +) : ExprValue { override fun eval(env: Environment): Datum { input.open(env) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivotPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivotPermissive.kt index f4196a9edb..338307922b 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivotPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprPivotPermissive.kt @@ -1,17 +1,18 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.getText -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.spi.value.Field internal class ExprPivotPermissive( - private val input: Operator.Relation, - private val key: Operator.Expr, - private val value: Operator.Expr, -) : Operator.Expr { + private val input: ExprRelation, + private val key: ExprValue, + private val value: ExprValue, +) : ExprValue { override fun eval(env: Environment): Datum { input.open(env) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSelect.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSelect.kt index 81ea777c14..6e04a338cc 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSelect.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSelect.kt @@ -1,7 +1,8 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.value.PartiQLValueExperimental @@ -12,15 +13,15 @@ import org.partiql.value.PartiQLValueExperimental * @property constructor */ internal class ExprSelect( - private val input: Operator.Relation, - private val constructor: Operator.Expr, + private val input: ExprRelation, + private val constructor: ExprValue, private val ordered: Boolean, -) : Operator.Expr { +) : ExprValue { @OptIn(PartiQLValueExperimental::class) class Elements( - private val input: Operator.Relation, - private val constructor: Operator.Expr, + private val input: ExprRelation, + private val constructor: ExprValue, private val env: Environment, ) : Iterable { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSpread.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSpread.kt index ac6a57abf2..03fc9ef878 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSpread.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSpread.kt @@ -1,16 +1,16 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.check -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.types.PType import org.partiql.value.PartiQLValueExperimental import org.partiql.value.PartiQLValueType internal class ExprSpread( - val args: Array -) : Operator.Expr { + val args: Array +) : ExprValue { @OptIn(PartiQLValueExperimental::class) override fun eval(env: Environment): Datum { diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructField.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructField.kt index d617bb88ef..9719fe6e98 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructField.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructField.kt @@ -1,5 +1,5 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.ExprValue -internal class ExprStructField(val key: Operator.Expr, val value: Operator.Expr) +internal class ExprStructField(val key: ExprValue, val value: ExprValue) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt index 6ef352296a..a76d713839 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructPermissive.kt @@ -1,12 +1,13 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum import org.partiql.spi.value.Field import org.partiql.types.PType -internal class ExprStructPermissive(private val fields: List) : Operator.Expr { +internal class ExprStructPermissive(private val fields: List) : + ExprValue { override fun eval(env: Environment): Datum { val fields = fields.mapNotNull { val key = it.key.eval(env) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructStrict.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructStrict.kt index 099f3218c6..2227c99113 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructStrict.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprStructStrict.kt @@ -1,13 +1,14 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.getText -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.spi.value.Field -internal class ExprStructStrict(private val fields: List) : Operator.Expr { +internal class ExprStructStrict(private val fields: List) : + ExprValue { override fun eval(env: Environment): Datum { val fields = fields.mapNotNull { val key = it.key.eval(env) diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubquery.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubquery.kt index 99bd718333..428554a6a6 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubquery.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubquery.kt @@ -2,9 +2,10 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.CardinalityViolation import org.partiql.errors.TypeCheckException -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.ValueUtility.check -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.types.PType @@ -13,7 +14,8 @@ import org.partiql.types.PType * * TODO REMOVE CONSTRUCTOR – TEMPORARY UNTIL SUBQUERIES ARE FIXED IN THE PLANNER. */ -internal class ExprSubquery(input: Operator.Relation, constructor: Operator.Expr) : Operator.Expr { +internal class ExprSubquery(input: ExprRelation, constructor: ExprValue) : + ExprValue { // DO NOT USE FINAL private var _input = input diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubqueryRow.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubqueryRow.kt index e4a2bb2f59..f0cd0feaea 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubqueryRow.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprSubqueryRow.kt @@ -1,17 +1,19 @@ package org.partiql.eval.internal.operator.rex import org.partiql.errors.CardinalityViolation -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment +import org.partiql.eval.ExprRelation +import org.partiql.eval.ExprValue import org.partiql.eval.internal.helpers.IteratorSupplier import org.partiql.eval.internal.helpers.ValueUtility.check -import org.partiql.eval.internal.operator.Operator import org.partiql.spi.value.Datum import org.partiql.types.PType /** * TODO REMOVE ME AFTER FIXING SUBQUERIES. */ -internal class ExprSubqueryRow(input: Operator.Relation, constructor: Operator.Expr) : Operator.Expr { +internal class ExprSubqueryRow(input: ExprRelation, constructor: ExprValue) : + ExprValue { // DO NOT USE FINAL private var _input = input diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprTable.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprTable.kt index 8a6be2e7d6..9b6781687a 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprTable.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprTable.kt @@ -1,7 +1,7 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.catalog.Table import org.partiql.spi.value.Datum @@ -12,7 +12,7 @@ import org.partiql.spi.value.Datum * * @param table */ -internal class ExprTable(table: Table) : Operator.Expr { +internal class ExprTable(table: Table) : ExprValue { // DO NOT USE FINAL private var _table = table diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprVar.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprVar.kt index b171b453ae..2184a0a8eb 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprVar.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/operator/rex/ExprVar.kt @@ -1,28 +1,16 @@ package org.partiql.eval.internal.operator.rex -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator +import org.partiql.eval.Environment +import org.partiql.eval.ExprValue import org.partiql.spi.value.Datum /** * Implementation for variable lookup; walks up environments if necessary, otherwise lookup using tuple offset. */ -internal class ExprVar(depth: Int, offset: Int) : Operator.Expr { +internal class ExprVar( + private var depth: Int, + private var offset: Int, +) : ExprValue { - // DO NOT USE FINAL - private var _depth = depth - private var _offset = offset - - override fun eval(env: Environment): Datum { - // shortcut for depth 0 - if (_depth == 0) { - return env[_offset] - } - // walk up environments - var curr = env - repeat(_depth) { - curr = curr.next() ?: error("We ran out of environments for depth ($_depth) and env: $env.") - } - return curr.getOrNull(_offset) ?: error("The env doesn't have a variable for depth/offset ($_depth/$_offset) and env: $env. Current is: $curr.") - } + override fun eval(env: Environment): Datum = env.get(depth, offset) } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/statement/QueryStatement.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/statement/QueryStatement.kt deleted file mode 100644 index 9b713eb632..0000000000 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/statement/QueryStatement.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.partiql.eval.internal.statement - -import org.partiql.eval.PartiQLResult -import org.partiql.eval.PartiQLStatement -import org.partiql.eval.internal.Environment -import org.partiql.eval.internal.operator.Operator -import org.partiql.spi.catalog.Session - -internal class QueryStatement(root: Operator.Expr) : PartiQLStatement { - - // DO NOT USE FINAL - private var _root = root - - override fun execute(session: Session): PartiQLResult { - val datum = _root.eval(Environment.empty) - val value = PartiQLResult.Value(datum) - return value - } -} diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt similarity index 95% rename from partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt rename to partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt index 045e31a7f8..158350ebc2 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEvaluatorTest.kt @@ -7,8 +7,8 @@ import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.PartiQLResult +import org.partiql.eval.Mode +import org.partiql.eval.compiler.PartiQLCompiler import org.partiql.parser.PartiQLParser import org.partiql.plan.Plan import org.partiql.planner.PartiQLPlanner @@ -41,10 +41,10 @@ import java.math.BigInteger import kotlin.test.assertNotNull /** - * This holds sanity tests during the development of the [PartiQLEngine.standard] implementation. + * This holds sanity tests during the development of the [PartiQLCompiler.standard] implementation. */ @OptIn(PartiQLValueExperimental::class) -class PartiQLEngineDefaultTest { +class PartiQLEvaluatorTest { @ParameterizedTest @MethodSource("sanityTestsCases") @@ -108,7 +108,7 @@ class PartiQLEngineDefaultTest { CAST(20 AS DECIMAL(1, 0)); """.trimIndent(), expected = missingValue(), - mode = PartiQLEngine.Mode.PERMISSIVE + mode = Mode.PERMISSIVE() ), SuccessTestCase( input = """ @@ -635,17 +635,17 @@ class PartiQLEngineDefaultTest { FROM [{'sensor':1, 'co':0.4}, {'sensor':1, 'co':0.2}, {'sensor':2, 'co':0.3}] AS l GROUP BY l.sensor AS sensor GROUP AS g """.trimIndent(), - expected = org.partiql.value.bagValue( - org.partiql.value.structValue( - "sensor" to org.partiql.value.int32Value(1), - "readings" to org.partiql.value.bagValue( + expected = bagValue( + structValue( + "sensor" to int32Value(1), + "readings" to bagValue( org.partiql.value.decimalValue(0.4.toBigDecimal()), org.partiql.value.decimalValue(0.2.toBigDecimal()) ) ), - org.partiql.value.structValue( - "sensor" to org.partiql.value.int32Value(2), - "readings" to org.partiql.value.bagValue( + structValue( + "sensor" to int32Value(2), + "readings" to bagValue( org.partiql.value.decimalValue(0.3.toBigDecimal()) ) ), @@ -731,7 +731,7 @@ class PartiQLEngineDefaultTest { SuccessTestCase( input = "SELECT t.a, s.b FROM << { 'a': 1 } >> t LEFT JOIN << { 'b': 2 } >> s ON false;", expected = bagValue(structValue("a" to int32Value(1), "b" to nullValue())), - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT() ), SuccessTestCase( input = "SELECT t.a, s.b FROM << { 'a': 1 } >> t FULL OUTER JOIN << { 'b': 2 } >> s ON false;", @@ -1055,7 +1055,7 @@ class PartiQLEngineDefaultTest { SuccessTestCase( input = "MISSING IS MISSING;", expected = boolValue(true), // TODO: Is this right? - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT(), ), SuccessTestCase( input = "SELECT VALUE t.a IS MISSING FROM << { 'b': 1 }, { 'a': 2 } >> AS t;", @@ -1070,7 +1070,7 @@ class PartiQLEngineDefaultTest { SuccessTestCase( input = "5 = 'a';", expected = boolValue(false), // TODO: Is this correct? - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT(), ), // PartiQL Specification Section 8 SuccessTestCase( @@ -1081,7 +1081,7 @@ class PartiQLEngineDefaultTest { SuccessTestCase( input = "NULL IS MISSING;", expected = boolValue(false), - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT(), ), SuccessTestCase( input = "SELECT * FROM <<{'a': 10, 'b': 1}, {'a': 1, 'b': 2}>> AS t ORDER BY t.a;", @@ -1149,7 +1149,7 @@ class PartiQLEngineDefaultTest { SuccessTestCase( input = "SELECT VALUE 5 + v FROM <<1, MISSING>> AS v;", expected = bagValue(int32Value(6), missingValue()), - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT(), ), ) @@ -1302,11 +1302,11 @@ class PartiQLEngineDefaultTest { public class SuccessTestCase @OptIn(PartiQLValueExperimental::class) constructor( val input: String, val expected: PartiQLValue, - val mode: PartiQLEngine.Mode = PartiQLEngine.Mode.PERMISSIVE, + val mode: Mode = Mode.PERMISSIVE(), val globals: List = emptyList(), ) { - private val engine = PartiQLEngine.builder().build() + private val compiler = PartiQLCompiler.standard() private val parser = PartiQLParser.standard() private val planner = PartiQLPlanner.standard() @@ -1339,16 +1339,8 @@ class PartiQLEngineDefaultTest { .catalogs(catalog) .build() val plan = planner.plan(statement, session).plan - val stmt = engine.prepare(plan, mode, session) - val result = when (val returned = stmt.execute(session)) { - is PartiQLResult.Value -> returned - is PartiQLResult.Error -> { - // TODO pretty-print V1 plans - System.err.append(plan.toString()) - throw returned.cause - } - } - val output = result.value.toPartiQLValue() // TODO: Assert directly on Datum + val result = compiler.prepare(plan, mode).execute() + val output = result.toPartiQLValue() // TODO: Assert directly on Datum assert(expected == output) { comparisonString(expected, output, plan) } @@ -1380,12 +1372,12 @@ class PartiQLEngineDefaultTest { val expectedPermissive: PartiQLValue, ) { - private val engine = PartiQLEngine.builder().build() + private val compiler = PartiQLCompiler.standard() private val parser = PartiQLParser.standard() private val planner = PartiQLPlanner.standard() internal fun assert() { - val (permissiveResult, plan) = run(mode = PartiQLEngine.Mode.PERMISSIVE) + val (permissiveResult, plan) = run(mode = Mode.PERMISSIVE()) val permissiveResultPValue = permissiveResult.toPartiQLValue() val assertionCondition = try { expectedPermissive == permissiveResultPValue // TODO: Assert using Datum @@ -1402,7 +1394,7 @@ class PartiQLEngineDefaultTest { } var error: Throwable? = null try { - val (strictResult, _) = run(mode = PartiQLEngine.Mode.STRICT) + val (strictResult, _) = run(mode = Mode.STRICT()) when (strictResult.type.kind) { PType.Kind.BAG, PType.Kind.ARRAY, PType.Kind.SEXP -> strictResult.toList() else -> strictResult @@ -1413,7 +1405,7 @@ class PartiQLEngineDefaultTest { assertNotNull(error) } - private fun run(mode: PartiQLEngine.Mode): Pair { + private fun run(mode: Mode): Pair { val statement = parser.parse(input).root val catalog = MemoryCatalog.builder().name("memory").build() val session = Session.builder() @@ -1421,18 +1413,8 @@ class PartiQLEngineDefaultTest { .catalogs(catalog) .build() val plan = planner.plan(statement, session).plan - val stmt = engine.prepare(plan, mode, session) - when (val result = stmt.execute(session)) { - is PartiQLResult.Value -> return result.value to plan - is PartiQLResult.Error -> { - val str = buildString { - appendLine("Execution resulted in an unexpected error. Plan:") - // TODO pretty-print V1 plans! - appendLine(plan) - } - throw RuntimeException(str, result.cause) - } - } + val result = compiler.prepare(plan, mode).execute() + return result to plan } @OptIn(PartiQLValueExperimental::class) @@ -1607,29 +1589,29 @@ class PartiQLEngineDefaultTest { { 'b': 4, 'c': NULL } >> AS t GROUP BY t.b AS gk_0; """.trimIndent(), - expected = org.partiql.value.bagValue( - org.partiql.value.structValue( - "gk_0" to org.partiql.value.int32Value(1), - "t_c_sum" to org.partiql.value.int32Value(3) + expected = bagValue( + structValue( + "gk_0" to int32Value(1), + "t_c_sum" to int32Value(3) ), - org.partiql.value.structValue( - "gk_0" to org.partiql.value.int32Value(2), - "t_c_sum" to org.partiql.value.int32Value(2) + structValue( + "gk_0" to int32Value(2), + "t_c_sum" to int32Value(2) ), - org.partiql.value.structValue( - "gk_0" to org.partiql.value.int32Value(3), - "t_c_sum" to org.partiql.value.int32Value(2) + structValue( + "gk_0" to int32Value(3), + "t_c_sum" to int32Value(2) ), - org.partiql.value.structValue( - "gk_0" to org.partiql.value.int32Value(4), - "t_c_sum" to org.partiql.value.int32Value(null) + structValue( + "gk_0" to int32Value(4), + "t_c_sum" to int32Value(null) ), - org.partiql.value.structValue( - "gk_0" to org.partiql.value.nullValue(), - "t_c_sum" to org.partiql.value.int32Value(3) + structValue( + "gk_0" to nullValue(), + "t_c_sum" to int32Value(3) ), ), - mode = org.partiql.eval.PartiQLEngine.Mode.PERMISSIVE + mode = Mode.PERMISSIVE() ).assert() // PartiQL Specification Section 8 @@ -1647,7 +1629,7 @@ class PartiQLEngineDefaultTest { fun missingAndTrueStrict() = SuccessTestCase( input = "MISSING AND TRUE;", expected = boolValue(null), // TODO: Is this right? - mode = PartiQLEngine.Mode.STRICT + mode = Mode.STRICT() ).assert() @Test diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt index e4441f40b3..39cf2e7e2b 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/operator/rex/ExprCallDynamicTest.kt @@ -5,7 +5,7 @@ import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import org.partiql.eval.internal.Environment +import org.partiql.eval.Environment import org.partiql.eval.internal.helpers.ValueUtility.check import org.partiql.spi.function.Function import org.partiql.spi.value.Datum @@ -38,7 +38,7 @@ class ExprCallDynamicTest { functions = functions, args = arrayOf(ExprLit(lhs), ExprLit(rhs)), ) - val result = expr.eval(Environment.empty).check(PartiQLValueType.INT32) + val result = expr.eval(Environment()).check(PartiQLValueType.INT32) assertEquals(expectedIndex, result.int) } diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index 9c04053d89..9ba5fa6691 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -133,6 +133,11 @@ public final class org/partiql/plan/Operation$Query$DefaultImpls { public static fun getType (Lorg/partiql/plan/Operation$Query;)Lorg/partiql/plan/rex/RexType; } +public abstract interface class org/partiql/plan/Operator { + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun getChildren ()Ljava/util/Collection; +} + public abstract interface class org/partiql/plan/Plan { public abstract fun getOperation ()Lorg/partiql/plan/Operation; public abstract fun getVersion ()Lorg/partiql/plan/Version; @@ -146,6 +151,99 @@ public abstract interface class org/partiql/plan/Version { public abstract fun toString ()Ljava/lang/String; } +public abstract interface class org/partiql/plan/Visitor { + public abstract fun defaultReturn (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun defaultVisit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitAggregate (Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitArray (Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitBag (Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCall (Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCallDynamic (Lorg/partiql/plan/rex/RexCallDynamic;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCase (Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCast (Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCoalesce (Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitCorrelate (Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitDistinct (Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitError (Lorg/partiql/plan/rel/RelError;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitError (Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitExcept (Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitExclude (Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitFilter (Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitIntersect (Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitIterate (Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitJoin (Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitLimit (Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitLit (Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitMissing (Lorg/partiql/plan/rex/RexMissing;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitNullIf (Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitOffset (Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitPathIndex (Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitPathKey (Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitPathSymbol (Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitPivot (Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitProject (Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitScan (Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSelect (Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSort (Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSpread (Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitStruct (Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSubquery (Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSubqueryComp (Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSubqueryIn (Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitTable (Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitUnion (Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitUnpivot (Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun visitVar (Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; +} + +public final class org/partiql/plan/Visitor$DefaultImpls { + public static fun defaultVisit (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visit (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitAggregate (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitArray (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitBag (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCall (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCallDynamic (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexCallDynamic;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCase (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCast (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCoalesce (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitCorrelate (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitDistinct (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitError (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelError;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitError (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitExcept (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitExclude (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitFilter (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitIntersect (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitIterate (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitJoin (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitLimit (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitLit (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitMissing (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexMissing;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitNullIf (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitOffset (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitPathIndex (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitPathKey (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitPathSymbol (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitPivot (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitProject (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitScan (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSelect (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSort (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSpread (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitStruct (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSubquery (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSubqueryComp (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSubqueryIn (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitSubqueryTest (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitTable (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitUnion (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitUnpivot (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; + public static fun visitVar (Lorg/partiql/plan/Visitor;Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; +} + public abstract interface class org/partiql/plan/builder/PlanFactory { public static final field Companion Lorg/partiql/plan/builder/PlanFactory$Companion; public static fun getSTANDARD ()Lorg/partiql/plan/builder/PlanFactory; @@ -359,15 +457,13 @@ public final class org/partiql/plan/builder/RexBuilder$Companion { public final fun variable (II)Lorg/partiql/plan/builder/RexBuilder; } -public abstract interface class org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract interface class org/partiql/plan/rel/Rel : org/partiql/plan/Operator { public abstract fun getType ()Lorg/partiql/plan/rel/RelType; public abstract fun isOrdered ()Z } public abstract interface class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getCalls ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getGroups ()Ljava/util/List; @@ -376,13 +472,13 @@ public abstract interface class org/partiql/plan/rel/RelAggregate : org/partiql/ } public final class org/partiql/plan/rel/RelAggregate$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelAggregate;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelAggregate;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelAggregate;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelAggregate;)Z } public abstract interface class org/partiql/plan/rel/RelCorrelate : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getJoinType ()Lorg/partiql/plan/JoinType; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; @@ -391,13 +487,13 @@ public abstract interface class org/partiql/plan/rel/RelCorrelate : org/partiql/ } public final class org/partiql/plan/rel/RelCorrelate$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelCorrelate;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelCorrelate;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelCorrelate;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelCorrelate;)Z } public abstract interface class org/partiql/plan/rel/RelDistinct : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getType ()Lorg/partiql/plan/rel/RelType; @@ -405,7 +501,7 @@ public abstract interface class org/partiql/plan/rel/RelDistinct : org/partiql/p } public final class org/partiql/plan/rel/RelDistinct$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelDistinct;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelDistinct;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelDistinct;)Ljava/util/Collection; public static fun getType (Lorg/partiql/plan/rel/RelDistinct;)Lorg/partiql/plan/rel/RelType; public static fun isOrdered (Lorg/partiql/plan/rel/RelDistinct;)Z @@ -413,7 +509,7 @@ public final class org/partiql/plan/rel/RelDistinct$DefaultImpls { public final class org/partiql/plan/rel/RelError : org/partiql/plan/rel/Rel { public fun (Ljava/lang/String;)V - public fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public fun getChildren ()Ljava/util/Collection; public final fun getMessage ()Ljava/lang/String; public fun getType ()Lorg/partiql/plan/rel/RelType; @@ -421,7 +517,7 @@ public final class org/partiql/plan/rel/RelError : org/partiql/plan/rel/Rel { } public abstract interface class org/partiql/plan/rel/RelExcept : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; @@ -430,13 +526,13 @@ public abstract interface class org/partiql/plan/rel/RelExcept : org/partiql/pla } public final class org/partiql/plan/rel/RelExcept$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelExcept;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelExcept;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelExcept;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelExcept;)Z } public abstract interface class org/partiql/plan/rel/RelExclude : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getExclusions ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; @@ -444,13 +540,13 @@ public abstract interface class org/partiql/plan/rel/RelExclude : org/partiql/pl } public final class org/partiql/plan/rel/RelExclude$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelExclude;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelExclude;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelExclude;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelExclude;)Z } public abstract interface class org/partiql/plan/rel/RelFilter : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getPredicate ()Lorg/partiql/plan/rex/Rex; @@ -459,14 +555,14 @@ public abstract interface class org/partiql/plan/rel/RelFilter : org/partiql/pla } public final class org/partiql/plan/rel/RelFilter$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelFilter;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelFilter;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelFilter;)Ljava/util/Collection; public static fun getType (Lorg/partiql/plan/rel/RelFilter;)Lorg/partiql/plan/rel/RelType; public static fun isOrdered (Lorg/partiql/plan/rel/RelFilter;)Z } public abstract interface class org/partiql/plan/rel/RelIntersect : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; @@ -475,26 +571,26 @@ public abstract interface class org/partiql/plan/rel/RelIntersect : org/partiql/ } public final class org/partiql/plan/rel/RelIntersect$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelIntersect;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelIntersect;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelIntersect;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelIntersect;)Z } public abstract interface class org/partiql/plan/rel/RelIterate : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rex/Rex; public abstract fun isOrdered ()Z } public final class org/partiql/plan/rel/RelIterate$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelIterate;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelIterate;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelIterate;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelIterate;)Z } public abstract interface class org/partiql/plan/rel/RelJoin : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getCondition ()Lorg/partiql/plan/rex/Rex; public abstract fun getJoinType ()Lorg/partiql/plan/JoinType; @@ -506,13 +602,13 @@ public abstract interface class org/partiql/plan/rel/RelJoin : org/partiql/plan/ } public final class org/partiql/plan/rel/RelJoin$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelJoin;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelJoin;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelJoin;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelJoin;)Z } public abstract interface class org/partiql/plan/rel/RelLimit : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getLimit ()Lorg/partiql/plan/rex/Rex; @@ -521,14 +617,14 @@ public abstract interface class org/partiql/plan/rel/RelLimit : org/partiql/plan } public final class org/partiql/plan/rel/RelLimit$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelLimit;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelLimit;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelLimit;)Ljava/util/Collection; public static fun getType (Lorg/partiql/plan/rel/RelLimit;)Lorg/partiql/plan/rel/RelType; public static fun isOrdered (Lorg/partiql/plan/rel/RelLimit;)Z } public abstract interface class org/partiql/plan/rel/RelOffset : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getOffset ()Lorg/partiql/plan/rex/Rex; @@ -537,14 +633,14 @@ public abstract interface class org/partiql/plan/rel/RelOffset : org/partiql/pla } public final class org/partiql/plan/rel/RelOffset$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelOffset;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelOffset;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelOffset;)Ljava/util/Collection; public static fun getType (Lorg/partiql/plan/rel/RelOffset;)Lorg/partiql/plan/rel/RelType; public static fun isOrdered (Lorg/partiql/plan/rel/RelOffset;)Z } public abstract interface class org/partiql/plan/rel/RelProject : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getProjections ()Ljava/util/List; @@ -552,14 +648,14 @@ public abstract interface class org/partiql/plan/rel/RelProject : org/partiql/pl } public final class org/partiql/plan/rel/RelProject$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelProject;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelProject;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelProject;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelProject;)Z } public final class org/partiql/plan/rel/RelProjectImpl : org/partiql/plan/rel/RelProject { public fun (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)V - public fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public fun equals (Ljava/lang/Object;)Z public fun getChildren ()Ljava/util/Collection; public fun getInput ()Lorg/partiql/plan/rel/Rel; @@ -570,20 +666,20 @@ public final class org/partiql/plan/rel/RelProjectImpl : org/partiql/plan/rel/Re } public abstract interface class org/partiql/plan/rel/RelScan : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rex/Rex; public abstract fun isOrdered ()Z } public final class org/partiql/plan/rel/RelScan$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelScan;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelScan;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelScan;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelScan;)Z } public abstract interface class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getCollations ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; @@ -592,7 +688,7 @@ public abstract interface class org/partiql/plan/rel/RelSort : org/partiql/plan/ } public final class org/partiql/plan/rel/RelSort$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelSort;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelSort;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelSort;)Ljava/util/Collection; public static fun getType (Lorg/partiql/plan/rel/RelSort;)Lorg/partiql/plan/rel/RelType; public static fun isOrdered (Lorg/partiql/plan/rel/RelSort;)Z @@ -609,7 +705,7 @@ public final class org/partiql/plan/rel/RelType$DefaultImpls { } public abstract interface class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; @@ -618,111 +714,64 @@ public abstract interface class org/partiql/plan/rel/RelUnion : org/partiql/plan } public final class org/partiql/plan/rel/RelUnion$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelUnion;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelUnion;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelUnion;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelUnion;)Z } public abstract interface class org/partiql/plan/rel/RelUnpivot : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rex/Rex; public abstract fun isOrdered ()Z } public final class org/partiql/plan/rel/RelUnpivot$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelUnpivot;Lorg/partiql/plan/rel/RelVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rel/RelUnpivot;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rel/RelUnpivot;)Ljava/util/Collection; public static fun isOrdered (Lorg/partiql/plan/rel/RelUnpivot;)Z } -public abstract interface class org/partiql/plan/rel/RelVisitor { - public abstract fun defaultReturn (Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun defaultVisit (Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visit (Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitAggregate (Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCorrelate (Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitDistinct (Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitError (Lorg/partiql/plan/rel/RelError;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitExcept (Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitExclude (Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitFilter (Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitIntersect (Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitIterate (Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitJoin (Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitLimit (Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitOffset (Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitProject (Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitScan (Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSort (Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitUnion (Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitUnpivot (Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class org/partiql/plan/rel/RelVisitor$DefaultImpls { - public static fun defaultVisit (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visit (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitAggregate (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCorrelate (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitDistinct (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitError (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelError;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitExcept (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitExclude (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitFilter (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitIntersect (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitIterate (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitJoin (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitLimit (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitOffset (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitProject (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitScan (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSort (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitUnion (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitUnpivot (Lorg/partiql/plan/rel/RelVisitor;Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract interface class org/partiql/plan/rex/Rex : org/partiql/plan/Operator { public abstract fun getType ()Lorg/partiql/plan/rex/RexType; } public abstract interface class org/partiql/plan/rex/RexArray : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getValues ()Ljava/util/Collection; } public final class org/partiql/plan/rex/RexArray$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexArray;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexArray;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexArray;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexBag : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getValues ()Ljava/util/Collection; } public final class org/partiql/plan/rex/RexBag$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexBag;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexBag;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexBag;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexCall : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getFunction ()Lorg/partiql/spi/function/Function$Instance; } public final class org/partiql/plan/rex/RexCall$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCall;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexCall;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexCall;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexCallDynamic : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getFunctions ()Ljava/util/List; @@ -730,12 +779,12 @@ public abstract interface class org/partiql/plan/rex/RexCallDynamic : org/partiq } public final class org/partiql/plan/rex/RexCallDynamic$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCallDynamic;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexCallDynamic;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexCallDynamic;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getBranches ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getDefault ()Lorg/partiql/plan/rex/Rex; @@ -748,112 +797,112 @@ public abstract interface class org/partiql/plan/rex/RexCase$Branch { } public final class org/partiql/plan/rex/RexCase$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCase;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexCase;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexCase;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexCast : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; public abstract fun getTarget ()Lorg/partiql/types/PType; } public final class org/partiql/plan/rex/RexCast$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCast;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexCast;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexCast;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexCoalesce : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; } public final class org/partiql/plan/rex/RexCoalesce$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCoalesce;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexCoalesce;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexCoalesce;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexError : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getMessage ()Ljava/lang/String; public abstract fun getTrace ()Ljava/util/List; } public final class org/partiql/plan/rex/RexError$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexError;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexError;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexError;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexLit : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getValue ()Lorg/partiql/spi/value/Datum; } public final class org/partiql/plan/rex/RexLit$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexLit;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexLit;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexLit;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexMissing : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getMessage ()Ljava/lang/String; public abstract fun getTrace ()Ljava/util/List; } public final class org/partiql/plan/rex/RexMissing$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexMissing;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexMissing;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexMissing;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexNullIf : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getV1 ()Lorg/partiql/plan/rex/Rex; public abstract fun getV2 ()Lorg/partiql/plan/rex/Rex; } public final class org/partiql/plan/rex/RexNullIf$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexNullIf;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexNullIf;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexNullIf;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexPathIndex : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getIndex ()Lorg/partiql/plan/rex/Rex; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; } public final class org/partiql/plan/rex/RexPathIndex$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathIndex;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexPathIndex;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class org/partiql/plan/rex/RexPathKey : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getKey ()Lorg/partiql/plan/rex/Rex; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; } public final class org/partiql/plan/rex/RexPathKey$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathKey;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexPathKey;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class org/partiql/plan/rex/RexPathSymbol : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; public abstract fun getSymbol ()Ljava/lang/String; } public final class org/partiql/plan/rex/RexPathSymbol$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathSymbol;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexPathSymbol;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class org/partiql/plan/rex/RexPivot : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getKey ()Lorg/partiql/plan/rex/Rex; @@ -861,41 +910,41 @@ public abstract interface class org/partiql/plan/rex/RexPivot : org/partiql/plan } public final class org/partiql/plan/rex/RexPivot$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPivot;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexPivot;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexPivot;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexSelect : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getConstructor ()Lorg/partiql/plan/rex/Rex; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; } public final class org/partiql/plan/rex/RexSelect$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSelect;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSelect;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexSelect;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexSpread : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getChildren ()Ljava/util/Collection; } public final class org/partiql/plan/rex/RexSpread$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSpread;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSpread;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexSpread;)Ljava/util/Collection; } public abstract interface class org/partiql/plan/rex/RexStruct : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getFields ()Ljava/util/List; } public final class org/partiql/plan/rex/RexStruct$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexStruct;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexStruct;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexStruct;)Ljava/util/Collection; } @@ -906,18 +955,18 @@ public final class org/partiql/plan/rex/RexStruct$Field { } public abstract interface class org/partiql/plan/rex/RexSubquery : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun asScalar ()Z public abstract fun getConstructor ()Lorg/partiql/plan/rex/Rex; public abstract fun getRel ()Lorg/partiql/plan/rel/Rel; } public final class org/partiql/plan/rex/RexSubquery$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubquery;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSubquery;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class org/partiql/plan/rex/RexSubqueryComp : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getComp ()Lorg/partiql/plan/rex/RexSubqueryComp$Comp; public abstract fun getQuantifier ()Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; @@ -938,7 +987,7 @@ public final class org/partiql/plan/rex/RexSubqueryComp$Comp : java/lang/Enum { } public final class org/partiql/plan/rex/RexSubqueryComp$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubqueryComp;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSubqueryComp;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public final class org/partiql/plan/rex/RexSubqueryComp$Quantifier : java/lang/Enum { @@ -952,23 +1001,23 @@ public final class org/partiql/plan/rex/RexSubqueryComp$Quantifier : java/lang/E } public abstract interface class org/partiql/plan/rex/RexSubqueryIn : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getArgs ()Ljava/util/List; public abstract fun getRel ()Lorg/partiql/plan/rel/Rel; } public final class org/partiql/plan/rex/RexSubqueryIn$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubqueryIn;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSubqueryIn;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public abstract interface class org/partiql/plan/rex/RexSubqueryTest : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getRel ()Lorg/partiql/plan/rel/Rel; public abstract fun getTest ()Lorg/partiql/plan/rex/RexSubqueryTest$Test; } public final class org/partiql/plan/rex/RexSubqueryTest$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubqueryTest;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexSubqueryTest;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; } public final class org/partiql/plan/rex/RexSubqueryTest$Test : java/lang/Enum { @@ -981,13 +1030,13 @@ public final class org/partiql/plan/rex/RexSubqueryTest$Test : java/lang/Enum { } public abstract interface class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getTable ()Lorg/partiql/spi/catalog/Table; } public final class org/partiql/plan/rex/RexTable$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexTable;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexTable;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexTable;)Ljava/util/Collection; } @@ -1006,73 +1055,14 @@ public final class org/partiql/plan/rex/RexType$Companion { } public abstract interface class org/partiql/plan/rex/RexVar : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getDepth ()I public abstract fun getOffset ()I } public final class org/partiql/plan/rex/RexVar$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexVar;Lorg/partiql/plan/rex/RexVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun accept (Lorg/partiql/plan/rex/RexVar;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun getChildren (Lorg/partiql/plan/rex/RexVar;)Ljava/util/Collection; } -public abstract interface class org/partiql/plan/rex/RexVisitor { - public abstract fun defaultReturn (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun defaultVisit (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visit (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitArray (Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitBag (Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCall (Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCallDynamic (Lorg/partiql/plan/rex/RexCallDynamic;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCase (Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCast (Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitCoalesce (Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitError (Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitLit (Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitMissing (Lorg/partiql/plan/rex/RexMissing;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitNullIf (Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitPathIndex (Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitPathKey (Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitPathSymbol (Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitPivot (Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSelect (Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSpread (Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitStruct (Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSubquery (Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSubqueryComp (Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSubqueryIn (Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitTable (Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun visitVar (Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class org/partiql/plan/rex/RexVisitor$DefaultImpls { - public static fun defaultVisit (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visit (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitArray (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitBag (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCall (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCallDynamic (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexCallDynamic;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCase (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCast (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitCoalesce (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitError (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitLit (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitMissing (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexMissing;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitNullIf (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitPathIndex (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitPathKey (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitPathSymbol (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitPivot (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSelect (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSpread (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitStruct (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSubquery (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSubqueryComp (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSubqueryIn (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitSubqueryTest (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitTable (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; - public static fun visitVar (Lorg/partiql/plan/rex/RexVisitor;Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; -} - diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operator.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Operator.kt new file mode 100644 index 0000000000..1a2196b5aa --- /dev/null +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Operator.kt @@ -0,0 +1,11 @@ +package org.partiql.plan + +/** + * Operator is the interface for a logical plan operator. + */ +public interface Operator { + + public fun accept(visitor: Visitor, ctx: C): R + + public fun getChildren(): Collection +} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Visitor.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Visitor.kt new file mode 100644 index 0000000000..e50cfc208f --- /dev/null +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Visitor.kt @@ -0,0 +1,149 @@ +package org.partiql.plan + +import org.partiql.plan.rel.RelAggregate +import org.partiql.plan.rel.RelCorrelate +import org.partiql.plan.rel.RelDistinct +import org.partiql.plan.rel.RelError +import org.partiql.plan.rel.RelExcept +import org.partiql.plan.rel.RelExclude +import org.partiql.plan.rel.RelFilter +import org.partiql.plan.rel.RelIntersect +import org.partiql.plan.rel.RelIterate +import org.partiql.plan.rel.RelJoin +import org.partiql.plan.rel.RelLimit +import org.partiql.plan.rel.RelOffset +import org.partiql.plan.rel.RelProject +import org.partiql.plan.rel.RelScan +import org.partiql.plan.rel.RelSort +import org.partiql.plan.rel.RelUnion +import org.partiql.plan.rel.RelUnpivot +import org.partiql.plan.rex.RexArray +import org.partiql.plan.rex.RexBag +import org.partiql.plan.rex.RexCall +import org.partiql.plan.rex.RexCallDynamic +import org.partiql.plan.rex.RexCase +import org.partiql.plan.rex.RexCast +import org.partiql.plan.rex.RexCoalesce +import org.partiql.plan.rex.RexError +import org.partiql.plan.rex.RexLit +import org.partiql.plan.rex.RexMissing +import org.partiql.plan.rex.RexNullIf +import org.partiql.plan.rex.RexPathIndex +import org.partiql.plan.rex.RexPathKey +import org.partiql.plan.rex.RexPathSymbol +import org.partiql.plan.rex.RexPivot +import org.partiql.plan.rex.RexSelect +import org.partiql.plan.rex.RexSpread +import org.partiql.plan.rex.RexStruct +import org.partiql.plan.rex.RexSubquery +import org.partiql.plan.rex.RexSubqueryComp +import org.partiql.plan.rex.RexSubqueryIn +import org.partiql.plan.rex.RexSubqueryTest +import org.partiql.plan.rex.RexTable +import org.partiql.plan.rex.RexVar + +/** + * A visitor for a logical [Operator] tree. + * + * @param R Visit return type + * @param C Context parameter type + */ +public interface Visitor { + + public fun defaultVisit(operator: Operator, ctx: C): R { + for (child in operator.getChildren()) { + child.accept(this, ctx) + } + return defaultReturn(operator, ctx) + } + + public fun defaultReturn(operator: Operator, ctx: C): R + + public fun visit(operator: Operator, ctx: C): R = operator.accept(this, ctx) + + // --[Rel]----------------------------------------------------------------------------------------------------------- + + public fun visitAggregate(rel: RelAggregate, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitDistinct(rel: RelDistinct, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitError(rel: RelError, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitExcept(rel: RelExcept, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitExclude(rel: RelExclude, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitFilter(rel: RelFilter, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitIntersect(rel: RelIntersect, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitIterate(rel: RelIterate, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitJoin(rel: RelJoin, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitCorrelate(rel: RelCorrelate, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitLimit(rel: RelLimit, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitOffset(rel: RelOffset, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitProject(rel: RelProject, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitScan(rel: RelScan, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitSort(rel: RelSort, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitUnion(rel: RelUnion, ctx: C): R = defaultVisit(rel, ctx) + + public fun visitUnpivot(rel: RelUnpivot, ctx: C): R = defaultVisit(rel, ctx) + + // --[Rex]----------------------------------------------------------------------------------------------------------- + + public fun visitArray(rex: RexArray, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitBag(rex: RexBag, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitCall(rex: RexCall, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitCallDynamic(rex: RexCallDynamic, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitCase(rex: RexCase, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitCast(rex: RexCast, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitCoalesce(rex: RexCoalesce, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitError(rex: RexError, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitLit(rex: RexLit, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitMissing(rex: RexMissing, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitNullIf(rex: RexNullIf, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitPathIndex(rex: RexPathIndex, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitPathKey(rex: RexPathKey, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitPathSymbol(rex: RexPathSymbol, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitPivot(rex: RexPivot, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSelect(rex: RexSelect, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitStruct(rex: RexStruct, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSubquery(rex: RexSubquery, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSubqueryComp(rex: RexSubqueryComp, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSubqueryIn(rex: RexSubqueryIn, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSubqueryTest(rex: RexSubqueryTest, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitSpread(rex: RexSpread, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitTable(rex: RexTable, ctx: C): R = defaultVisit(rex, ctx) + + public fun visitVar(rex: RexVar, ctx: C): R = defaultVisit(rex, ctx) +} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt index 633b5c23b3..6e4f943d52 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt @@ -417,7 +417,8 @@ public interface PlanFactory { * @param type * @return */ - public fun rexCase(branches: List, default: Rex?, type: RexType): RexCase = rexCase(null, branches, default, type) + public fun rexCase(branches: List, default: Rex?, type: RexType): RexCase = + rexCase(null, branches, default, type) /** * Create a [RexCase] instance for a case-when with dynamic type. diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt index 671fe0fc53..55d3d9af86 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt @@ -1,15 +1,13 @@ package org.partiql.plan.rel +import org.partiql.plan.Operator + /** - * TODO DOCUMENTATION + * A [Rel] is an [Operator] that produces a collection of tuples. */ -public interface Rel { +public interface Rel : Operator { public fun getType(): RelType public fun isOrdered(): Boolean - - public fun getChildren(): Collection - - public fun accept(visitor: RelVisitor, ctx: C): R } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt index 7b63bd2681..4a0c0e550d 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt @@ -1,6 +1,7 @@ package org.partiql.plan.rel import org.partiql.plan.AggregateCall +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -19,7 +20,7 @@ public interface RelAggregate : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitAggregate(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt index b9ed534a00..b8f51b2f49 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt @@ -1,6 +1,7 @@ package org.partiql.plan.rel import org.partiql.plan.JoinType +import org.partiql.plan.Visitor /** * Logical operator for nested-loop joins (correlated subqueries // lateral joins). @@ -17,7 +18,7 @@ public interface RelCorrelate : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCorrelate(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt index 347429e4e6..77ae8a3b56 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor + /** * Logical `DISTINCT` operator. */ @@ -13,7 +15,7 @@ public interface RelDistinct : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitDistinct(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelError.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelError.kt index f855004af1..cb63be7655 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelError.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelError.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor + /** * TODO DELETE ME IN rc2 */ @@ -13,5 +15,5 @@ public class RelError(public val message: String) : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitError(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitError(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt index f2d3d983a2..a74cb8a33e 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor + /** * Logical `EXCEPT [ALL|DISTINCT]` operator for set (or multiset) difference. */ @@ -15,7 +17,7 @@ public interface RelExcept : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitExcept(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt index 8fbb2d95af..3e3522b5e5 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt @@ -1,6 +1,7 @@ package org.partiql.plan.rel import org.partiql.plan.Exclusion +import org.partiql.plan.Visitor /** * Logical `EXCLUDE` operation. @@ -15,7 +16,7 @@ public interface RelExclude : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitExclude(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt index 646327aef2..18fc542b8d 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -17,7 +18,7 @@ public interface RelFilter : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitFilter(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt index 03528459a7..4062ff6c45 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor + /** * Logical `INTERSECT [ALL|DISTINCT]` operator for set (or multiset) intersection. */ @@ -15,7 +17,7 @@ public interface RelIntersect : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitIntersect(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt index 29c33d580e..15b6cc9a58 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -13,7 +14,7 @@ public interface RelIterate : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitIterate(this, ctx) } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt index d8a0e1b799..6846b08175 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt @@ -1,6 +1,7 @@ package org.partiql.plan.rel import org.partiql.plan.JoinType +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -26,7 +27,7 @@ public interface RelJoin : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitJoin(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitJoin(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt index 379848c35e..ada7af34bf 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -17,7 +18,7 @@ public interface RelLimit : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitLimit(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitLimit(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt index a94df599f7..5ab13454ff 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -17,7 +18,7 @@ public interface RelOffset : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitOffset(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitOffset(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt index 3653c863e6..3e50f26da5 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -15,7 +16,7 @@ public interface RelProject : Rel { override fun isOrdered(): Boolean = getInput().isOrdered() - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitProject(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitProject(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt index b7a240e20e..6c98ce1db0 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -13,7 +14,7 @@ public interface RelScan : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitScan(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitScan(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt index 3c1fe0d3b3..31ee8c8df4 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt @@ -1,6 +1,7 @@ package org.partiql.plan.rel import org.partiql.plan.Collation +import org.partiql.plan.Visitor /** * Logical sort operator. @@ -17,7 +18,7 @@ public interface RelSort : Rel { override fun isOrdered(): Boolean = true - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitSort(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSort(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt index a66f82b27e..ecfb2dcfc2 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor + /** * Logical `UNION [ALL|DISTINCT]` operator for set (or multiset) union. */ @@ -15,7 +17,7 @@ public interface RelUnion : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitUnion(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitUnion(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt index 4ccec4c7dd..d64278c9c6 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rel +import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex /** @@ -13,7 +14,7 @@ public interface RelUnpivot : Rel { override fun isOrdered(): Boolean = false - override fun accept(visitor: RelVisitor, ctx: C): R = visitor.visitUnpivot(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitUnpivot(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelVisitor.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelVisitor.kt deleted file mode 100644 index 38c0d3010b..0000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelVisitor.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.partiql.plan.rel - -/** - * TODO DOCUMENTATION - * - * @param R Visit return type - * @param C Context parameter type - */ -public interface RelVisitor { - - public fun defaultVisit(rel: Rel, ctx: C): R { - for (child in rel.getChildren()) { - child.accept(this, ctx) - } - return defaultReturn(rel, ctx) - } - - public fun defaultReturn(rel: Rel, ctx: C): R - - public fun visit(rel: Rel, ctx: C): R = rel.accept(this, ctx) - - public fun visitAggregate(rel: RelAggregate, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitDistinct(rel: RelDistinct, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitError(rel: RelError, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitExcept(rel: RelExcept, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitExclude(rel: RelExclude, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitFilter(rel: RelFilter, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitIntersect(rel: RelIntersect, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitIterate(rel: RelIterate, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitJoin(rel: RelJoin, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitCorrelate(rel: RelCorrelate, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitLimit(rel: RelLimit, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitOffset(rel: RelOffset, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitProject(rel: RelProject, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitScan(rel: RelScan, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitSort(rel: RelSort, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitUnion(rel: RelUnion, ctx: C): R = defaultVisit(rel, ctx) - - public fun visitUnpivot(rel: RelUnpivot, ctx: C): R = defaultVisit(rel, ctx) -} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt index c530979bca..df78b03fc6 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt @@ -1,13 +1,11 @@ package org.partiql.plan.rex +import org.partiql.plan.Operator + /** - * TODO DOCUMENTATION + * A [Rex] is an [Operator] that produces a value. */ -public interface Rex { +public interface Rex : Operator { public fun getType(): RexType - - public fun getChildren(): Collection - - public fun accept(visitor: RexVisitor, ctx: C): R } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt index ed210ef542..f979194d56 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION */ @@ -9,7 +11,7 @@ public interface RexArray : Rex { override fun getChildren(): Collection = getValues().toList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitArray(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitArray(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt index b0ce1e6cf3..7b2acba378 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION */ @@ -9,7 +11,7 @@ public interface RexBag : Rex { override fun getChildren(): Collection = getValues() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitBag(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitBag(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt index 8a31b968f7..bfe39ec06f 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.spi.function.Function /** @@ -19,7 +20,7 @@ public interface RexCall : Rex { override fun getChildren(): Collection = getArgs() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitCall(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCall(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt index ec781451c4..af9fece070 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.spi.function.Function /** @@ -24,7 +25,7 @@ public interface RexCallDynamic : Rex { override fun getChildren(): Collection = getArgs() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitCallDynamic(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCallDynamic(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt index e02ebbc8dd..4d6a665ba7 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Representative of the simple CASE-WHEN. */ @@ -11,7 +13,7 @@ public interface RexCase : Rex { public fun getDefault(): Rex? - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitCase(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCase(this, ctx) override fun getChildren(): Collection { val children = mutableListOf() diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt index 680072d2ae..96f21fb208 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.types.PType /** @@ -13,7 +14,7 @@ public interface RexCast : Rex { override fun getChildren(): Collection = listOf(getOperand()) - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitCast(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCast(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt index 69321874fd..aa7cef41ab 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION */ @@ -9,7 +11,7 @@ public interface RexCoalesce : Rex { override fun getChildren(): Collection = getArgs() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitCoalesce(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCoalesce(this, ctx) } internal class RexCoalesceImpl(args: List, type: RexType) : RexCoalesce { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt index 211ea12d35..bfe7b21517 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + public interface RexError : Rex { public fun getMessage(): String @@ -8,7 +10,7 @@ public interface RexError : Rex { override fun getChildren(): Collection = emptyList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitError(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitError(this, ctx) } internal class RexErrorImpl(message: String, trace: List) : RexError { @@ -31,7 +33,7 @@ public interface RexMissing : Rex { override fun getChildren(): Collection = emptyList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitMissing(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitMissing(this, ctx) } internal class RexMissingImpl(message: String, trace: List) : RexMissing { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt index 0140449ac8..954b0fe6df 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.spi.value.Datum /** @@ -11,7 +12,7 @@ public interface RexLit : Rex { override fun getChildren(): Collection = emptyList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitLit(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitLit(this, ctx) } internal class RexLitImpl(value: Datum) : RexLit { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt index 67e3ef937f..9f98216cbc 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Logical operator for the SQL NULLIF special form. */ @@ -11,7 +13,7 @@ public interface RexNullIf : Rex { override fun getChildren(): Collection = listOf(getV1(), getV2()) - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitNullIf(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitNullIf(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt index c4fb686de2..926e1f0a78 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Logical path index operator. */ @@ -9,7 +11,7 @@ public interface RexPathIndex : Rex { public fun getIndex(): Rex - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitPathIndex(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathIndex(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt index 06e3c0ab4b..97d27ddda8 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Logical operator for path lookup by key. */ @@ -9,7 +11,7 @@ public interface RexPathKey : Rex { public fun getKey(): Rex - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitPathKey(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathKey(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt index d5c8a6dee6..2b4d400e7c 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Logical operator for path lookup by symbol. */ @@ -9,7 +11,7 @@ public interface RexPathSymbol : Rex { public fun getSymbol(): String - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitPathSymbol(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathSymbol(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt index cc677d315d..05c6bd9001 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.plan.rel.Rel import org.partiql.types.PType @@ -16,7 +17,7 @@ public interface RexPivot : Rex { override fun getChildren(): Collection = listOf(getKey(), getValue()) - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitPivot(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPivot(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt index 0733671879..95096cc871 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.plan.rel.Rel import org.partiql.types.PType @@ -14,7 +15,7 @@ public interface RexSelect : Rex { override fun getChildren(): Collection = listOf(getConstructor()) - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSelect(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSelect(this, ctx) } internal class RexSelectImpl(input: Rel, constructor: Rex) : RexSelect { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt index c3a8659d38..f4157f8c4c 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION */ @@ -9,7 +11,7 @@ public interface RexSpread : Rex { override fun getChildren(): Collection = getArgs() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSpread(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSpread(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt index 0a9dbe172a..3ad4cfffc5 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION */ @@ -16,7 +18,7 @@ public interface RexStruct : Rex { return children } - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitStruct(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitStruct(this, ctx) /** * TODO DOCUMENTATION diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt index 52af4aa333..9d94538ea3 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * Scalar subquery coercion. */ @@ -13,7 +15,7 @@ public interface RexSubquery : Rex { // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES public fun asScalar(): Boolean - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSubquery(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubquery(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt index 7506321f9c..7d9ae0093a 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.plan.rel.Rel import org.partiql.plan.rex.RexSubqueryComp.Comp import org.partiql.plan.rex.RexSubqueryComp.Quantifier @@ -20,7 +21,7 @@ public interface RexSubqueryComp : Rex { public fun getRel(): Rel - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSubqueryComp(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryComp(this, ctx) /** * SQL for use in the . diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt index 7f407ea745..c742274a07 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.plan.rel.Rel public interface RexSubqueryIn : Rex { @@ -8,7 +9,7 @@ public interface RexSubqueryIn : Rex { public fun getRel(): Rel - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSubqueryIn(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryIn(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt index 5e6db52357..9ad2ab6bd3 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.plan.rex.RexSubqueryTest.Test /** @@ -14,7 +15,7 @@ public interface RexSubqueryTest : Rex { public fun getRel(): org.partiql.plan.rel.Rel - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitSubqueryTest(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryTest(this, ctx) /** * EXISTS and UNIQUE are defined by SQL. diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt index db161ae271..8bef45722b 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt @@ -1,5 +1,6 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor import org.partiql.spi.catalog.Table /** @@ -11,7 +12,7 @@ public interface RexTable : Rex { override fun getChildren(): Collection = emptyList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitTable(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitTable(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt index fd68924251..709626dc37 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt @@ -1,5 +1,7 @@ package org.partiql.plan.rex +import org.partiql.plan.Visitor + /** * TODO DOCUMENTATION * TODO NAMING?? @@ -18,7 +20,7 @@ public interface RexVar : Rex { override fun getChildren(): Collection = emptyList() - override fun accept(visitor: RexVisitor, ctx: C): R = visitor.visitVar(this, ctx) + override fun accept(visitor: Visitor, ctx: C): R = visitor.visitVar(this, ctx) } /** diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVisitor.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVisitor.kt deleted file mode 100644 index 370f4df0e4..0000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVisitor.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.partiql.plan.rex - -/** - * TODO DOCUMENTATION - * - * @param R Visit return type - * @param C Context parameter type - */ -public interface RexVisitor { - - public fun defaultVisit(rex: Rex, ctx: C): R { - for (child in rex.getChildren()) { - child.accept(this, ctx) - } - return defaultReturn(rex, ctx) - } - - public fun defaultReturn(rex: Rex, ctx: C): R - - public fun visit(rex: Rex, ctx: C): R = rex.accept(this, ctx) - - public fun visitArray(rex: RexArray, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitBag(rex: RexBag, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitCall(rex: RexCall, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitCallDynamic(rex: RexCallDynamic, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitCase(rex: RexCase, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitCast(rex: RexCast, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitCoalesce(rex: RexCoalesce, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitError(rex: RexError, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitLit(rex: RexLit, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitMissing(rex: RexMissing, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitNullIf(rex: RexNullIf, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitPathIndex(rex: RexPathIndex, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitPathKey(rex: RexPathKey, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitPathSymbol(rex: RexPathSymbol, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitPivot(rex: RexPivot, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSelect(rex: RexSelect, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitStruct(rex: RexStruct, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSubquery(rex: RexSubquery, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSubqueryComp(rex: RexSubqueryComp, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSubqueryIn(rex: RexSubqueryIn, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSubqueryTest(rex: RexSubqueryTest, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitSpread(rex: RexSpread, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitTable(rex: RexTable, ctx: C): R = defaultVisit(rex, ctx) - - public fun visitVar(rex: RexVar, ctx: C): R = defaultVisit(rex, ctx) -} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt index e2130cc620..0fe2d36355 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt @@ -3,8 +3,9 @@ package org.partiql.planner import org.partiql.plan.Operation +import org.partiql.plan.Operator import org.partiql.plan.Plan -import org.partiql.plan.rel.Rel +import org.partiql.plan.Visitor import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelCorrelate import org.partiql.plan.rel.RelDistinct @@ -21,8 +22,6 @@ import org.partiql.plan.rel.RelScan import org.partiql.plan.rel.RelSort import org.partiql.plan.rel.RelUnion import org.partiql.plan.rel.RelUnpivot -import org.partiql.plan.rel.RelVisitor -import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexArray import org.partiql.plan.rex.RexBag import org.partiql.plan.rex.RexCall @@ -47,14 +46,13 @@ import org.partiql.plan.rex.RexSubqueryIn import org.partiql.plan.rex.RexSubqueryTest import org.partiql.plan.rex.RexTable import org.partiql.plan.rex.RexVar -import org.partiql.plan.rex.RexVisitor /** * This class asserts the equivalence of two query plans. * * Replacement for https://github.com/partiql/partiql-lang-kotlin/blob/main/partiql-planner/src/test/kotlin/org/partiql/planner/util/PlanNodeEquivalentVisitor.kt#L16 */ -object PlanEquivalenceVisitor : RelVisitor, RexVisitor { +object PlanEquivalenceVisitor : Visitor { @JvmStatic public fun equals(p1: Plan, p2: Plan): Boolean = visitPlan(p1, p2) @@ -80,9 +78,7 @@ object PlanEquivalenceVisitor : RelVisitor, RexVisitor() { +class ConformanceTestEval : ConformanceTestBase() { companion object { @JvmStatic @RegisterExtension diff --git a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt index ccc65af24f..7eadbf55e8 100644 --- a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt +++ b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt @@ -7,9 +7,9 @@ import com.amazon.ionelement.api.ElementType import com.amazon.ionelement.api.StructElement import com.amazon.ionelement.api.toIonElement import com.amazon.ionelement.api.toIonValue -import org.partiql.eval.PartiQLEngine -import org.partiql.eval.PartiQLResult -import org.partiql.eval.PartiQLStatement +import org.partiql.eval.Mode +import org.partiql.eval.Statement +import org.partiql.eval.compiler.PartiQLCompiler import org.partiql.parser.PartiQLParser import org.partiql.plan.Operation.Query import org.partiql.planner.PartiQLPlanner @@ -35,47 +35,33 @@ import org.partiql.value.toIon @OptIn(PartiQLValueExperimental::class) class EvalExecutor( private val session: Session, - private val mode: PartiQLEngine.Mode, -) : TestExecutor { + private val mode: Mode, +) : TestExecutor { - override fun prepare(statement: String): PartiQLStatement { - val stmt = parser.parse(statement).root - val plan = planner.plan(stmt, session).plan - return engine.prepare(plan, mode, session) + override fun prepare(input: String): Statement { + val ast = parser.parse(input).root + val plan = planner.plan(ast, session).plan + return compiler.prepare(plan, mode) } - override fun execute(statement: PartiQLStatement): PartiQLResult { - return statement.execute(session) + override fun execute(input: Statement): Datum { + return input.execute() } - override fun fromIon(value: IonValue): PartiQLResult { + override fun fromIon(value: IonValue): Datum { val partiql = PartiQLValueIonReaderBuilder.standard().build(value.toIonElement()).read() val datum = Datum.of(partiql) - - return PartiQLResult.Value(datum) + return datum } - override fun toIon(value: PartiQLResult): IonValue { - if (value is PartiQLResult.Value) { - return value.value.toPartiQLValue().toIon().toIonValue(ION) - } - error("PartiQLResult cannot be converted to Ion") + override fun toIon(value: Datum): IonValue { + val partiql = value.toPartiQLValue() + return partiql.toIon().toIonValue(ION) } // TODO: Use DATUM - override fun compare(actual: PartiQLResult, expect: PartiQLResult): Boolean { - if (actual is PartiQLResult.Value && expect is PartiQLResult.Value) { - return valueComparison(actual.value.toPartiQLValue(), expect.value.toPartiQLValue()) - } - if (actual is PartiQLResult.Error) { - throw actual.cause - } - val errorMessage = buildString { - appendLine("Cannot compare different types of PartiQLResult.") - appendLine(" - Expected : $expect") - appendLine(" - Actual : $actual") - } - error(errorMessage) + override fun compare(actual: Datum, expect: Datum): Boolean { + return valueComparison(actual.toPartiQLValue(), expect.toPartiQLValue()) } // Value comparison of PartiQL Value that utilized Ion Hashcode. @@ -115,16 +101,16 @@ class EvalExecutor( } companion object { + val compiler = PartiQLCompiler.standard() val parser = PartiQLParser.standard() val planner = PartiQLPlanner.standard() - val engine = PartiQLEngine.standard() // TODO REPLACE WITH DATUM COMPARATOR val comparator = PartiQLValue.comparator() } - object Factory : TestExecutor.Factory { + object Factory : TestExecutor.Factory { - override fun create(env: IonStruct, options: CompileType): TestExecutor { + override fun create(env: IonStruct, options: CompileType): TestExecutor { // infer catalog from conformance test `env` val catalog = infer(env.toIonElement() as StructElement) val session = Session.builder() @@ -132,8 +118,8 @@ class EvalExecutor( .catalogs(catalog) .build() val mode = when (options) { - CompileType.PERMISSIVE -> PartiQLEngine.Mode.PERMISSIVE - CompileType.STRICT -> PartiQLEngine.Mode.STRICT + CompileType.PERMISSIVE -> Mode.PERMISSIVE() + CompileType.STRICT -> Mode.STRICT() } return EvalExecutor(session, mode) } diff --git a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/test/TestExecutor.kt b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/test/TestExecutor.kt index 508402ec8b..ec89bcad67 100644 --- a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/test/TestExecutor.kt +++ b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/test/TestExecutor.kt @@ -9,18 +9,18 @@ interface TestExecutor { /** * Compile the given statement. * - * @param statement + * @param input * @return */ - fun prepare(statement: String): T + fun prepare(input: String): T /** * Execute the statement, returning a value we can assert on. * - * @param statement + * @param input * @return */ - fun execute(statement: T): V + fun execute(input: T): V /** * Compare the equality of two values.