diff --git a/docs/wiki/v1/compiler.md b/docs/wiki/v1/compiler.md index 43f94e292..c86da18b0 100644 --- a/docs/wiki/v1/compiler.md +++ b/docs/wiki/v1/compiler.md @@ -60,8 +60,8 @@ I have labelled these children in the illustration so that you can see where the RelLimit / \ x: RelOffset - / \ - y: z: + / \ + y: z: ``` The compiler will look for this pattern in the operator tree, and produce a match like so, diff --git a/partiql-eval/api/partiql-eval.api b/partiql-eval/api/partiql-eval.api index bf609d0d5..6dda94908 100644 --- a/partiql-eval/api/partiql-eval.api +++ b/partiql-eval/api/partiql-eval.api @@ -45,9 +45,8 @@ public abstract interface class org/partiql/eval/Statement { } public class org/partiql/eval/compiler/Match { - public fun (Lorg/partiql/plan/Operator;Ljava/util/List;)V - public fun children (I)Ljava/util/List; - public fun operator (I)Lorg/partiql/plan/Operator; + public fun (Lorg/partiql/plan/Operand;)V + public fun getOperand ()Lorg/partiql/plan/Operand; } public abstract interface class org/partiql/eval/compiler/PartiQLCompiler { @@ -70,7 +69,11 @@ public class org/partiql/eval/compiler/Pattern { public abstract class org/partiql/eval/compiler/Strategy { public fun (Lorg/partiql/eval/compiler/Pattern;)V - public abstract fun apply (Lorg/partiql/eval/compiler/Match;)Lorg/partiql/eval/Expr; + public abstract fun apply (Lorg/partiql/eval/compiler/Match;Lorg/partiql/eval/compiler/Strategy$Callback;)Lorg/partiql/eval/Expr; public fun getPattern ()Lorg/partiql/eval/compiler/Pattern; } +public abstract interface class org/partiql/eval/compiler/Strategy$Callback { + public abstract fun apply (Lorg/partiql/plan/Operator;)Lorg/partiql/eval/Expr; +} + diff --git a/partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java b/partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java index de099a857..25066085b 100644 --- a/partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java +++ b/partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java @@ -1,50 +1,31 @@ package org.partiql.eval.compiler; import org.jetbrains.annotations.NotNull; -import org.partiql.eval.Expr; -import org.partiql.plan.Operator; - -import java.util.Collections; -import java.util.List; +import org.partiql.plan.Operand; /** * Match represents a subtree match to be sent to the */ public class Match { - private final Operator[] operators; - private final List> children; + private final Operand[] operands; /** - * Single operator match with zero-or-more inputs. + * Single operand match with zero-or-more inputs. * - * @param operator matched logical operator. - * @param children compiled child operators. + * @param operand matched logical operand. */ - public Match(@NotNull Operator operator, @NotNull List children) { - this.operators = new Operator[]{operator}; - this.children = Collections.singletonList(children); - } - - /** - * Get the i-th operator (pre-order) matched by the pattern. - * - * @param i 0-indexed - * @return Operator - */ - @NotNull - public Operator operator(int i) { - return operators[i]; + public Match(@NotNull Operand operand) { + this.operands = new Operand[]{operand}; } /** - * Get the i-th input to this pattern. + * Get the first (or only) operand * - * @param i 0-indexed - * @return Expr + * @return Operand */ @NotNull - public List children(int i) { - return children.get(i); + public Operand getOperand() { + return operands[0]; } } diff --git a/partiql-eval/src/main/java/org/partiql/eval/compiler/Strategy.java b/partiql-eval/src/main/java/org/partiql/eval/compiler/Strategy.java index 34ad6fdbf..0a10bc5be 100644 --- a/partiql-eval/src/main/java/org/partiql/eval/compiler/Strategy.java +++ b/partiql-eval/src/main/java/org/partiql/eval/compiler/Strategy.java @@ -34,8 +34,20 @@ public Pattern getPattern() { * Applies the strategy to a logical plan operator and returns the physical operation (expr). * * @param match holds the matched operators + * @param callback for compiling arguments of matched operators * @return the physical operation */ @NotNull - public abstract Expr apply(@NotNull Match match); + public abstract Expr apply(@NotNull Match match, @NotNull Callback callback); + + /** + * A compilation callback for strategies to compile arguments of matched operators. + */ + public interface Callback { + + /** + * @return a physical operator (expr) for the logical operator. + */ + Expr apply(Operator operator); + } } diff --git a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt index e1821d561..cd2c584d1 100644 --- a/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt +++ b/partiql-eval/src/main/kotlin/org/partiql/eval/internal/compiler/StandardCompiler.kt @@ -62,6 +62,7 @@ import org.partiql.eval.internal.operator.rex.ExprVar import org.partiql.plan.Action import org.partiql.plan.Collation import org.partiql.plan.JoinType +import org.partiql.plan.Operand import org.partiql.plan.Operator import org.partiql.plan.OperatorVisitor import org.partiql.plan.Plan @@ -170,25 +171,25 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { * @param operator * @return */ - private fun compileWithStrategies(operator: Operator, ctx: Unit): Expr { + private fun compileWithStrategies(operator: Operator): Expr { // if strategy matches root, compile children to form a match. for (strategy in strategies) { // first match if (strategy.pattern.matches(operator)) { - // compile children - val children = operator.getOperands().map { compileWithStrategies(it, ctx) } - val match = Match(operator, children) - return strategy.apply(match) + // assume single match + val operand = Operand.single(operator) + val match = Match(operand) + return strategy.apply(match, ::compileWithStrategies) } } return operator.accept(this, Unit) } // TODO REMOVE ME - private fun compile(rel: Rel, ctx: Unit): ExprRelation = compileWithStrategies(rel, ctx) as ExprRelation + private fun compile(rel: Rel, ctx: Unit): ExprRelation = compileWithStrategies(rel) as ExprRelation // TODO REMOVE ME - private fun compile(rex: Rex, ctx: Unit): ExprValue = compileWithStrategies(rex, ctx) as ExprValue + private fun compile(rex: Rex, ctx: Unit): ExprValue = compileWithStrategies(rex) as ExprValue override fun defaultReturn(operator: Operator, ctx: Unit): Expr { error("No compiler strategy matches the operator: ${operator::class.java.simpleName}") diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/compiler/StrategyTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/compiler/StrategyTest.kt index 912b57887..3e909318a 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/compiler/StrategyTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/compiler/StrategyTest.kt @@ -34,7 +34,7 @@ public class StrategyTest { var trigged = false val pattern = Pattern(RelLimit::class.java) val strategy = object : Strategy(pattern) { - override fun apply(match: Match): Expr { + override fun apply(match: Match, callback: Callback): Expr { trigged = true return MyLimit() } diff --git a/partiql-plan/README.md b/partiql-plan/README.md index 55771e76b..f884d58f5 100644 --- a/partiql-plan/README.md +++ b/partiql-plan/README.md @@ -1,32 +1,73 @@ # partiql-plan -## Classes +This package holds logical plans which are composed of actions and operator trees. -* Operator +* Operator (tree node interface) * Rel & RelBase * Rex & RexBase - -## Visitors - * OperatorVisitor * OperatorRewriter -## Design - -For the rule and strategy patterns to work, we need to model classes whose operands have a stable ordering; -so we have defined an abstract base class for all operators which holds operands and controls the access to them. -We use base implementations for state management and enforcing operands ordering; however we use interfaces for the -top-level of each domain. The abstract bases can be extended, and the operator/rel/rex interfaces can be implemented -directly. +## Operands What are operands? +* Operands are an important concept * An operand is an input to some operator. * An operator may have more than one operand e.g. join (left and right). * Rel operands are typically called "inputs" * Operands unify inputs since PartiQL bridges rel/rex domains. * Not all operators are operands e.g. the limit of RelLimit is a rex, but not an operand - it is an "arg" +| Operator | Operands | Arguments | +|-----------------|------------------|------------------------| +| RelAggregate | input | measures, groups | +| RelCorrelate | left, right | joinType | +| RelDistinct | input | | +| RelExcept | left, right | all | +| RelExclude | input | exclusions | +| RelFilter | input | predicate | +| RelIntersect | left, right | all | +| RelIterate | rex | | +| RelJoin | left, right | joinType, condition | +| RelLimit | input | limit | +| RelOffset | input | offset | +| RelProject | input | projections | +| RelScan | rex | | +| RelSort | input | collations | +| RelUnion | left, right | all | +| RelUnpivot | rex | | +| RexArray | values (vararg) | | +| RexBag | values (vararg) | | +| RexCall | args | | +| RexCase | match (optional) | branches, default | +| RexCast | operand | type | +| RexCoalesce | args (vararg) | | +| RexDispatch | args (vararg) | | +| RexLit | | value | +| RexNullIf | v1, v2 | | +| RexPathIndex | operand | index | +| RexPathKey | operand | key | +| RexPathSymbol | operand | symbol | +| RexPivot | input | key, value | +| RexSelect | input | constructor | +| RexSpread | args (vararg) | | +| RexStruct | | fields | +| RexSubquery | input | | +| RexSubqueryComp | input | comparison, quantifier | +| RexSubqueryIn | input | args | +| RexSubqueryTest | input | test | +| RexTable | | table | +| RexVar | | scope, offset | + +## Design + +For the rule and strategy patterns to work, we need to model classes whose operands have a stable ordering; +so we have defined an abstract base class for all operators which holds operands and controls the access to them. +We use base implementations for state management and enforcing operands ordering; however we use interfaces for the +top-level of each domain. The abstract bases can be extended, and the operator/rel/rex interfaces can be implemented +directly. + Why interfaces for top-level domain entities and not abstract base classes? * We don’t want to force materialization of operands (consider wrapping a serde class) diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index 4b1e687f9..42fd74b39 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -124,9 +124,24 @@ public class org/partiql/plan/JoinType : org/partiql/spi/Enum { public static fun RIGHT ()Lorg/partiql/plan/JoinType; } +public abstract interface class org/partiql/plan/Operand : java/lang/Iterable { + public static fun single (Lorg/partiql/plan/Operator;)Lorg/partiql/plan/Operand; + public static fun vararg (Ljava/util/List;)Lorg/partiql/plan/Operand; +} + +public class org/partiql/plan/Operand$Single : org/partiql/plan/Operand { + public final field operator Lorg/partiql/plan/Operator; + public fun iterator ()Ljava/util/Iterator; +} + +public class org/partiql/plan/Operand$Variadic : org/partiql/plan/Operand { + public final field operators Ljava/util/List; + public fun iterator ()Ljava/util/Iterator; +} + public abstract interface class org/partiql/plan/Operator { public abstract fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getOperand (I)Lorg/partiql/plan/Operator; + public abstract fun getOperand (I)Lorg/partiql/plan/Operand; public abstract fun getOperands ()Ljava/util/List; public abstract fun getTag ()I public abstract fun setTag (I)V @@ -408,7 +423,7 @@ public class org/partiql/plan/rel/RelAggregate$Measure { public abstract class org/partiql/plan/rel/RelBase : org/partiql/plan/rel/Rel { public fun ()V - public final fun getOperand (I)Lorg/partiql/plan/Operator; + public final fun getOperand (I)Lorg/partiql/plan/Operand; public final fun getOperands ()Ljava/util/List; public fun getTag ()I public final fun getType ()Lorg/partiql/plan/rel/RelType; @@ -573,7 +588,7 @@ public abstract class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/RelBas protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public class org/partiql/plan/rel/RelType { +public final class org/partiql/plan/rel/RelType { public static final field ORDERED I public fun getDegree ()I public fun getField (I)Lorg/partiql/types/Field; @@ -632,7 +647,7 @@ public abstract class org/partiql/plan/rex/RexBag : org/partiql/plan/rex/RexBase public abstract class org/partiql/plan/rex/RexBase : org/partiql/plan/rex/Rex { public fun ()V - public final fun getOperand (I)Lorg/partiql/plan/Operator; + public final fun getOperand (I)Lorg/partiql/plan/Operand; public final fun getOperands ()Ljava/util/List; public fun getTag ()I public final fun getType ()Lorg/partiql/plan/rex/RexType; @@ -887,7 +902,7 @@ public abstract class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/RexBa protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public class org/partiql/plan/rex/RexType { +public final class org/partiql/plan/rex/RexType { public fun equals (Ljava/lang/Object;)Z public fun getPType ()Lorg/partiql/types/PType; public fun hashCode ()I diff --git a/partiql-plan/src/main/java/org/partiql/plan/Operand.java b/partiql-plan/src/main/java/org/partiql/plan/Operand.java new file mode 100644 index 000000000..4111eb62f --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/Operand.java @@ -0,0 +1,68 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; + +import java.util.Iterator; +import java.util.List; + +/** + * Operands in an operator tree used for strategy and rule pattern matching. + */ +public interface Operand extends Iterable { + + /** + * @return a single operand + */ + public static Operand single(Operator operator) { + return new Single(operator); + } + + /** + * @return a variadic operand + * + * See ImmutableCollections.java ListCopy. + */ + @SuppressWarnings("unchecked") + public static Operand vararg(List operators) { + return new Variadic((List) operators); + } + + /** + * A single operator. + */ + public class Single implements Operand { + + @NotNull + public final Operator operator; + + private Single(@NotNull Operator operator) { + this.operator = operator; + } + + + @NotNull + @Override + public Iterator iterator() { + return List.of(operator).iterator(); + } + } + + /** + * A variadic operator. + */ + public class Variadic implements Operand { + + @NotNull + public final List operators; + + private Variadic(@NotNull List operators) { + this.operators = operators; + } + + @NotNull + @Override + public Iterator iterator() { + return operators.iterator(); + } + } +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Operator.java b/partiql-plan/src/main/java/org/partiql/plan/Operator.java index f54f16c09..17d9ec8cd 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Operator.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Operator.java @@ -33,17 +33,13 @@ public interface Operator { public abstract R accept(OperatorVisitor visitor, C ctx); /** - * Get i-th child (input) operator. - * - * @param index child index - * @return child operator + * @return the i-th operand */ - @NotNull - public abstract Operator getOperand(int index); + public abstract Operand getOperand(int index); /** - * @return all child (input) operators. + * @return all input operands. */ @NotNull - public abstract List getOperands(); + public abstract List getOperands(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java index 40368dc82..6b9198d63 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java @@ -50,8 +50,10 @@ public interface OperatorVisitor { default R defaultVisit(Operator operator, C ctx) { - for (Operator child : operator.getOperands()) { - child.accept(this, ctx); + for (Operand o : operator.getOperands()) { + for (Operator op : o) { + op.accept(this, ctx); + } } return defaultReturn(operator, ctx); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java index 05585d61f..333961957 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import org.partiql.spi.function.Aggregation; @@ -57,8 +57,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java index 8a046bce9..00ce25419 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import java.util.List; @@ -12,7 +12,7 @@ public abstract class RelBase implements Rel { private int tag = 0; private RelType type; - private List operands; + private List operands; @Override public int getTag() { @@ -40,13 +40,16 @@ public void setType(@NotNull RelType type) { @NotNull @Override - public final Operator getOperand(int index) { + public final Operand getOperand(int index) { + if (operands == null) { + operands = operands(); + } return operands.get(index); } @NotNull @Override - public final List getOperands() { + public final List getOperands() { if (operands == null) { operands = operands(); } @@ -65,5 +68,5 @@ public final List getOperands() { * * @return computed operands. */ - protected abstract List operands(); + protected abstract List operands(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java index 549e0e258..c9915b784 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.JoinType; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -46,9 +46,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getLeft(); - Rel c1 = getRight(); + protected final List operands() { + Operand c0 = Operand.single(getLeft()); + Operand c1 = Operand.single(getRight()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java index eaa1d29cd..aa61ecbe3 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -33,8 +33,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java index 0767756d7..690919e57 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -44,9 +44,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getLeft(); - Rel c1 = getRight(); + protected final List operands() { + Operand c0 = Operand.single(getLeft()); + Operand c1 = Operand.single(getRight()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java index c8d436f44..5132dde91 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Exclusion; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -40,8 +40,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java index fa073ec68..81e936515 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -27,7 +27,7 @@ public static RelFilter create(@NotNull Rel input, @NotNull Rex predicate) { public abstract Rel getInput(); /** - * @return predicate rex (operand 1) + * @return predicate rex. */ @NotNull public abstract Rex getPredicate(); @@ -40,10 +40,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); - Rex c1 = getPredicate(); - return List.of(c0, c1); + protected final List operands() { + Operand c0 = Operand.single(getInput()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java index cad60fec6..6b0873ada 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -44,9 +44,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getLeft(); - Rel c1 = getRight(); + protected final List operands() { + Operand c0 = Operand.single(getLeft()); + Operand c1 = Operand.single(getRight()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java index 00eb12654..ec449f7e9 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -34,8 +34,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rex c0 = getRex(); + protected final List operands() { + Operand c0 = Operand.single(getRex()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java index 01136b54b..e33722d06 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.JoinType; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -40,7 +40,7 @@ public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull Rex public abstract JoinType getJoinType(); /** - * @return the join condition (operand 2), or null if there is no condition. + * @return the join condition. */ @NotNull public abstract Rex getCondition(); @@ -52,11 +52,10 @@ protected RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getLeft(); - Rel c1 = getRight(); - Rex c2 = getCondition(); // can be null! - return List.of(c0, c1, c2); + protected final List operands() { + Operand c0 = Operand.single(getLeft()); + Operand c1 = Operand.single(getRight()); + return List.of(c0, c1); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java index 2f70b6b83..69b19e603 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -40,9 +40,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); - Rex c1 = getLimit(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); + Operand c1 = Operand.single(getLimit()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java index f3043b5e5..01d948875 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -40,9 +40,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); - Rex c1 = getOffset(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); + Operand c1 = Operand.single(getOffset()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java index 4223039a8..13a587e2b 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -40,8 +40,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java index c9e1df5ca..5fe47c344 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -34,8 +34,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rex c0 = getRex(); + protected final List operands() { + Operand c0 = Operand.single(getRex()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java index b901a974d..6af38bd7d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Collation; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -34,8 +34,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java index 60bff0736..fa27f75da 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java @@ -6,7 +6,7 @@ /** * Analogous to a ROW type, consider cardinality estimates or other hint mechanisms. */ -public class RelType { +public final class RelType { public static final int ORDERED = 0x01; diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java index 711d4fca2..fb54ef4d3 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -44,9 +44,9 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getLeft(); - Rel c1 = getRight(); + protected final List operands() { + Operand c0 = Operand.single(getLeft()); + Operand c1 = Operand.single(getRight()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java index 53b49acb3..31c625697 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java @@ -1,7 +1,7 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; @@ -34,8 +34,8 @@ protected final RelType type() { @NotNull @Override - protected final List operands() { - Rex c0 = getRex(); + protected final List operands() { + Operand c0 = Operand.single(getRex()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java index 955c2280f..13e6cec6b 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java @@ -1,6 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operand; import org.partiql.plan.Operator; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -34,9 +35,9 @@ protected final RexType type() { @NotNull @Override - protected final List operands() { - List varargs = getValues(); - return List.copyOf(varargs); + protected final List operands() { + Operand c0 = Operand.vararg(getValues()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java index b8aa2c8be..9f59b900e 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java @@ -1,12 +1,15 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operand; import org.partiql.plan.Operator; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; /** * Logical bag expression abstract base class. @@ -35,9 +38,11 @@ protected final RexType type() { @NotNull @Override - protected final List operands() { - Collection varargs = getValues(); - return List.copyOf(varargs); + protected final List operands() { + // uh oh! prescribing order (??) + List values = new ArrayList<>(getValues()); + Operand c0 = Operand.vararg(values); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java index 2a2f54e41..8ab53c628 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import java.util.List; @@ -11,7 +11,7 @@ public abstract class RexBase implements Rex { private int tag = 0; - private List operands; + private List operands; private RexType type; @Override @@ -40,13 +40,16 @@ public final void setType(RexType type) { @NotNull @Override - public final Operator getOperand(int index) { + public final Operand getOperand(int index) { + if (operands == null) { + operands = operands(); + } return operands.get(index); } @NotNull @Override - public final List getOperands() { + public final List getOperands() { if (operands == null) { operands = operands(); } @@ -65,5 +68,5 @@ public final List getOperands() { * * @return computed operands. */ - protected abstract List operands(); + protected abstract List operands(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java index cee7621c8..7cd2bcb81 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.spi.function.Function; @@ -35,9 +35,9 @@ protected RexType type() { } @Override - protected List operands() { - List varargs = getArgs(); - return List.copyOf(varargs); + protected List operands() { + Operand c0 = Operand.vararg(getArgs()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java index d2f97dffa..a440a2e2a 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -35,7 +35,7 @@ public static Branch branch(@NotNull Rex condition, @NotNull Rex result) { public abstract List getBranches(); /** - * @return the default expression, or {@code null} if none (operand 1) + * @return the default expression, or {@code null} if none (not an operand) */ @Nullable public abstract Rex getDefault(); @@ -47,10 +47,13 @@ protected final RexType type() { } @Override - protected List operands() { - Rex c0 = getMatch(); - Rex c1 = getDefault(); - return List.of(c0, c1); + protected List operands() { + Rex match = getMatch(); + if (match == null) { + return List.of(); + } + Operand c0 = Operand.single(match); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java index 8da3edf2d..e8b939e2d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -38,8 +38,9 @@ protected final RexType type() { } @Override - protected List operands() { - return List.of(); + protected List operands() { + Operand c0 = Operand.single(getOperand()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java index b38415e99..f33ac89b0 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -31,9 +31,9 @@ protected final RexType type() { } @Override - protected final List operands() { - List varargs = getArgs(); - return List.copyOf(varargs); + protected final List operands() { + Operand c0 = Operand.vararg(getArgs()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java index 7191c9a3e..be39c6bfd 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.spi.function.Function; import org.partiql.types.PType; @@ -43,9 +43,9 @@ protected final RexType type() { } @Override - protected final List operands() { - List varargs = getArgs(); - return List.copyOf(varargs); + protected final List operands() { + Operand c0 = Operand.vararg(getArgs()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java index a93864515..d18962618 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -28,7 +28,7 @@ protected RexType type() { } @Override - protected List operands() { + protected List operands() { return List.of(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java index 9ead1d4f5..ff8f34617 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.spi.value.Datum; @@ -30,7 +30,7 @@ protected final RexType type() { } @Override - protected List operands() { + protected List operands() { return List.of(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java index dfbce4efc..b95905e86 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -42,9 +42,9 @@ protected final RexType type() { } @Override - protected final List operands() { - Rex c0 = getV1(); - Rex c1 = getV2(); + protected final List operands() { + Operand c0 = Operand.single(getV1()); + Operand c1 = Operand.single(getV2()); return List.of(c0, c1); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java index a669c17f0..f986587ef 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -26,7 +26,7 @@ public static RexPathIndex create(@NotNull Rex operand, @NotNull Rex index) { public abstract Rex getOperand(); /** - * @return index rex (operand 1) + * @return index rex */ public abstract Rex getIndex(); @@ -37,10 +37,9 @@ protected final RexType type() { } @Override - protected final List operands() { - Rex c0 = getOperand(); - Rex c1 = getIndex(); - return List.of(c0, c1); + protected final List operands() { + Operand c0 = Operand.single(getOperand()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java index 8822d33af..0a1f15d45 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -26,7 +26,7 @@ public static RexPathKey create(@NotNull Rex operand, @NotNull Rex key) { public abstract Rex getOperand(); /** - * @return key rex (operand 1) + * @return key rex. */ @NotNull public abstract Rex getKey(); @@ -38,10 +38,9 @@ protected final RexType type() { } @Override - protected List operands() { - Rex c0 = getOperand(); - Rex c1 = getKey(); - return List.of(c0, c1); + protected List operands() { + Operand c0 = Operand.single(getOperand()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java index e39d588d3..fd77bd0b4 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -38,8 +38,8 @@ protected final RexType type() { } @Override - protected final List operands() { - Rex c0 = getOperand(); + protected final List operands() { + Operand c0 = Operand.single(getOperand()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java index abeeb2d83..d98d6a487 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -46,11 +46,9 @@ protected final RexType type() { } @Override - protected final List operands() { - Rel c0 = getInput(); - Rex c1 = getKey(); - Rex c2 = getValue(); - return List.of(c0, c1, c2); + protected final List operands() { + Operand c0 = Operand.single(getInput()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java index 38e82a23a..7eb830f7e 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -28,7 +28,7 @@ public static RexSelect create(@NotNull Rel input, @NotNull Rex constructor) { public abstract Rel getInput(); /** - * @return constructor rex (operand 1) + * @return constructor rex. */ public abstract Rex getConstructor(); @@ -40,10 +40,9 @@ protected final RexType type() { @NotNull @Override - protected final List operands() { - Rel c0 = getInput(); - Rex c1 = getConstructor(); - return List.of(c0, c1); + protected final List operands() { + Operand c0 = Operand.single(getInput()); + return List.of(c0); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java index 72c43d043..3f86e5882 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java @@ -1,6 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operand; import org.partiql.plan.Operator; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -33,9 +34,9 @@ protected final RexType type() { @NotNull @Override - protected final List operands() { - List varargs = getArgs(); - return List.copyOf(varargs); + protected final List operands() { + Operand c0 = Operand.vararg(getArgs()); + return List.of(c0); } public R accept(OperatorVisitor visitor, C ctx) { diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java index db20868a5..9752ebfab 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -41,7 +41,7 @@ protected final RexType type() { } @Override - protected List operands() { + protected List operands() { return List.of(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java index 4a807ef47..49f334d5d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; @@ -40,8 +40,8 @@ protected final RexType type() { } @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java index 5e88bbd87..3518cf9d4 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.spi.Enum; @@ -60,8 +60,8 @@ protected final RexType type() { } @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java index 171c87e9d..cab4210fe 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -39,8 +39,8 @@ protected final RexType type() { } @Override - protected final List operands() { - Rel c0 = getInput(); + protected final List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java index 0d68fcc8b..54a299c35 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.spi.Enum; @@ -46,8 +46,8 @@ protected final RexType type() { } @Override - protected List operands() { - Rel c0 = getInput(); + protected List operands() { + Operand c0 = Operand.single(getInput()); return List.of(c0); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java index 08d104a67..679258938 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.spi.catalog.Table; @@ -32,7 +32,7 @@ protected final RexType type() { } @Override - protected final List operands() { + protected final List operands() { return List.of(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java index 5ca435186..a02b64ae0 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java @@ -9,7 +9,7 @@ *

* Developer Note: In later releases, a [RexType] may hold metadata to aid custom planner implementations. */ -public class RexType { +public final class RexType { private final PType type; diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java index f086ad401..282e5dd58 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java @@ -1,7 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.Operator; +import org.partiql.plan.Operand; import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; @@ -31,7 +31,7 @@ public static RexVar create(int scope, int offset, PType type) { public abstract int getOffset(); @Override - protected final List operands() { + protected final List operands() { return List.of(); }