From 0475812adfdc52bcbcc7c4cd3bd52b31cd7094fe Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 11:36:48 -0500 Subject: [PATCH 01/19] Swith rel interfaces to java --- .../org/partiql/plan/AggregateCall.kt | 0 .../org/partiql/plan/Collation.java} | 0 .../org/partiql/plan/Exclusion.kt | 0 .../org/partiql/plan/JoinType.kt | 0 .../org/partiql/plan/Operation.kt | 0 .../org/partiql/plan/Operator.java} | 0 .../{kotlin => java}/org/partiql/plan/Plan.kt | 0 .../org/partiql/plan/Version.kt | 0 .../org/partiql/plan/Visitor.kt | 0 .../main/java/org/partiql/plan/rel/Rel.java | 16 ++++ .../org/partiql/plan/rel/RelAggregate.java | 65 ++++++++++++++++ .../org/partiql/plan/rel/RelCorrelate.java | 24 ++++++ .../org/partiql/plan/rel/RelDistinct.java | 18 +++++ .../java/org/partiql/plan/rel/RelExcept.java | 26 +++++++ .../java/org/partiql/plan/rel/RelExclude.java | 24 ++++++ .../java/org/partiql/plan/rel/RelFilter.java | 28 +++++++ .../org/partiql/plan/rel/RelIntersect.java | 23 ++++++ .../java/org/partiql/plan/rel/RelIterate.java | 19 +++++ .../java/org/partiql/plan/rel/RelJoin.java | 30 ++++++++ .../java/org/partiql/plan/rel/RelLimit.java | 22 ++++++ .../java/org/partiql/plan/rel/RelOffset.java | 23 ++++++ .../java/org/partiql/plan/rel/RelProject.java | 24 ++++++ .../java/org/partiql/plan/rel/RelScan.java | 19 +++++ .../java/org/partiql/plan/rel/RelSort.java | 24 ++++++ .../java/org/partiql/plan/rel/RelType.java | 23 ++++++ .../java/org/partiql/plan/rel/RelUnion.java | 24 ++++++ .../java/org/partiql/plan/rel/RelUnpivot.java | 19 +++++ .../org/partiql/plan/rex/Rex.kt | 0 .../org/partiql/plan/rex/RexArray.kt | 0 .../org/partiql/plan/rex/RexBag.kt | 0 .../org/partiql/plan/rex/RexCall.kt | 0 .../org/partiql/plan/rex/RexCallDynamic.kt | 0 .../org/partiql/plan/rex/RexCase.kt | 0 .../org/partiql/plan/rex/RexCast.kt | 0 .../org/partiql/plan/rex/RexCoalesce.kt | 0 .../org/partiql/plan/rex/RexError.kt | 0 .../org/partiql/plan/rex/RexLit.kt | 0 .../org/partiql/plan/rex/RexNullIf.kt | 0 .../org/partiql/plan/rex/RexPathIndex.kt | 0 .../org/partiql/plan/rex/RexPathKey.kt | 0 .../org/partiql/plan/rex/RexPathSymbol.kt | 0 .../org/partiql/plan/rex/RexPivot.kt | 0 .../org/partiql/plan/rex/RexSelect.kt | 0 .../org/partiql/plan/rex/RexSpread.kt | 0 .../org/partiql/plan/rex/RexStruct.kt | 0 .../org/partiql/plan/rex/RexSubquery.kt | 0 .../org/partiql/plan/rex/RexSubqueryComp.kt | 0 .../org/partiql/plan/rex/RexSubqueryIn.kt | 0 .../org/partiql/plan/rex/RexSubqueryTest.kt | 0 .../org/partiql/plan/rex/RexTable.kt | 0 .../org/partiql/plan/rex/RexType.kt | 0 .../org/partiql/plan/rex/RexVar.kt | 0 .../RelDistinctImpl.kt} | 21 +----- .../RelExcept.kt => impl/RelExceptImpl.kt} | 23 +----- .../RelExclude.kt => impl/RelExcludeImpl.kt} | 20 +---- .../RelFilter.kt => impl/RelFilterImpl.kt} | 25 +------ .../RelIntersectImpl.kt} | 23 +----- .../RelIterate.kt => impl/RelIterateImpl.kt} | 18 +---- .../{rel/RelJoin.kt => impl/RelJoinImpl.kt} | 29 +------ .../{rel/RelLimit.kt => impl/RelLimitImpl.kt} | 21 +----- .../RelOffset.kt => impl/RelOffsetImpl.kt} | 21 +----- .../RelProject.kt => impl/RelProjectImpl.kt} | 19 +---- .../{rel/RelScan.kt => impl/RelScanImpl.kt} | 17 +---- .../{rel/RelSort.kt => impl/RelSortImpl.kt} | 21 +----- .../{rel/RelUnion.kt => impl/RelUnionImpl.kt} | 22 +----- .../org/partiql/plan/impl/RelUnpivotImpl.kt | 2 + .../main/kotlin/org/partiql/plan/rel/Rel.kt | 13 ---- .../org/partiql/plan/rel/RelAggregate.kt | 75 ------------------- .../org/partiql/plan/rel/RelCorrelate.kt | 72 ------------------ .../kotlin/org/partiql/plan/rel/RelType.kt | 17 ----- .../kotlin/org/partiql/plan/rel/RelUnpivot.kt | 43 ----------- 71 files changed, 466 insertions(+), 487 deletions(-) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/AggregateCall.kt (100%) rename partiql-plan/src/main/{kotlin/org/partiql/plan/Collation.kt => java/org/partiql/plan/Collation.java} (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/Exclusion.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/JoinType.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/Operation.kt (100%) rename partiql-plan/src/main/{kotlin/org/partiql/plan/Operator.kt => java/org/partiql/plan/Operator.java} (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/Plan.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/Version.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/Visitor.kt (100%) create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/Rex.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexArray.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexBag.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexCall.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexCallDynamic.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexCase.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexCast.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexCoalesce.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexError.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexLit.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexNullIf.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexPathIndex.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexPathKey.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexPathSymbol.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexPivot.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSelect.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSpread.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexStruct.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSubquery.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSubqueryComp.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSubqueryIn.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexSubqueryTest.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexTable.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexType.kt (100%) rename partiql-plan/src/main/{kotlin => java}/org/partiql/plan/rex/RexVar.kt (100%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelDistinct.kt => impl/RelDistinctImpl.kt} (66%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelExcept.kt => impl/RelExceptImpl.kt} (72%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelExclude.kt => impl/RelExcludeImpl.kt} (72%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelFilter.kt => impl/RelFilterImpl.kt} (68%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelIntersect.kt => impl/RelIntersectImpl.kt} (71%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelIterate.kt => impl/RelIterateImpl.kt} (60%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelJoin.kt => impl/RelJoinImpl.kt} (71%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelLimit.kt => impl/RelLimitImpl.kt} (68%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelOffset.kt => impl/RelOffsetImpl.kt} (68%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelProject.kt => impl/RelProjectImpl.kt} (70%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelScan.kt => impl/RelScanImpl.kt} (61%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelSort.kt => impl/RelSortImpl.kt} (71%) rename partiql-plan/src/main/kotlin/org/partiql/plan/{rel/RelUnion.kt => impl/RelUnionImpl.kt} (72%) create mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelType.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/AggregateCall.kt b/partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/AggregateCall.kt rename to partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Collation.kt b/partiql-plan/src/main/java/org/partiql/plan/Collation.java similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Collation.kt rename to partiql-plan/src/main/java/org/partiql/plan/Collation.java diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Exclusion.kt b/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Exclusion.kt rename to partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/JoinType.kt b/partiql-plan/src/main/java/org/partiql/plan/JoinType.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/JoinType.kt rename to partiql-plan/src/main/java/org/partiql/plan/JoinType.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operation.kt b/partiql-plan/src/main/java/org/partiql/plan/Operation.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Operation.kt rename to partiql-plan/src/main/java/org/partiql/plan/Operation.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operator.kt b/partiql-plan/src/main/java/org/partiql/plan/Operator.java similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Operator.kt rename to partiql-plan/src/main/java/org/partiql/plan/Operator.java diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Plan.kt b/partiql-plan/src/main/java/org/partiql/plan/Plan.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Plan.kt rename to partiql-plan/src/main/java/org/partiql/plan/Plan.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Version.kt b/partiql-plan/src/main/java/org/partiql/plan/Version.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Version.kt rename to partiql-plan/src/main/java/org/partiql/plan/Version.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Visitor.kt b/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/Visitor.kt rename to partiql-plan/src/main/java/org/partiql/plan/Visitor.kt diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java new file mode 100644 index 000000000..ee1e8340c --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java @@ -0,0 +1,16 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; + +/** + * A Rel is an {@link Operator that produces a collection of tuples. + */ +public interface Rel extends Operator { + + /** + * @return RelType. + */ + @NotNull + public RelType getType(); +} 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 new file mode 100644 index 000000000..b877d659c --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java @@ -0,0 +1,65 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; +import org.partiql.spi.function.Aggregation; + +import java.util.Collection; + +/** + * Interface for an aggregation operator. + *
+ * TODO GROUP STRATEGY ISSUE + */ +public interface RelAggregate extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Collection getMeasures(); + + @NotNull + public Collection getGroups(); + + @NotNull + public Collection getChildren(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitAggregate(this, ctx); + } + + /** + * An aggregation function along with its arguments and any additional filters (e.g. DISTINCT). + */ + public class Measure { + + private final Aggregation agg; + private final Collection args; + private final Boolean distinct; + + public Measure(Aggregation agg, Collection args, Boolean distinct) { + this.agg = agg; + this.args = args; + this.distinct = distinct; + } + + @NotNull + public Aggregation getAgg() { + return agg; + } + + @NotNull + public Collection getArgs() { + return args; + } + + @NotNull + public Boolean isDistinct() { + return distinct; + } + } +} 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 new file mode 100644 index 000000000..59e4a3402 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java @@ -0,0 +1,24 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; + +/** + * Logical operator for nested-loop joins (correlated subqueries // lateral joins). + */ +public interface RelCorrelate extends Rel { + + @NotNull + public Rel getLeft(); + + @NotNull + public Rel getRight(); + + @NotNull + public Rel getJoinType(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitCorrelate(this, ctx); + } +} 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 new file mode 100644 index 000000000..5f09989e9 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java @@ -0,0 +1,18 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; + +/** + * Logical `DISTINCT` operator. + */ +public interface RelDistinct extends Rel { + + @NotNull + public Rel getInput(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitDistinct(this, ctx); + } +} 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 new file mode 100644 index 000000000..a1942d883 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java @@ -0,0 +1,26 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; + +/** + * Logical `EXCEPT [ALL|DISTINCT]` operator for set (or multiset) difference. + */ +public interface RelExcept extends Rel { + + /** + * @return true if the `ALL` keyword was used, false otherwise. + */ + public boolean isAll(); + + @NotNull + public Rel getLeft(); + + @NotNull + public Rel getRight(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitExcept(this, ctx); + } +} 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 new file mode 100644 index 000000000..4190fb025 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java @@ -0,0 +1,24 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Exclusion; +import org.partiql.plan.Visitor; + +import java.util.Collection; + +/** + * Logical `EXCLUDE` operator. + */ +public interface RelExclude extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Collection getExclusions(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitExclude(this, ctx); + } +} 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 new file mode 100644 index 000000000..d35b1b43a --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java @@ -0,0 +1,28 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical filter operation for the WHERE and HAVING clauses. + *
+ *
+ *
    + *
  1. input (rel)
  2. + *
  3. predicate (rex)
  4. + *
+ */ +public interface RelFilter extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Rex getPredicate(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitFilter(this, ctx); + } +} 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 new file mode 100644 index 000000000..47ed477f5 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java @@ -0,0 +1,23 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; + +/** + * Logical `INTERSECT [ALL|DISTINCT]` operator for set (or multiset) intersection. + */ +public interface RelIntersect extends Rel { + + public boolean isAll(); + + @NotNull + public Rel getLeft(); + + @NotNull + public Rel getRight(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitIntersect(this, ctx); + } +} 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 new file mode 100644 index 000000000..03bd10e53 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java @@ -0,0 +1,19 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical scan corresponding to the clause `FROM AS AT `. + */ +public interface RelIterate extends Rel { + + @NotNull + public Rex getRex(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitIterate(this, ctx); + } +} 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 new file mode 100644 index 000000000..03b0d60b4 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java @@ -0,0 +1,30 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.partiql.plan.JoinType; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical join operator. + */ +public interface RelJoin extends Rel { + + @NotNull + public Rel getLeft(); + + @NotNull + public Rel getRight(); + + @NotNull + public JoinType getJoinType(); + + @Nullable + public Rex getCondition(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitJoin(this, ctx); + } +} 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 new file mode 100644 index 000000000..291344d46 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelLimit.java @@ -0,0 +1,22 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical `LIMIT` operator. + */ +public interface RelLimit extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Rex getLimit(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitLimit(this, ctx); + } +} 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 new file mode 100644 index 000000000..8c8f682f9 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelOffset.java @@ -0,0 +1,23 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical `OFFSET` operator. + */ +public interface RelOffset extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Rex getOffset(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitOffset(this, ctx); + } +} + 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 new file mode 100644 index 000000000..4480ffb06 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelProject.java @@ -0,0 +1,24 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +import java.util.Collection; + +/** + * Logical `PROJECTION` operator + */ +public interface RelProject extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Collection getProjections(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitProject(this, ctx); + } +} 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 new file mode 100644 index 000000000..c466e6a54 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelScan.java @@ -0,0 +1,19 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical scan corresponding to the clause `FROM AS `. + */ +public interface RelScan extends Rel { + + @NotNull + public Rex getRex(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitScan(this, ctx); + } +} 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 new file mode 100644 index 000000000..68cb41cdd --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelSort.java @@ -0,0 +1,24 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Collation; +import org.partiql.plan.Visitor; + +import java.util.Collection; + +/** + * Logical sort operator. + */ +public interface RelSort extends Rel { + + @NotNull + public Rel getInput(); + + @NotNull + public Collection getCollations(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitSort(this, ctx); + } +} 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 new file mode 100644 index 000000000..7952da872 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java @@ -0,0 +1,23 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.types.Field; + +/** + * Analogous to a ROW type, consider rank/cardinality or other hint mechanisms. + */ +public interface RelType { + + public int getFieldSize(); + + @NotNull + public Field[] getFields(); + + @NotNull + public Field getField(String name); + + /** + * @return true if the rel produces an ordered stream of rows. + */ + public boolean isOrdered(); +} 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 new file mode 100644 index 000000000..bf22d6da0 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnion.java @@ -0,0 +1,24 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; + +/** + * Logical `UNION [ALL|DISTINCT]` operator for set (or multiset) union. + */ +public interface RelUnion extends Rel { + + public boolean isAll(); + + @NotNull + public Rel getLeft(); + + @NotNull + public Rel getRight(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitUnion(this, ctx); + } +} + 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 new file mode 100644 index 000000000..bc91ad415 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelUnpivot.java @@ -0,0 +1,19 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rex.Rex; + +/** + * Logical `UNPIVOT` operator. + */ +public interface RelUnpivot extends Rel { + + @NotNull + public Rex getRex(); + + @Override + default public R accept(Visitor visitor, C ctx) { + return visitor.visitUnpivot(this, ctx); + } +} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/Rex.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexArray.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexBag.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCall.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCallDynamic.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCase.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCast.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexCoalesce.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexError.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexError.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexLit.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexNullIf.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathIndex.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathKey.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPathSymbol.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexPivot.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSelect.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSpread.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexStruct.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubquery.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryComp.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryIn.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexSubqueryTest.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexTable.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexType.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexType.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexType.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.kt similarity index 100% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rex/RexVar.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.kt diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt similarity index 66% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt index 77ae8a3b5..f4274ca9c 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelDistinct.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt @@ -1,24 +1,5 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor - -/** - * Logical `DISTINCT` operator. - */ -public interface RelDistinct : Rel { - - public fun getInput(): Rel - - override fun getChildren(): Collection = listOf(getInput()) - - override fun getType(): RelType = getInput().getType() - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitDistinct(this, ctx) -} - /** * Default [RelDistinct] implementation. */ @@ -51,4 +32,4 @@ internal class RelDistinctImpl(input: Rel) : RelDistinct { override fun hashCode(): Int { return _input.hashCode() } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt similarity index 72% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt index a74cb8a33..42ca73359 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExcept.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt @@ -1,26 +1,5 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor - -/** - * Logical `EXCEPT [ALL|DISTINCT]` operator for set (or multiset) difference. - */ -public interface RelExcept : Rel { - - public fun isAll(): Boolean - - public fun getLeft(): Rel - - public fun getRight(): Rel - - override fun getChildren(): Collection = listOf(getLeft(), getRight()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitExcept(this, ctx) -} - /** * Default [RelExcept] implementation. */ @@ -67,4 +46,4 @@ internal class RelExceptImpl(left: Rel, right: Rel, isAll: Boolean) : result = 31 * result + _right.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt similarity index 72% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt index 3e3522b5e..82af2847a 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelExclude.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt @@ -1,24 +1,6 @@ package org.partiql.plan.rel import org.partiql.plan.Exclusion -import org.partiql.plan.Visitor - -/** - * Logical `EXCLUDE` operation. - */ -public interface RelExclude : Rel { - - public fun getInput(): Rel - - public fun getExclusions(): List - - override fun getChildren(): Collection = listOf(getInput()) - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitExclude(this, ctx) -} /** * Default [RelExclude] implementation. @@ -56,4 +38,4 @@ internal class RelExcludeImpl(input: Rel, exclusions: List) : RelExcl result = 31 * result + _exclusions.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt similarity index 68% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt index e76b86981..3d603dc55 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelFilter.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt @@ -1,30 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical filter operation for the WHERE and HAVING clauses. - * - * arg 0 – rel input - * arg 1 - rex predicate - */ -public interface RelFilter : Rel { - - public fun getInput(): Rel - - public fun getPredicate(): Rex - - override fun getChildren(): Collection = listOf(getInput()) - - override fun getType(): RelType = getInput().getType() - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitFilter(this, ctx) -} - /** * Default [RelFilter] implementation. */ @@ -65,4 +42,4 @@ internal class RelFilterImpl(input: Rel, predicate: Rex) : RelFilter { result = 31 * result + _predicate.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt similarity index 71% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt index 4062ff6c4..9877701d9 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIntersect.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt @@ -1,26 +1,5 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor - -/** - * Logical `INTERSECT [ALL|DISTINCT]` operator for set (or multiset) intersection. - */ -public interface RelIntersect : Rel { - - public fun isAll(): Boolean - - public fun getLeft(): Rel - - public fun getRight(): Rel - - override fun getChildren(): Collection = listOf(getLeft(), getRight()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitIntersect(this, ctx) -} - /** * Default [RelIntersect] implementation. */ @@ -67,4 +46,4 @@ internal class RelIntersectImpl(left: Rel, right: Rel, isAll: Boolean) : result = 31 * result + _right.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt similarity index 60% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt index 15b6cc9a5..f5c81ce0a 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelIterate.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt @@ -1,23 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical scan corresponding to the clause `FROM AS AT `. - */ -public interface RelIterate : Rel { - - public fun getInput(): Rex - - override fun getChildren(): Collection = emptyList() - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitIterate(this, ctx) -} - /** * Default [RelIterate] implementation. */ @@ -41,4 +25,4 @@ internal class RelIterateImpl(input: Rex) : RelIterate { override fun hashCode(): Int { return _input.hashCode() } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt similarity index 71% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt index 6846b0817..9262aec3f 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelJoin.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt @@ -1,35 +1,8 @@ package org.partiql.plan.rel import org.partiql.plan.JoinType -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * TODO DOCUMENTATION - */ -public interface RelJoin : Rel { - - public fun getLeft(): Rel - - // TODO REMOVE ME TEMPORARY – https://github.com/partiql/partiql-lang-kotlin/issues/1575 - public fun getLeftSchema(): RelType? - - public fun getRight(): Rel - - // TODO REMOVE ME TEMPORARY – https://github.com/partiql/partiql-lang-kotlin/issues/1575 - public fun getRightSchema(): RelType? - - public fun getCondition(): Rex? - - public fun getJoinType(): JoinType - - override fun getChildren(): Collection = listOf(getLeft(), getRight()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitJoin(this, ctx) -} - /** * Default [RelJoin] implementation. */ @@ -95,4 +68,4 @@ internal class RelJoinImpl( result = 31 * result + _joinType.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt similarity index 68% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt index ada7af34b..411e8b889 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelLimit.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt @@ -1,26 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical `LIMIT` operator. - */ -public interface RelLimit : Rel { - - public fun getInput(): Rel - - public fun getLimit(): Rex - - override fun getChildren(): Collection = listOf(getInput()) - - override fun getType(): RelType = getInput().getType() - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitLimit(this, ctx) -} - /** * Default [RelLimit] implementation. */ @@ -54,4 +35,4 @@ internal class RelLimitImpl(input: Rel, limit: Rex) : RelLimit { result = 31 * result + _limit.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt similarity index 68% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt index 5ab13454f..f6feb64d8 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelOffset.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt @@ -1,26 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical `OFFSET` operator. - */ -public interface RelOffset : Rel { - - public fun getInput(): Rel - - public fun getOffset(): Rex - - override fun getChildren(): Collection = listOf(getInput()) - - override fun getType(): RelType = getInput().getType() - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitOffset(this, ctx) -} - /** * Default [RelOffset] implementation. */ @@ -54,4 +35,4 @@ internal class RelOffsetImpl(input: Rel, offset: Rex) : RelOffset { result = 31 * result + _offset.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt similarity index 70% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt index 3e50f26da..3d9173950 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelProject.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt @@ -1,24 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical `PROJECTION` operator - */ -public interface RelProject : Rel { - - public fun getInput(): Rel - - public fun getProjections(): List - - override fun getChildren(): Collection = listOf(getInput()) - - override fun isOrdered(): Boolean = getInput().isOrdered() - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitProject(this, ctx) -} - /** * Default [RelProject] implementation. */ @@ -52,4 +35,4 @@ public class RelProjectImpl(input: Rel, projections: List) : RelProject { result = 31 * result + _projections.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt similarity index 61% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt index 6c98ce1db..9485afb62 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelScan.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt @@ -1,22 +1,7 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor import org.partiql.plan.rex.Rex -/** - * Logical scan corresponding to the clause `FROM AS `. - */ -public interface RelScan : Rel { - - public fun getInput(): Rex - - override fun getChildren(): Collection = emptyList() - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitScan(this, ctx) -} - /** * Default [RelScan] implementation. */ @@ -40,4 +25,4 @@ internal class RelScanImpl(input: Rex) : RelScan { override fun hashCode(): Int { return _input.hashCode() } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt similarity index 71% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt index 31ee8c8df..bd3d1ae90 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelSort.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt @@ -1,25 +1,6 @@ package org.partiql.plan.rel import org.partiql.plan.Collation -import org.partiql.plan.Visitor - -/** - * Logical sort operator. - */ -public interface RelSort : Rel { - - public fun getInput(): Rel - - public fun getCollations(): List - - override fun getChildren(): Collection = listOf(getInput()) - - override fun getType(): RelType = getInput().getType() - - override fun isOrdered(): Boolean = true - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSort(this, ctx) -} /** * Default [RelSort] implementation. @@ -59,4 +40,4 @@ internal class RelSortImpl(input: Rel, collations: List) : RelSort { result = 31 * result + _collations.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt similarity index 72% rename from partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt index ecfb2dcfc..bb80676cb 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnion.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt @@ -1,25 +1,5 @@ package org.partiql.plan.rel -import org.partiql.plan.Visitor - -/** - * Logical `UNION [ALL|DISTINCT]` operator for set (or multiset) union. - */ -public interface RelUnion : Rel { - - public fun isAll(): Boolean - - public fun getLeft(): Rel - - public fun getRight(): Rel - - override fun getChildren(): Collection = listOf(getLeft(), getRight()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitUnion(this, ctx) -} - /** * Default [RelUnion] implementation. */ @@ -66,4 +46,4 @@ internal class RelUnionImpl(left: Rel, right: Rel, isAll: Boolean) : result = 31 * result + _right.hashCode() return result } -} +} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt new file mode 100644 index 000000000..112cd10a9 --- /dev/null +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt @@ -0,0 +1,2 @@ +package org.partiql.plan.rel + 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 deleted file mode 100644 index 55d3d9af8..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/Rel.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.Operator - -/** - * A [Rel] is an [Operator] that produces a collection of tuples. - */ -public interface Rel : Operator { - - public fun getType(): RelType - - public fun isOrdered(): Boolean -} 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 deleted file mode 100644 index 4a0c0e550..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelAggregate.kt +++ /dev/null @@ -1,75 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.AggregateCall -import org.partiql.plan.Visitor -import org.partiql.plan.rex.Rex - -/** - * TODO GROUP STRATEGY - * TODO GROUP BY - */ -public interface RelAggregate : Rel { - - public fun getInput(): Rel - - public fun getCalls(): List - - public fun getGroups(): List - - override fun getChildren(): Collection = listOf(getInput()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitAggregate(this, ctx) -} - -/** - * Default [RelAggregate] implementation. - */ -internal class RelAggregateImpl( - input: Rel, - calls: List, - groups: List, -) : - RelAggregate { - - // DO NOT USE FINAL - private var _input = input - private var _calls = calls - private var _groups = groups - - private var _children: List? = null - - override fun getInput(): Rel = _input - - override fun getCalls(): List = _calls - - override fun getGroups(): List = _groups - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_input) - } - return _children!! - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelAggregate) return false - if (_input != other.getInput()) return false - if (_calls != other.getCalls()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _calls.hashCode() - return result - } -} 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 deleted file mode 100644 index b8f51b2f4..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelCorrelate.kt +++ /dev/null @@ -1,72 +0,0 @@ -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). - */ -public interface RelCorrelate : Rel { - - public fun getLeft(): Rel - - public fun getRight(): Rel - - public fun getJoinType(): JoinType - - override fun getChildren(): Collection = listOf(getLeft(), getRight()) - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = - visitor.visitCorrelate(this, ctx) -} - -/** - * Default [RelCorrelate] implementation. - */ -internal class RelCorrelateImpl(left: Rel, right: Rel, joinType: JoinType) : RelCorrelate { - - // DO NOT USE FINAL - private var _left = left - private var _right = right - private var _joinType = joinType - - private var _children: List? = null - - override fun getLeft(): Rel = _left - - override fun getRight(): Rel = _right - - override fun getJoinType(): JoinType = _joinType - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_left, _right) - } - return _children!! - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun isOrdered(): Boolean = false - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelCorrelate) return false - if (_left != other.getLeft()) return false - if (_right != other.getRight()) return false - if (_joinType != other.getJoinType()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _left.hashCode() - result = 31 * result + _right.hashCode() - result = 31 * result + _joinType.hashCode() - return result - } -} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelType.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelType.kt deleted file mode 100644 index cd2a3da43..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelType.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.types.Field - -/** - * Analogous to a ROW type. - * - * TODO does not need to be an interface. - */ -public interface RelType { - - public fun getSize(): Int = getFields().size - - public fun getFields(): List - - public fun getField(name: String): Field -} 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 deleted file mode 100644 index d64278c9c..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/rel/RelUnpivot.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.Visitor -import org.partiql.plan.rex.Rex - -/** - * TODO DOCUMENTATION - */ -public interface RelUnpivot : Rel { - - public fun getInput(): Rex - - override fun getChildren(): Collection = emptyList() - - override fun isOrdered(): Boolean = false - - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitUnpivot(this, ctx) -} - -/** - * Default [RelUnpivot] implementation. - */ -internal class RelUnpivotImpl(input: Rex) : RelUnpivot { - - // DO NOT USE FINAL - private var _input: Rex = input - - override fun getInput(): Rex = _input - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other !is RelUnpivot) return false - return _input == other.getInput() - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun hashCode(): Int { - return _input.hashCode() - } -} From 4b37e3e90992b7f5e025c38382dec19bd2c23c25 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 15:15:45 -0500 Subject: [PATCH 02/19] Updates rels to java abc --- .../internal/compiler/StandardCompiler.kt | 4 +- .../main/java/org/partiql/plan/Collation.java | 105 +++++++++++++++--- .../main/java/org/partiql/plan/Operator.java | 46 ++++++-- .../main/java/org/partiql/plan/rel/Rel.java | 2 +- .../org/partiql/plan/rel/RelAggregate.java | 43 +++++-- .../java/org/partiql/plan/rel/RelBase.java | 28 +++++ .../org/partiql/plan/rel/RelCorrelate.java | 45 +++++++- .../org/partiql/plan/rel/RelDistinct.java | 36 +++++- .../java/org/partiql/plan/rel/RelExcept.java | 46 ++++++-- .../java/org/partiql/plan/rel/RelExclude.java | 40 ++++++- .../java/org/partiql/plan/rel/RelFilter.java | 49 ++++++-- .../org/partiql/plan/rel/RelIntersect.java | 47 +++++++- .../java/org/partiql/plan/rel/RelIterate.java | 34 +++++- .../java/org/partiql/plan/rel/RelJoin.java | 46 ++++++-- .../java/org/partiql/plan/rel/RelLimit.java | 42 ++++++- .../java/org/partiql/plan/rel/RelOffset.java | 42 ++++++- .../java/org/partiql/plan/rel/RelProject.java | 40 ++++++- .../java/org/partiql/plan/rel/RelScan.java | 36 +++++- .../java/org/partiql/plan/rel/RelSort.java | 34 +++++- .../java/org/partiql/plan/rel/RelType.java | 8 +- .../java/org/partiql/plan/rel/RelUnion.java | 48 ++++++-- .../java/org/partiql/plan/rel/RelUnpivot.java | 36 +++++- .../main/java/org/partiql/plan/rex/Rex.java | 13 +++ .../src/main/java/org/partiql/plan/rex/Rex.kt | 11 -- .../plan/rex/{RexArray.kt => RexArray.java} | 7 +- .../plan/rex/{RexBag.kt => RexBag.java} | 7 +- .../plan/rex/{RexCall.kt => RexCall.java} | 7 +- ...{RexCallDynamic.kt => RexCallDynamic.java} | 7 +- .../plan/rex/{RexCase.kt => RexCase.java} | 7 +- .../plan/rex/{RexCast.kt => RexCast.java} | 7 +- .../rex/{RexCoalesce.kt => RexCoalesce.java} | 7 +- .../plan/rex/{RexError.kt => RexError.java} | 5 +- .../plan/rex/{RexLit.kt => RexLit.java} | 5 +- .../plan/rex/{RexNullIf.kt => RexNullIf.java} | 7 +- .../{RexPathIndex.kt => RexPathIndex.java} | 5 +- .../rex/{RexPathKey.kt => RexPathKey.java} | 5 +- .../{RexPathSymbol.kt => RexPathSymbol.java} | 5 +- .../plan/rex/{RexPivot.kt => RexPivot.java} | 7 +- .../plan/rex/{RexSelect.kt => RexSelect.java} | 7 +- .../plan/rex/{RexSpread.kt => RexSpread.java} | 5 +- .../plan/rex/{RexStruct.kt => RexStruct.java} | 7 +- .../rex/{RexSubquery.kt => RexSubquery.java} | 5 +- ...exSubqueryComp.kt => RexSubqueryComp.java} | 5 +- .../{RexSubqueryIn.kt => RexSubqueryIn.java} | 5 +- ...exSubqueryTest.kt => RexSubqueryTest.java} | 5 +- .../plan/rex/{RexTable.kt => RexTable.java} | 5 +- .../plan/rex/{RexType.kt => RexType.java} | 0 .../plan/rex/{RexVar.kt => RexVar.java} | 5 +- .../org/partiql/plan/builder/PlanFactory.kt | 32 +++--- .../org/partiql/plan/impl/RelDistinctImpl.kt | 35 ------ .../org/partiql/plan/impl/RelExceptImpl.kt | 49 -------- .../org/partiql/plan/impl/RelExcludeImpl.kt | 41 ------- .../org/partiql/plan/impl/RelFilterImpl.kt | 45 -------- .../org/partiql/plan/impl/RelIntersectImpl.kt | 49 -------- .../org/partiql/plan/impl/RelIterateImpl.kt | 28 ----- .../org/partiql/plan/impl/RelJoinImpl.kt | 71 ------------ .../org/partiql/plan/impl/RelLimitImpl.kt | 38 ------- .../org/partiql/plan/impl/RelOffsetImpl.kt | 38 ------- .../org/partiql/plan/impl/RelProjectImpl.kt | 38 ------- .../org/partiql/plan/impl/RelScanImpl.kt | 28 ----- .../org/partiql/plan/impl/RelSortImpl.kt | 43 ------- .../org/partiql/plan/impl/RelUnionImpl.kt | 49 -------- .../org/partiql/plan/impl/RelUnpivotImpl.kt | 2 - 63 files changed, 838 insertions(+), 766 deletions(-) create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexArray.kt => RexArray.java} (76%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexBag.kt => RexBag.java} (77%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexCall.kt => RexCall.java} (80%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexCallDynamic.kt => RexCallDynamic.java} (82%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexCase.kt => RexCase.java} (92%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexCast.kt => RexCast.java} (85%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexCoalesce.kt => RexCoalesce.java} (76%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexError.kt => RexError.java} (68%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexLit.kt => RexLit.java} (81%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexNullIf.kt => RexNullIf.java} (79%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexPathIndex.kt => RexPathIndex.java} (77%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexPathKey.kt => RexPathKey.java} (77%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexPathSymbol.kt => RexPathSymbol.java} (79%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexPivot.kt => RexPivot.java} (87%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSelect.kt => RexSelect.java} (84%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSpread.kt => RexSpread.java} (84%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexStruct.kt => RexStruct.java} (87%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSubquery.kt => RexSubquery.java} (89%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSubqueryComp.kt => RexSubqueryComp.java} (91%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSubqueryIn.kt => RexSubqueryIn.java} (80%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexSubqueryTest.kt => RexSubqueryTest.java} (87%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexTable.kt => RexTable.java} (84%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexType.kt => RexType.java} (100%) rename partiql-plan/src/main/java/org/partiql/plan/rex/{RexVar.kt => RexVar.java} (87%) delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt 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 b7e8f70f6..2d921e78f 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 @@ -195,7 +195,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun visitAggregate(rel: RelAggregate, ctx: Unit): ExprRelation { val input = compile(rel.getInput(), ctx) - val aggs = rel.getCalls().map { call -> + val aggs = rel.getMeasures().map { call -> val agg = call.getAgg() val args = call.getArgs().map { compile(it, ctx).catch() } val distinct = call.isDistinct() @@ -241,7 +241,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitIterate(rel: RelIterate, ctx: Unit): ExprRelation { - val input = compile(rel.getInput(), ctx) + val input = compile(rel.getRex(), ctx) return when (mode) { Mode.PERMISSIVE -> RelOpIteratePermissive(input) Mode.STRICT -> RelOpIterate(input) diff --git a/partiql-plan/src/main/java/org/partiql/plan/Collation.java b/partiql-plan/src/main/java/org/partiql/plan/Collation.java index bf052768f..ee68494b1 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Collation.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Collation.java @@ -1,30 +1,105 @@ -package org.partiql.plan +package org.partiql.plan; -import org.partiql.plan.rex.Rex +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.rex.Rex; +import org.partiql.spi.Enum; /** - * TODO DOCUMENTATION + * Represents a collation, which is a resolved sort specification. */ public interface Collation { /** - * TODO REPLACE WITH COLUMN INDEX + * API WARNING – THIS WILL BE REPLACED WITH AN `int` IN 1.0. + *
+ * TODO replace with an `int` in 1.0 + * TODO ... + * + * @return the column to sort by */ - public fun getRex(): Rex + public Rex getColumn(); - public fun getOrder(): Order + /** + * @return ASC, DESC, or OTHER + */ + public Order getOrder(); + + /** + * @return NULL ordering + */ + public Nulls getNulls(); + + /** + * Collation value ordering. + */ + public final class Order extends Enum { + + private Order(int code) { + super(code); + } - public fun getNulls(): Nulls + public static final int UNKNOWN = 0; + public static final int ASC = 1; + public static final int DESC = 2; - public enum class Order { - ASC, - DESC, - OTHER, + @NotNull + public static Order ASC() { + return new Order(ASC); + } + + @NotNull + public static Order DESC() { + return new Order(DESC); + } + + @Override + public String toString() { + int code = code(); + switch (code) { + case ASC: + return "ASC"; + case DESC: + return "DESC"; + default: + return String.valueOf(code); + } + } } - public enum class Nulls { - FIRST, - LAST, - OTHER, + /** + * Collation null ordering. + */ + public final class Nulls extends Enum { + + private Nulls(int code) { + super(code); + } + + public static final int UNKNOWN = 0; + public static final int FIRST = 1; + public static final int LAST = 2; + + @NotNull + public static Order FIRST() { + return new Order(FIRST); + } + + @NotNull + public static Order LAST() { + return new Order(LAST); + } + + @Override + public String toString() { + int code = code(); + switch (code) { + case FIRST: + return "FIRST"; + case LAST: + return "LAST"; + default: + return String.valueOf(code); + } + } } } 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 083e27a2c..0afafe439 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Operator.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Operator.java @@ -1,25 +1,49 @@ -package org.partiql.plan +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; /** - * Operator is the interface for a logical plan operator. + * The interface for all logical plan operators. */ public interface Operator { - public fun accept(visitor: Visitor, ctx: C): R + /** + * Tag getter. + */ + public int getTag(); /** - * Get i-th child (input) operator. + * Tag setter. * - * @param index + * @param tag new tag value. */ - public fun getChild(index: Int) { - throw UnsupportedOperationException("getChild") - } + public void setTag(int tag); /** - * Get all child (input) operators. + * Visitor accept. * - * @return + * @param visitor visitor implementation. + * @param ctx visitor scoped args. + * @param Visitor return type. + * @param Visitor context type (scoped args). + * @return R + */ + public abstract R accept(Visitor visitor, C ctx); + + /** + * Get i-th child (input) operator. + * + * @param index child index + * @return child operator + */ + @NotNull + public abstract Operator getChild(int index); + + /** + * @return all child (input) operators. */ - public fun getChildren(): Collection + @NotNull + public abstract List getChildren(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java index ee1e8340c..f4c152f0d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java @@ -12,5 +12,5 @@ public interface Rel extends Operator { * @return RelType. */ @NotNull - public RelType getType(); + RelType getType(); } 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 b877d659c..df12b26bf 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 @@ -7,35 +7,58 @@ import org.partiql.spi.function.Aggregation; import java.util.Collection; +import java.util.List; /** - * Interface for an aggregation operator. - *
- * TODO GROUP STRATEGY ISSUE + * The logical aggregation abstract base class. */ -public interface RelAggregate extends Rel { +public abstract class RelAggregate extends RelBase { + + // TODO GROUP STRATEGY: https://github.com/partiql/partiql-lang-kotlin/issues/1664 + + private final RelType type = null; + private List children = null; + + /** + * @return the input (child 0) + */ + @NotNull + public abstract Rel getInput(); @NotNull - public Rel getInput(); + public abstract Collection getMeasures(); @NotNull - public Collection getMeasures(); + public abstract Collection getGroups(); @NotNull - public Collection getGroups(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Collection getChildren(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitAggregate(this, ctx); } /** * An aggregation function along with its arguments and any additional filters (e.g. DISTINCT). */ - public class Measure { + public static class Measure { private final Aggregation agg; private final Collection args; 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 new file mode 100644 index 000000000..c756d5dea --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java @@ -0,0 +1,28 @@ +package org.partiql.plan.rel; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; + +/** + * Abstract base class for all relational operators. + */ +public abstract class RelBase implements Rel { + + private int tag = 0; + + @Override + public int getTag() { + return tag; + } + + @Override + public void setTag(int tag) { + this.tag = tag; + } + + @NotNull + @Override + public Operator getChild(int index) { + return getChildren().get(index); + } +} 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 59e4a3402..7200c2723 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 @@ -1,24 +1,57 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.JoinType; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import java.util.List; + /** - * Logical operator for nested-loop joins (correlated subqueries // lateral joins). + * Logical nested-loop joins (correlated subqueries // lateral joins) abstract base class. */ -public interface RelCorrelate extends Rel { +public abstract class RelCorrelate extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return the left input (child 0) + */ + @NotNull + public abstract Rel getLeft(); + + /** + * @return the right input (child 1) + */ + @NotNull + public abstract Rel getRight(); @NotNull - public Rel getLeft(); + public abstract JoinType getJoinType(); @NotNull - public Rel getRight(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rel getJoinType(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getLeft(); + Rel c1 = getRight(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitCorrelate(this, ctx); } } 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 5f09989e9..cff6d6dc8 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,18 +1,46 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import java.util.List; + /** - * Logical `DISTINCT` operator. + * Logical distinct operator abstract base class. */ -public interface RelDistinct extends Rel { +public abstract class RelDistinct extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + @NotNull + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rel getInput(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitDistinct(this, ctx); } } 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 a1942d883..1e339efa0 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,26 +1,58 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import java.util.List; + /** - * Logical `EXCEPT [ALL|DISTINCT]` operator for set (or multiset) difference. + * Logical except abstract base class. */ -public interface RelExcept extends Rel { +public abstract class RelExcept extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return true if ALL else DISTINCT. + */ + public abstract boolean isAll(); + + /** + * @return left input (child 0) + */ + @NotNull + public abstract Rel getLeft(); /** - * @return true if the `ALL` keyword was used, false otherwise. + * @return right input (child 1) */ - public boolean isAll(); + @NotNull + public abstract Rel getRight(); @NotNull - public Rel getLeft(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rel getRight(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getLeft(); + Rel c1 = getRight(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitExcept(this, ctx); } } 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 4190fb025..d21e9dd43 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,23 +2,53 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Exclusion; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import java.util.Collection; +import java.util.List; /** - * Logical `EXCLUDE` operator. + * Logical exclude abstract base class. */ -public interface RelExclude extends Rel { +public abstract class RelExclude extends RelBase { + private final RelType type = null; + private List children = null; + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return exclusions (not an operator child). + */ @NotNull - public Rel getInput(); + public abstract Collection getExclusions(); @NotNull - public Collection getExclusions(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitExclude(this, ctx); } } 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 d35b1b43a..4043147f8 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,28 +1,55 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical filter operation for the WHERE and HAVING clauses. - *
- *
- *
    - *
  1. input (rel)
  2. - *
  3. predicate (rex)
  4. - *
+ * Logical filter abstract base class. */ -public interface RelFilter extends Rel { +public abstract class RelFilter extends RelBase { + + + private List children = null; + private final RelType type = null; + /** + * @return input rel (child 0) + */ @NotNull - public Rel getInput(); + public abstract Rel getInput(); + /** + * @return predicate rex (child 1) + */ @NotNull - public Rex getPredicate(); + public abstract Rex getPredicate(); + + @NotNull + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + Rex c1 = getPredicate(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitFilter(this, ctx); } } 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 47ed477f5..63535692b 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,23 +1,58 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import java.util.List; + /** - * Logical `INTERSECT [ALL|DISTINCT]` operator for set (or multiset) intersection. + * Logical intersect abstract base class. */ -public interface RelIntersect extends Rel { +public abstract class RelIntersect extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return true if ALL else DISTINCT. + */ + public abstract boolean isAll(); + + /** + * @return left rel (child 0) + */ + @NotNull + public abstract Rel getLeft(); - public boolean isAll(); + /** + * @return right rel (child 1) + */ + @NotNull + public abstract Rel getRight(); @NotNull - public Rel getLeft(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rel getRight(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getLeft(); + Rel c1 = getRight(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitIntersect(this, ctx); } } 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 03bd10e53..c290533a0 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,19 +1,47 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** * Logical scan corresponding to the clause `FROM AS AT `. */ -public interface RelIterate extends Rel { +public abstract class RelIterate extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rex (child 0) + */ + @NotNull + public abstract Rex getRex(); + + @NotNull + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rex getRex(); + @Override + public final List getChildren() { + if (children == null) { + Rex c0 = getRex(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitIterate(this, ctx); } } 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 03b0d60b4..da5a190d4 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 @@ -3,28 +3,58 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.partiql.plan.JoinType; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical join operator. + * Logical join abstract base class. */ -public interface RelJoin extends Rel { +public abstract class RelJoin extends RelBase { - @NotNull - public Rel getLeft(); + private final RelType type = null; + private List children = null; + /** + * @return left input (child 0) + */ @NotNull - public Rel getRight(); + public abstract Rel getLeft(); + /** + * @return right input (child 1) + */ @NotNull - public JoinType getJoinType(); + public abstract Rel getRight(); + /** + * @return the join condition (child 2), or null if there is no condition. + */ @Nullable - public Rex getCondition(); + public abstract Rex getCondition(); + + /** + * @return JoinType + */ + @NotNull + public abstract JoinType getJoinType(); + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getLeft(); + Rel c1 = getRight(); + Rex c2 = getCondition(); // can be null! + children = List.of(c0, c1, c2); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitJoin(this, ctx); } } 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 291344d46..6c364f514 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,22 +1,54 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical `LIMIT` operator. + * Logical limit abstract base class. */ -public interface RelLimit extends Rel { +public abstract class RelLimit extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return limit rex (child 1) + */ + @NotNull + public abstract Rex getLimit(); @NotNull - public Rel getInput(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rex getLimit(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + Rex c1 = getLimit(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitLimit(this, ctx); } } 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 8c8f682f9..fb7a8d883 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,22 +1,54 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical `OFFSET` operator. + * Logical offset abstract base class. */ -public interface RelOffset extends Rel { +public abstract class RelOffset extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return offset rex (child 1) + */ + @NotNull + public abstract Rex getOffset(); @NotNull - public Rel getInput(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rex getOffset(); + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + Rex c1 = getOffset(); + children = List.of(c0, c1); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitOffset(this, ctx); } } 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 4480ffb06..4a819d984 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,24 +1,54 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; import java.util.Collection; +import java.util.List; /** - * Logical `PROJECTION` operator + * Logical project abstract base class. */ -public interface RelProject extends Rel { +public abstract class RelProject extends RelBase { + private final RelType type = null; + private List children = null; + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return projection (not a child, it's a list not an operator). + */ @NotNull - public Rel getInput(); + public abstract Collection getProjections(); @NotNull - public Collection getProjections(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getInput(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitProject(this, ctx); } } 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 c466e6a54..fcecf6eb1 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,19 +1,47 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical scan corresponding to the clause `FROM AS `. + * Logical scan abstract base class. */ -public interface RelScan extends Rel { +public abstract class RelScan extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rex (child 0) + */ + @NotNull + public abstract Rex getRex(); + + @NotNull + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rex getRex(); + @Override + public final List getChildren() { + if (children == null) { + Rex c0 = getRex(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitScan(this, ctx); } } 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 68cb41cdd..92f22e416 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,23 +2,47 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Collation; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import java.util.Collection; +import java.util.List; /** - * Logical sort operator. + * Logical sort abstract base class. */ -public interface RelSort extends Rel { +public abstract class RelSort extends RelBase { + + private final RelType type = null; + private List children = null; + + @NotNull + public abstract Rel getInput(); @NotNull - public Rel getInput(); + public abstract Collection getCollations(); @NotNull - public Collection getCollations(); + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } + + @NotNull + @Override + public List getChildren() { + if (children == null) { + Rel c0 = getInput(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitSort(this, ctx); } } 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 7952da872..63dc672c6 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 @@ -8,16 +8,16 @@ */ public interface RelType { - public int getFieldSize(); + int getFieldSize(); @NotNull - public Field[] getFields(); + Field[] getFields(); @NotNull - public Field getField(String name); + Field getField(String name); /** * @return true if the rel produces an ordered stream of rows. */ - public boolean isOrdered(); + boolean isOrdered(); } 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 bf22d6da0..15ae385c2 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,24 +1,58 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import java.util.List; + /** - * Logical `UNION [ALL|DISTINCT]` operator for set (or multiset) union. + * Logical union abstract base class. */ -public interface RelUnion extends Rel { +public abstract class RelUnion extends RelBase { + + private final RelType type = null; + private List children = null; - public boolean isAll(); + /** + * @return true if ALL else DISTINCT. + */ + public abstract boolean isAll(); + /** + * @return left rel (child 0) + */ @NotNull - public Rel getLeft(); + public abstract Rel getLeft(); + /** + * @return right rel (child 1) + */ @NotNull - public Rel getRight(); + public abstract Rel getRight(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + Rel c0 = getLeft(); + Rel c1 = getRight(); + children = List.of(c0, c1); + } + return children; + } + + @Override + public R accept(Visitor visitor, C ctx) { return visitor.visitUnion(this, ctx); } } - 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 bc91ad415..8ca5cf21c 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,19 +1,47 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; +import java.util.List; + /** - * Logical `UNPIVOT` operator. + * Logical unpivot abstract base class. */ -public interface RelUnpivot extends Rel { +public abstract class RelUnpivot extends RelBase { + + private final RelType type = null; + private List children = null; + + /** + * @return input rex (child 0) + */ + @NotNull + public abstract Rex getRex(); + + @NotNull + @Override + public final RelType getType() { + if (type == null) { + throw new UnsupportedOperationException("Derive type is not implemented"); + } + return type; + } @NotNull - public Rex getRex(); + @Override + public final List getChildren() { + if (children == null) { + Rex c0 = getRex(); + children = List.of(c0); + } + return children; + } @Override - default public R accept(Visitor visitor, C ctx) { + public R accept(Visitor visitor, C ctx) { return visitor.visitUnpivot(this, ctx); } } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java new file mode 100644 index 000000000..211502f1d --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java @@ -0,0 +1,13 @@ +package org.partiql.plan.rex; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; + +/** + * A [Rex] is an [Operator] that produces a value. + */ +public interface Rex extends Operator { + + @NotNull + public RexType getType(); +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt deleted file mode 100644 index df78b03fc..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.partiql.plan.rex - -import org.partiql.plan.Operator - -/** - * A [Rex] is an [Operator] that produces a value. - */ -public interface Rex : Operator { - - public fun getType(): RexType -} diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java similarity index 76% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java index f979194d5..b202f717c 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java @@ -9,9 +9,10 @@ public interface RexArray : Rex { public fun getValues(): Collection - override fun getChildren(): Collection = getValues().toList() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitArray(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitArray(this, ctx) } /** @@ -25,7 +26,7 @@ internal class RexArrayImpl(values: Collection, type: RexType) : RexArray { override fun getValues(): Collection = _values - override fun getChildren(): Collection = _values.toList() + override fun getType(): RexType = _type diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java similarity index 77% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java index 7b2acba37..735f865a5 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java @@ -9,9 +9,10 @@ public interface RexBag : Rex { public fun getValues(): Collection - override fun getChildren(): Collection = getValues() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitBag(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitBag(this, ctx) } /** @@ -25,7 +26,7 @@ internal class RexBagImpl(values: Collection, type: RexType) : RexBag { override fun getValues(): Collection = _values - override fun getChildren(): Collection = _values + override fun getType(): RexType = _type diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java similarity index 80% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java index bfe39ec06..b42ef5565 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java @@ -18,9 +18,10 @@ public fun getFunction(): Function.Instance */ public fun getArgs(): List - override fun getChildren(): Collection = getArgs() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCall(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitCall(this, ctx) } /** @@ -39,5 +40,5 @@ override fun getArgs(): List = _args override fun getType(): RexType = _type - override fun getChildren(): Collection = _args + } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java similarity index 82% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java index 2c85dee79..cfe96c5d6 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java @@ -24,9 +24,10 @@ public fun getFunctions(): List */ public fun getArgs(): List - override fun getChildren(): Collection = getArgs() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCallDynamic(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitCallDynamic(this, ctx) } /** @@ -50,5 +51,5 @@ override fun getArgs(): List = args override fun getType(): RexType = _type - override fun getChildren(): Collection = args + } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java similarity index 92% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java index 4d6a665ba..697a8b56b 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java @@ -13,9 +13,10 @@ public fun getBranches(): List public fun getDefault(): Rex? - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCase(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitCase(this, ctx) - override fun getChildren(): Collection { + val children = mutableListOf() val match = getMatch() val branches = getBranches() @@ -60,7 +61,7 @@ override fun getBranches(): List = _branches override fun getDefault(): Rex? = _default - override fun getChildren(): Collection { + if (_children == null) { _children = super.getChildren() } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java similarity index 85% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java index 96f21fb20..ced96be5d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java @@ -12,9 +12,10 @@ public fun getOperand(): Rex public fun getTarget(): PType - override fun getChildren(): Collection = listOf(getOperand()) + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCast(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitCast(this, ctx) } /** @@ -32,7 +33,7 @@ override fun getOperand(): Rex = _operand override fun getTarget(): PType = _target - override fun getChildren(): Collection { + if (_children == null) { _children = listOf(_operand) } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java similarity index 76% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java index aa7cef41a..af7b0550e 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCoalesce.java @@ -9,9 +9,10 @@ public interface RexCoalesce : Rex { public fun getArgs(): List - override fun getChildren(): Collection = getArgs() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitCoalesce(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitCoalesce(this, ctx) } internal class RexCoalesceImpl(args: List, type: RexType) : RexCoalesce { @@ -22,7 +23,7 @@ internal class RexCoalesceImpl(args: List, type: RexType) : RexCoalesce { override fun getArgs(): List = _args - override fun getChildren(): Collection = _args + override fun getType(): RexType = _type diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java similarity index 68% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexError.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java index b8c018662..7467d72e5 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java @@ -10,9 +10,10 @@ public interface RexError : Rex { override fun getType(): RexType = RexType.dynamic() - override fun getChildren(): Collection = emptyList() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitError(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitError(this, ctx) } internal class RexErrorImpl : RexError diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java similarity index 81% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java index 954b0fe6d..fb8b0591e 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java @@ -10,9 +10,10 @@ public interface RexLit : Rex { public fun getValue(): Datum - override fun getChildren(): Collection = emptyList() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitLit(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitLit(this, ctx) } internal class RexLitImpl(value: Datum) : RexLit { diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java similarity index 79% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java index 9f98216cb..a371df6a1 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexNullIf.java @@ -11,9 +11,10 @@ public fun getV1(): Rex public fun getV2(): Rex - override fun getChildren(): Collection = listOf(getV1(), getV2()) + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitNullIf(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitNullIf(this, ctx) } /** @@ -31,7 +32,7 @@ override fun getV2(): Rex = _v2 override fun getType(): RexType = _v1.getType() - override fun getChildren(): Collection = listOf(_v1, _v2) + override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java similarity index 77% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java index 926e1f0a7..53d4f8003 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathIndex.java @@ -11,7 +11,8 @@ public fun getOperand(): Rex public fun getIndex(): Rex - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathIndex(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitPathIndex(this, ctx) } /** @@ -30,5 +31,5 @@ override fun getIndex() = _index override fun getType(): RexType = _type - override fun getChildren(): Collection = listOf(_operand, _index) + } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java similarity index 77% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java index 97d27ddda..b59243a31 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathKey.java @@ -11,7 +11,8 @@ public fun getOperand(): Rex public fun getKey(): Rex - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathKey(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitPathKey(this, ctx) } /** @@ -30,5 +31,5 @@ override fun getKey() = _key override fun getType(): RexType = _type - override fun getChildren(): Collection = listOf(_operand, _key) + } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java similarity index 79% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java index 2b4d400e7..0b9275568 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPathSymbol.java @@ -11,7 +11,8 @@ public fun getOperand(): Rex public fun getSymbol(): String - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPathSymbol(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitPathSymbol(this, ctx) } /** @@ -30,5 +31,5 @@ override fun getSymbol() = _symbol override fun getType(): RexType = _type - override fun getChildren(): Collection = listOf(_operand) + } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java similarity index 87% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java index 05c6bd900..b41e85670 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexPivot.java @@ -15,9 +15,10 @@ public fun getKey(): Rex public fun getValue(): Rex - override fun getChildren(): Collection = listOf(getKey(), getValue()) + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitPivot(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitPivot(this, ctx) } /** @@ -46,7 +47,7 @@ override fun getType(): RexType { return RexType(type!!) } - override fun getChildren(): Collection { + if (children == null) { children = listOf(getKey(), getValue()) } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java similarity index 84% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java index 95096cc87..4ec74c5eb 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSelect.java @@ -13,9 +13,10 @@ public fun getInput(): Rel public fun getConstructor(): Rex - override fun getChildren(): Collection = listOf(getConstructor()) + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSelect(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSelect(this, ctx) } internal class RexSelectImpl(input: Rel, constructor: Rex) : RexSelect { @@ -41,7 +42,7 @@ override fun getType(): RexType { return _type!! } - override fun getChildren(): Collection = listOf(_constructor) + override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java similarity index 84% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java index f4157f8c4..4515b9969 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java @@ -9,9 +9,10 @@ public interface RexSpread : Rex { public fun getArgs(): List - override fun getChildren(): Collection = getArgs() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSpread(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSpread(this, ctx) } /** diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java similarity index 87% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java index 3ad4cfffc..ec178cac1 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexStruct.java @@ -9,7 +9,7 @@ public interface RexStruct : Rex { public fun getFields(): List - override fun getChildren(): Collection { + val children = mutableListOf() for (field in getFields()) { children.add(field.getKey()) @@ -18,7 +18,8 @@ override fun getChildren(): Collection { return children } - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitStruct(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitStruct(this, ctx) /** * TODO DOCUMENTATION @@ -46,7 +47,7 @@ override fun getFields(): List = _fields override fun getType(): RexType = _type - override fun getChildren(): Collection { + if (_children == null) { _children = super.getChildren() } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java similarity index 89% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java index 9d94538ea..3250bc70e 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubquery.java @@ -15,7 +15,8 @@ public fun getConstructor(): Rex // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES public fun asScalar(): Boolean - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubquery(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSubquery(this, ctx) } /** @@ -38,7 +39,7 @@ override fun getType(): RexType { TODO("Not yet implemented") } - override fun getChildren(): Collection { + TODO("Not yet implemented") } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java similarity index 91% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java index 7d9ae0093..799b64b13 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java @@ -21,7 +21,8 @@ public fun getQuantifier(): Quantifier? public fun getRel(): Rel - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryComp(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryComp(this, ctx) /** * SQL for use in the . @@ -79,7 +80,7 @@ override fun getQuantifier(): Quantifier? = _quantifier override fun getRel(): Rel = _rel - override fun getChildren(): Collection = _args + // TODO hashcode/equals? } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java similarity index 80% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java index c742274a0..704439274 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryIn.java @@ -9,7 +9,8 @@ public fun getArgs(): List public fun getRel(): Rel - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryIn(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryIn(this, ctx) } /** @@ -29,7 +30,7 @@ override fun getArgs(): List = _args override fun getRel(): Rel = _rel - override fun getChildren(): Collection = _args + // TODO hashcode/equals? } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java similarity index 87% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java index 9ad2ab6bd..fb398ac1c 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryTest.java @@ -15,7 +15,8 @@ public fun getTest(): Test public fun getRel(): org.partiql.plan.rel.Rel - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitSubqueryTest(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryTest(this, ctx) /** * EXISTS and UNIQUE are defined by SQL. @@ -48,7 +49,7 @@ override fun getTest(): Test = _test override fun getRel(): org.partiql.plan.rel.Rel = _rel - override fun getChildren(): Collection = emptyList() + // TODO hashcode/equals? } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java similarity index 84% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java index 8bef45722..b36085481 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexTable.java @@ -10,9 +10,10 @@ public interface RexTable : Rex { public fun getTable(): Table - override fun getChildren(): Collection = emptyList() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitTable(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitTable(this, ctx) } /** diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java similarity index 100% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexType.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexType.java diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.kt b/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java similarity index 87% rename from partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.kt rename to partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java index 709626dc3..8ddc4309b 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java @@ -18,9 +18,10 @@ public fun getDepth(): Int */ public fun getOffset(): Int - override fun getChildren(): Collection = emptyList() + - override fun accept(visitor: Visitor, ctx: C): R = visitor.visitVar(this, ctx) + @Override + default public R accept(Visitor visitor, C ctx) { = visitor.visitVar(this, 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 ed9b9eaab..b901d12d2 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 @@ -7,38 +7,38 @@ import org.partiql.plan.JoinType import org.partiql.plan.RelAggregateCallImpl import org.partiql.plan.rel.Rel import org.partiql.plan.rel.RelAggregate -import org.partiql.plan.rel.RelAggregateImpl +import org.partiql.plan.impl.RelAggregateImpl import org.partiql.plan.rel.RelCorrelate -import org.partiql.plan.rel.RelCorrelateImpl +import org.partiql.plan.impl.RelCorrelateImpl import org.partiql.plan.rel.RelDistinct -import org.partiql.plan.rel.RelDistinctImpl +import org.partiql.plan.impl.RelDistinctImpl import org.partiql.plan.rel.RelExcept -import org.partiql.plan.rel.RelExceptImpl +import org.partiql.plan.impl.RelExceptImpl import org.partiql.plan.rel.RelExclude -import org.partiql.plan.rel.RelExcludeImpl +import org.partiql.plan.impl.RelExcludeImpl import org.partiql.plan.rel.RelFilter -import org.partiql.plan.rel.RelFilterImpl +import org.partiql.plan.impl.RelFilterImpl import org.partiql.plan.rel.RelIntersect -import org.partiql.plan.rel.RelIntersectImpl +import org.partiql.plan.impl.RelIntersectImpl import org.partiql.plan.rel.RelIterate -import org.partiql.plan.rel.RelIterateImpl +import org.partiql.plan.impl.RelIterateImpl import org.partiql.plan.rel.RelJoin -import org.partiql.plan.rel.RelJoinImpl +import org.partiql.plan.impl.RelJoinImpl import org.partiql.plan.rel.RelLimit -import org.partiql.plan.rel.RelLimitImpl +import org.partiql.plan.impl.RelLimitImpl import org.partiql.plan.rel.RelOffset -import org.partiql.plan.rel.RelOffsetImpl +import org.partiql.plan.impl.RelOffsetImpl import org.partiql.plan.rel.RelProject -import org.partiql.plan.rel.RelProjectImpl +import org.partiql.plan.impl.RelProjectImpl import org.partiql.plan.rel.RelScan -import org.partiql.plan.rel.RelScanImpl +import org.partiql.plan.impl.RelScanImpl import org.partiql.plan.rel.RelSort -import org.partiql.plan.rel.RelSortImpl +import org.partiql.plan.impl.RelSortImpl import org.partiql.plan.rel.RelType import org.partiql.plan.rel.RelUnion -import org.partiql.plan.rel.RelUnionImpl +import org.partiql.plan.impl.RelUnionImpl import org.partiql.plan.rel.RelUnpivot -import org.partiql.plan.rel.RelUnpivotImpl +import org.partiql.plan.impl.RelUnpivotImpl import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexArray import org.partiql.plan.rex.RexArrayImpl diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt deleted file mode 100644 index f4274ca9c..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelDistinctImpl.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.partiql.plan.rel - -/** - * Default [RelDistinct] implementation. - */ -internal class RelDistinctImpl(input: Rel) : RelDistinct { - - // DO NOT USE FINAL - private var _input: Rel = input - private var _children: List? = null - private var _ordered: Boolean = input.isOrdered() - - override fun getInput(): Rel = _input - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_input) - } - return _children!! - } - - override fun getType(): RelType = _input.getType() - - override fun isOrdered(): Boolean = _ordered - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other !is RelDistinct) return false - return _input == other.getInput() - } - - override fun hashCode(): Int { - return _input.hashCode() - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt deleted file mode 100644 index 42ca73359..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExceptImpl.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.partiql.plan.rel - -/** - * Default [RelExcept] implementation. - */ -internal class RelExceptImpl(left: Rel, right: Rel, isAll: Boolean) : - RelExcept { - - // DO NOT USE FINAL - private var _isAll = isAll - private var _left = left - private var _right = right - private var _children: List? = null - - override fun isAll(): Boolean = _isAll - - override fun getLeft(): Rel = _left - - override fun getRight(): Rel = _right - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_left, _right) - } - return _children!! - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun isOrdered(): Boolean = false - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelExcept) return false - if (_isAll != other.isAll()) return false - if (_left != other.getLeft()) return false - if (_right != other.getRight()) return false - return true - } - - override fun hashCode(): Int { - var result = _isAll.hashCode() - result = 31 * result + _left.hashCode() - result = 31 * result + _right.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt deleted file mode 100644 index 82af2847a..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelExcludeImpl.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.Exclusion - -/** - * Default [RelExclude] implementation. - */ -internal class RelExcludeImpl(input: Rel, exclusions: List) : RelExclude { - - // DO NOT USE FINAL - private var _input: Rel = input - private var _exclusions: List = exclusions - private var _ordered: Boolean = input.isOrdered() - - override fun getInput(): Rel = _input - - override fun getChildren(): Collection = listOf(_input) - - override fun getExclusions(): List = _exclusions - - override fun isOrdered(): Boolean = _ordered - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelExclude) return false - if (_input != other.getInput()) return false - if (_exclusions != other.getExclusions()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _exclusions.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt deleted file mode 100644 index 3d603dc55..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelFilterImpl.kt +++ /dev/null @@ -1,45 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelFilter] implementation. - */ -internal class RelFilterImpl(input: Rel, predicate: Rex) : RelFilter { - - // DO NOT USE FINAL - private var _input: Rel = input - private var _children: List? = null - private var _predicate: Rex = predicate - private var _ordered: Boolean = input.isOrdered() - - override fun getInput(): Rel = _input - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_input) - } - return _children!! - } - - override fun getPredicate(): Rex = _predicate - - override fun getType(): RelType = _input.getType() - - override fun isOrdered(): Boolean = _ordered - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelFilter) return false - if (_input != other.getInput()) return false - if (_predicate != other.getPredicate()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _predicate.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt deleted file mode 100644 index 9877701d9..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIntersectImpl.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.partiql.plan.rel - -/** - * Default [RelIntersect] implementation. - */ -internal class RelIntersectImpl(left: Rel, right: Rel, isAll: Boolean) : - RelIntersect { - - // DO NOT USE FINAL - private var _isAll = isAll - private var _left = left - private var _right = right - private var _children: List? = null - - override fun isAll(): Boolean = _isAll - - override fun getLeft(): Rel = _left - - override fun getRight(): Rel = _right - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_left, _right) - } - return _children!! - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun isOrdered(): Boolean = false - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelIntersect) return false - if (_isAll != other.isAll()) return false - if (_left != other.getLeft()) return false - if (_right != other.getRight()) return false - return true - } - - override fun hashCode(): Int { - var result = _isAll.hashCode() - result = 31 * result + _left.hashCode() - result = 31 * result + _right.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt deleted file mode 100644 index f5c81ce0a..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelIterateImpl.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelIterate] implementation. - */ -internal class RelIterateImpl(input: Rex) : RelIterate { - - // DO NOT USE FINAL - private var _input: Rex = input - - override fun getInput(): Rex = _input - - override fun getType(): RelType { - TODO("Implement getSchema for scan") - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other !is RelIterate) return false - return _input == other.getInput() - } - - override fun hashCode(): Int { - return _input.hashCode() - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt deleted file mode 100644 index 9262aec3f..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelJoinImpl.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.JoinType -import org.partiql.plan.rex.Rex - -/** - * Default [RelJoin] implementation. - */ -internal class RelJoinImpl( - left: Rel, - right: Rel, - condition: Rex?, - joinType: JoinType, - leftSchema: RelType?, - rightSchema: RelType?, -) : RelJoin { - - // DO NOT USE FINAL - private var _left = left - private var _right = right - private var _condition = condition - private var _joinType = joinType - private var _leftSchema = leftSchema - private var _rightSchema = rightSchema - - private var _children: List? = null - - override fun getLeft(): Rel = _left - - override fun getRight(): Rel = _right - - override fun getCondition(): Rex? = _condition - - override fun getJoinType(): JoinType = _joinType - - override fun getLeftSchema(): RelType? = _leftSchema - - override fun getRightSchema(): RelType? = _rightSchema - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_left, _right) - } - return _children!! - } - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun isOrdered(): Boolean = false - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelJoin) return false - if (_left != other.getLeft()) return false - if (_right != other.getRight()) return false - if (_condition != other.getCondition()) return false - if (_joinType != other.getJoinType()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _left.hashCode() - result = 31 * result + _right.hashCode() - result = 31 * result + _condition.hashCode() - result = 31 * result + _joinType.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt deleted file mode 100644 index 411e8b889..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelLimitImpl.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelLimit] implementation. - */ -internal class RelLimitImpl(input: Rel, limit: Rex) : RelLimit { - - // DO NOT USE FINAL - private var _input: Rel = input - private var _limit: Rex = limit - - override fun getInput(): Rel = _input - - override fun getLimit(): Rex = _limit - - override fun getChildren(): Collection = listOf(_input) - - override fun getType(): RelType = _input.getType() - - override fun isOrdered(): Boolean = _input.isOrdered() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelLimit) return false - if (_input != other.getInput()) return false - if (_limit != other.getLimit()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _limit.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt deleted file mode 100644 index f6feb64d8..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelOffsetImpl.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelOffset] implementation. - */ -internal class RelOffsetImpl(input: Rel, offset: Rex) : RelOffset { - - // DO NOT USE FINAL - private var _input: Rel = input - private var _offset: Rex = offset - - override fun getInput(): Rel = _input - - override fun getOffset(): Rex = _offset - - override fun getChildren(): Collection = listOf(_input) - - override fun getType(): RelType = _input.getType() - - override fun isOrdered(): Boolean = _input.isOrdered() - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelOffset) return false - if (_input != other.getInput()) return false - if (_offset != other.getOffset()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _offset.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt deleted file mode 100644 index 3d9173950..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelProjectImpl.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelProject] implementation. - */ -public class RelProjectImpl(input: Rel, projections: List) : RelProject { - - // DO NOT USE FINAL - private var _input = input - private var _projections = projections - - override fun getInput(): Rel = _input - - override fun getProjections(): List = _projections - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun getChildren(): Collection = listOf(_input) - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelProject) return false - if (_input != other.getInput()) return false - if (_projections != other.getProjections()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _projections.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt deleted file mode 100644 index 9485afb62..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelScanImpl.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.rex.Rex - -/** - * Default [RelScan] implementation. - */ -internal class RelScanImpl(input: Rex) : RelScan { - - // DO NOT USE FINAL - private var _input: Rex = input - - override fun getInput(): Rex = _input - - override fun getType(): RelType { - TODO("Implement getSchema for scan") - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other == null || other !is RelScan) return false - return _input == other.getInput() - } - - override fun hashCode(): Int { - return _input.hashCode() - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt deleted file mode 100644 index bd3d1ae90..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelSortImpl.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.partiql.plan.rel - -import org.partiql.plan.Collation - -/** - * Default [RelSort] implementation. - */ -internal class RelSortImpl(input: Rel, collations: List) : RelSort { - - // DO NOT USE FINAL - private var _input = input - private var _collations = collations - - private var _children: List? = null - - override fun getInput(): Rel = _input - - override fun getCollations(): List = _collations - - override fun getType(): RelType = _input.getType() - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_input) - } - return _children!! - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelSort) return false - if (_input != other.getInput()) return false - if (_collations != other.getCollations()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _collations.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt deleted file mode 100644 index bb80676cb..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnionImpl.kt +++ /dev/null @@ -1,49 +0,0 @@ -package org.partiql.plan.rel - -/** - * Default [RelUnion] implementation. - */ -internal class RelUnionImpl(left: Rel, right: Rel, isAll: Boolean) : - RelUnion { - - // DO NOT USE FINAL - private var _isAll = isAll - private var _left = left - private var _right = right - private var _children: List? = null - - override fun isAll(): Boolean = _isAll - - override fun getLeft(): Rel = _left - - override fun getRight(): Rel = _right - - override fun getChildren(): Collection { - if (_children == null) { - _children = listOf(_left, _right) - } - return _children!! - } - - override fun isOrdered(): Boolean = false - - override fun getType(): RelType { - TODO("Not yet implemented") - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RelUnion) return false - if (_isAll != other.isAll()) return false - if (_left != other.getLeft()) return false - if (_right != other.getRight()) return false - return true - } - - override fun hashCode(): Int { - var result = _isAll.hashCode() - result = 31 * result + _left.hashCode() - result = 31 * result + _right.hashCode() - return result - } -} \ No newline at end of file diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt deleted file mode 100644 index 112cd10a9..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/impl/RelUnpivotImpl.kt +++ /dev/null @@ -1,2 +0,0 @@ -package org.partiql.plan.rel - From 3139f3af09a27c3c19e7ede723454d82dd1f95cc Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 17:44:57 -0500 Subject: [PATCH 03/19] Rex abstract base classes --- .../internal/compiler/StandardCompiler.kt | 8 +- partiql-plan/README.md | 32 ++++ .../src/main/java/org/partiql/plan/Visitor.kt | 4 +- .../org/partiql/plan/rel/RelAggregate.java | 32 ++-- .../java/org/partiql/plan/rel/RelBase.java | 40 +++- .../org/partiql/plan/rel/RelCorrelate.java | 23 +-- .../org/partiql/plan/rel/RelDistinct.java | 21 +-- .../java/org/partiql/plan/rel/RelExcept.java | 23 +-- .../java/org/partiql/plan/rel/RelExclude.java | 24 +-- .../java/org/partiql/plan/rel/RelFilter.java | 24 +-- .../org/partiql/plan/rel/RelIntersect.java | 23 +-- .../java/org/partiql/plan/rel/RelIterate.java | 21 +-- .../java/org/partiql/plan/rel/RelJoin.java | 18 +- .../java/org/partiql/plan/rel/RelLimit.java | 23 +-- .../java/org/partiql/plan/rel/RelOffset.java | 23 +-- .../java/org/partiql/plan/rel/RelProject.java | 24 +-- .../java/org/partiql/plan/rel/RelScan.java | 21 +-- .../java/org/partiql/plan/rel/RelSort.java | 24 +-- .../java/org/partiql/plan/rel/RelUnion.java | 23 +-- .../java/org/partiql/plan/rel/RelUnpivot.java | 21 +-- .../java/org/partiql/plan/rex/RexArray.java | 57 +++--- .../java/org/partiql/plan/rex/RexBag.java | 57 +++--- .../java/org/partiql/plan/rex/RexBase.java | 64 +++++++ .../java/org/partiql/plan/rex/RexCall.java | 53 +++--- .../org/partiql/plan/rex/RexCallDynamic.java | 55 ------ .../java/org/partiql/plan/rex/RexCase.java | 136 ++++++-------- .../java/org/partiql/plan/rex/RexCast.java | 76 +++----- .../org/partiql/plan/rex/RexCoalesce.java | 51 +++--- .../org/partiql/plan/rex/RexDispatch.java | 46 +++++ .../java/org/partiql/plan/rex/RexError.java | 28 ++- .../java/org/partiql/plan/rex/RexLit.java | 48 +++-- .../java/org/partiql/plan/rex/RexNullIf.java | 67 +++---- .../org/partiql/plan/rex/RexPathIndex.java | 55 +++--- .../java/org/partiql/plan/rex/RexPathKey.java | 56 +++--- .../org/partiql/plan/rex/RexPathSymbol.java | 55 +++--- .../java/org/partiql/plan/rex/RexPivot.java | 105 +++++------ .../java/org/partiql/plan/rex/RexSelect.java | 77 ++++---- .../java/org/partiql/plan/rex/RexSpread.java | 56 +++--- .../java/org/partiql/plan/rex/RexStruct.java | 84 ++++----- .../org/partiql/plan/rex/RexSubquery.java | 67 +++---- .../org/partiql/plan/rex/RexSubqueryComp.java | 173 +++++++++++------- .../org/partiql/plan/rex/RexSubqueryIn.java | 58 +++--- .../org/partiql/plan/rex/RexSubqueryTest.java | 75 ++++---- .../java/org/partiql/plan/rex/RexTable.java | 55 +++--- .../java/org/partiql/plan/rex/RexType.java | 55 ++++-- .../java/org/partiql/plan/rex/RexVar.java | 63 +++---- .../org/partiql/plan/builder/PlanFactory.kt | 18 +- .../partiql/planner/PlanEquivalenceVisitor.kt | 4 +- 48 files changed, 1082 insertions(+), 1164 deletions(-) create mode 100644 partiql-plan/README.md create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java create mode 100644 partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java 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 2d921e78f..4a581e749 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 @@ -85,7 +85,7 @@ import org.partiql.plan.rex.Rex 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.RexDispatch import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexCast import org.partiql.plan.rex.RexCoalesce @@ -338,7 +338,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { return ExprBag(values) } - override fun visitCallDynamic(rex: RexCallDynamic, ctx: Unit): ExprValue { + override fun visitCallDynamic(rex: RexDispatch, ctx: Unit): ExprValue { // Check candidate arity for uniformity var arity: Int = -1 val name = rex.getName() @@ -401,7 +401,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitLit(rex: RexLit, ctx: Unit): ExprValue { - return ExprLit(rex.getValue()) + return ExprLit(rex.getDatum()) } override fun visitNullIf(rex: RexNullIf, ctx: Unit): ExprValue { @@ -460,7 +460,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitSubquery(rex: RexSubquery, ctx: Unit): ExprValue { - val rel = compile(rex.getRel(), ctx) + val rel = compile(rex.getInput(), ctx) val constructor = compile(rex.getConstructor(), ctx) return when (rex.asScalar()) { true -> ExprSubquery(rel, constructor) diff --git a/partiql-plan/README.md b/partiql-plan/README.md new file mode 100644 index 000000000..f746a8bcd --- /dev/null +++ b/partiql-plan/README.md @@ -0,0 +1,32 @@ +# partiql-plan + +## Classes + +* Operator +* Rel +* Rex + +## Visitors + +* Visitor +* Rewriter + +## Design + +For the rule and strategy patterns to work, we need to model classes whose children have a stable ordering; +so we have defined an abstract base class for all operators which holds children and controls the access to them. +We use base implementations for state management and enforcing children 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 children (consider wrapping a serde class) +* We don’t want to force holding state (aka having to call super constructors) +* The operator/rel/rex should be flexible for extension and the interface is the most open-ended / non-prescriptive. + +Why abstract base classes for individual operators and not interfaces? + +* Enforce children ordering is the primary reason; also can memoize children. +* Hold state such as mutable tags and computed types. +* We want the standard operators to be prescriptive but not limiting. diff --git a/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt b/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt index 29b5ca0e7..485e37f84 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt @@ -19,7 +19,7 @@ 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.RexDispatch import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexCast import org.partiql.plan.rex.RexCoalesce @@ -101,7 +101,7 @@ public interface Visitor { public fun visitCall(rex: RexCall, ctx: C): R = defaultVisit(rex, ctx) - public fun visitCallDynamic(rex: RexCallDynamic, ctx: C): R = defaultVisit(rex, ctx) + public fun visitCallDynamic(rex: RexDispatch, ctx: C): R = defaultVisit(rex, ctx) public fun visitCase(rex: RexCase, ctx: C): R = defaultVisit(rex, 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 df12b26bf..2c6635eea 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 @@ -6,7 +6,6 @@ import org.partiql.plan.rex.Rex; import org.partiql.spi.function.Aggregation; -import java.util.Collection; import java.util.List; /** @@ -16,9 +15,6 @@ public abstract class RelAggregate extends RelBase { // TODO GROUP STRATEGY: https://github.com/partiql/partiql-lang-kotlin/issues/1664 - private final RelType type = null; - private List children = null; - /** * @return the input (child 0) */ @@ -26,32 +22,26 @@ public abstract class RelAggregate extends RelBase { public abstract Rel getInput(); @NotNull - public abstract Collection getMeasures(); + public abstract List getMeasures(); @NotNull - public abstract Collection getGroups(); + public abstract List getGroups(); @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - children = List.of(c0); - } - return children; + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitAggregate(this, ctx); } @@ -61,10 +51,10 @@ public R accept(Visitor visitor, C ctx) { public static class Measure { private final Aggregation agg; - private final Collection args; + private final List args; private final Boolean distinct; - public Measure(Aggregation agg, Collection args, Boolean distinct) { + public Measure(Aggregation agg, List args, Boolean distinct) { this.agg = agg; this.args = args; this.distinct = distinct; @@ -76,7 +66,7 @@ public Aggregation getAgg() { } @NotNull - public Collection getArgs() { + public List getArgs() { return args; } 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 c756d5dea..8c325e09c 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 @@ -3,12 +3,16 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; +import java.util.List; + /** * Abstract base class for all relational operators. */ public abstract class RelBase implements Rel { private int tag = 0; + private RelType type; + private List children; @Override public int getTag() { @@ -22,7 +26,39 @@ public void setTag(int tag) { @NotNull @Override - public Operator getChild(int index) { - return getChildren().get(index); + public final RelType getType() { + if (type == null) { + type = type(); + } + return type; + } + + @NotNull + @Override + public final Operator getChild(int index) { + return children.get(index); } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + children = children(); + } + return children; + } + + /** + * PROTECTED (could also be package private atm). + * + * @return computed type. + */ + protected abstract RelType type(); + + /** + * PROTECTED (could also be package private atm). + * + * @return computed children. + */ + protected abstract List children(); } 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 7200c2723..364d0caa2 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 @@ -12,9 +12,6 @@ */ public abstract class RelCorrelate extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return the left input (child 0) */ @@ -32,26 +29,20 @@ public abstract class RelCorrelate extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getLeft(); - Rel c1 = getRight(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getLeft(); + Rel c1 = getRight(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitCorrelate(this, ctx); } } 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 cff6d6dc8..d5119c340 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 @@ -11,9 +11,6 @@ */ public abstract class RelDistinct extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rel (child 0) */ @@ -22,25 +19,19 @@ public abstract class RelDistinct extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - children = List.of(c0); - } - return children; + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitDistinct(this, ctx); } } 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 1e339efa0..9c22fa30c 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 @@ -11,9 +11,6 @@ */ public abstract class RelExcept extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return true if ALL else DISTINCT. */ @@ -33,26 +30,20 @@ public abstract class RelExcept extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getLeft(); - Rel c1 = getRight(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getLeft(); + Rel c1 = getRight(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitExcept(this, ctx); } } 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 d21e9dd43..9c8a9b004 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 @@ -5,7 +5,6 @@ import org.partiql.plan.Operator; import org.partiql.plan.Visitor; -import java.util.Collection; import java.util.List; /** @@ -13,9 +12,6 @@ */ public abstract class RelExclude extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rel (child 0) */ @@ -26,29 +22,23 @@ public abstract class RelExclude extends RelBase { * @return exclusions (not an operator child). */ @NotNull - public abstract Collection getExclusions(); + public abstract List getExclusions(); @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - children = List.of(c0); - } - return children; + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitExclude(this, ctx); } } 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 4043147f8..2aa50813b 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 @@ -12,10 +12,6 @@ */ public abstract class RelFilter extends RelBase { - - private List children = null; - private final RelType type = null; - /** * @return input rel (child 0) */ @@ -30,26 +26,20 @@ public abstract class RelFilter extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - Rex c1 = getPredicate(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getInput(); + Rex c1 = getPredicate(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitFilter(this, ctx); } } 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 63535692b..d5b15c4a5 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 @@ -11,9 +11,6 @@ */ public abstract class RelIntersect extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return true if ALL else DISTINCT. */ @@ -33,26 +30,20 @@ public abstract class RelIntersect extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getLeft(); - Rel c1 = getRight(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getLeft(); + Rel c1 = getRight(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitIntersect(this, ctx); } } 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 c290533a0..067fc07c7 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 @@ -12,9 +12,6 @@ */ public abstract class RelIterate extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rex (child 0) */ @@ -23,25 +20,19 @@ public abstract class RelIterate extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rex c0 = getRex(); - children = List.of(c0); - } - return children; + protected final List children() { + Rex c0 = getRex(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitIterate(this, ctx); } } 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 da5a190d4..5b3384552 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 @@ -14,9 +14,6 @@ */ public abstract class RelJoin extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return left input (child 0) */ @@ -43,18 +40,15 @@ public abstract class RelJoin extends RelBase { @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getLeft(); - Rel c1 = getRight(); - Rex c2 = getCondition(); // can be null! - children = List.of(c0, c1, c2); - } - return children; + protected final List children() { + Rel c0 = getLeft(); + Rel c1 = getRight(); + Rex c2 = getCondition(); // can be null! + return List.of(c0, c1, c2); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitJoin(this, ctx); } } 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 6c364f514..49d439c96 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 @@ -12,9 +12,6 @@ */ public abstract class RelLimit extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rel (child 0) */ @@ -29,26 +26,20 @@ public abstract class RelLimit extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - Rex c1 = getLimit(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getInput(); + Rex c1 = getLimit(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitLimit(this, ctx); } } 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 fb7a8d883..4def97fcc 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 @@ -12,9 +12,6 @@ */ public abstract class RelOffset extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rel (child 0) */ @@ -29,26 +26,20 @@ public abstract class RelOffset extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - Rex c1 = getOffset(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getInput(); + Rex c1 = getOffset(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitOffset(this, ctx); } } 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 4a819d984..9fcba7add 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 @@ -5,7 +5,6 @@ import org.partiql.plan.Visitor; import org.partiql.plan.rex.Rex; -import java.util.Collection; import java.util.List; /** @@ -13,9 +12,6 @@ */ public abstract class RelProject extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rel (child 0) */ @@ -26,29 +22,23 @@ public abstract class RelProject extends RelBase { * @return projection (not a child, it's a list not an operator). */ @NotNull - public abstract Collection getProjections(); + public abstract List getProjections(); @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getInput(); - children = List.of(c0); - } - return children; + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitProject(this, ctx); } } 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 fcecf6eb1..e5e247415 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 @@ -12,9 +12,6 @@ */ public abstract class RelScan extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rex (child 0) */ @@ -23,25 +20,19 @@ public abstract class RelScan extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rex c0 = getRex(); - children = List.of(c0); - } - return children; + protected final List children() { + Rex c0 = getRex(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitScan(this, ctx); } } 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 92f22e416..eecc771e2 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 @@ -5,7 +5,6 @@ import org.partiql.plan.Operator; import org.partiql.plan.Visitor; -import java.util.Collection; import java.util.List; /** @@ -13,36 +12,27 @@ */ public abstract class RelSort extends RelBase { - private final RelType type = null; - private List children = null; - @NotNull public abstract Rel getInput(); @NotNull - public abstract Collection getCollations(); + public abstract List getCollations(); @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public List getChildren() { - if (children == null) { - Rel c0 = getInput(); - children = List.of(c0); - } - return children; + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitSort(this, ctx); } } 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 15ae385c2..6305acab9 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 @@ -11,9 +11,6 @@ */ public abstract class RelUnion extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return true if ALL else DISTINCT. */ @@ -33,26 +30,20 @@ public abstract class RelUnion extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rel c0 = getLeft(); - Rel c1 = getRight(); - children = List.of(c0, c1); - } - return children; + protected final List children() { + Rel c0 = getLeft(); + Rel c1 = getRight(); + return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitUnion(this, ctx); } } 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 8ca5cf21c..5e0ce16b2 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 @@ -12,9 +12,6 @@ */ public abstract class RelUnpivot extends RelBase { - private final RelType type = null; - private List children = null; - /** * @return input rex (child 0) */ @@ -23,25 +20,19 @@ public abstract class RelUnpivot extends RelBase { @NotNull @Override - public final RelType getType() { - if (type == null) { - throw new UnsupportedOperationException("Derive type is not implemented"); - } - return type; + protected final RelType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } @NotNull @Override - public final List getChildren() { - if (children == null) { - Rex c0 = getRex(); - children = List.of(c0); - } - return children; + protected final List children() { + Rex c0 = getRex(); + return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitUnpivot(this, ctx); } } 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 b202f717c..3355c11c3 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,41 +1,38 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; -/** - * TODO DOCUMENTATION - */ -public interface RexArray : Rex { - - public fun getValues(): Collection - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitArray(this, ctx) -} +import java.util.List; /** - * Default [RexArray] operator for extension. + * Logical array expression abstract base class. */ -internal class RexArrayImpl(values: Collection, type: RexType) : RexArray { +public abstract class RexArray extends RexBase { - // DO NOT USE FINAL - private var _values = values - private var _type = type + /** + * @return the values of the array, also the children. + */ + @NotNull + public abstract List getValues(); - override fun getValues(): Collection = _values - - - - override fun getType(): RexType = _type + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.array()); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexArray) return false - if (_values != other.getValues()) return false - return true + @NotNull + @Override + protected final List children() { + List varargs = getValues(); + return List.copyOf(varargs); } - override fun hashCode(): Int = _values.hashCode() + @Override + public R accept(@NotNull Visitor visitor, C ctx) { + return visitor.visitArray(this, ctx); + } } 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 735f865a5..38f328557 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,41 +1,38 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; -/** - * TODO DOCUMENTATION - */ -public interface RexBag : Rex { - - public fun getValues(): Collection - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitBag(this, ctx) -} +import java.util.List; /** - * Default [RexBag] operator for extension. + * Logical bag expression abstract base class. */ -internal class RexBagImpl(values: Collection, type: RexType) : RexBag { +public abstract class RexBag extends RexBase { - // DO NOT USE FINAL - private var _values = values - private var _type = type + /** + * @return the values of the array, also the children. + */ + @NotNull + public abstract List getValues(); - override fun getValues(): Collection = _values - - - - override fun getType(): RexType = _type + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.bag()); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexBag) return false - if (_values != other.getValues()) return false - return true + @NotNull + @Override + protected final List children() { + List varargs = getValues(); + return List.copyOf(varargs); } - override fun hashCode(): Int = _values.hashCode() + @Override + public R accept(@NotNull Visitor visitor, C ctx) { + return visitor.visitBag(this, ctx); + } } 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 new file mode 100644 index 000000000..da5701465 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java @@ -0,0 +1,64 @@ +package org.partiql.plan.rex; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; + +import java.util.List; + +/** + * Abstract base class for all scalar expressions. + */ +public abstract class RexBase implements Rex { + + private int tag = 0; + private List children; + private RexType type; + + @Override + public int getTag() { + return tag; + } + + @Override + public void setTag(int tag) { + this.tag = tag; + } + + @NotNull + @Override + public final RexType getType() { + if (type == null) { + type = type(); + } + return type; + } + + @NotNull + @Override + public final Operator getChild(int index) { + return children.get(index); + } + + @NotNull + @Override + public final List getChildren() { + if (children == null) { + children = children(); + } + return children; + } + + /** + * PROTECTED (could also be package private atm). + * + * @return computed type. + */ + protected abstract RexType type(); + + /** + * PROTECTED (could also be package private atm). + * + * @return computed children. + */ + protected abstract List children(); +} 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 b42ef5565..230a5bd58 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,44 +1,43 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.spi.function.Function +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.spi.function.Function; + +import java.util.List; /** - * Logical operator for a scalar function call. + * Logical scalar function expression abstract base class. */ -public interface RexCall : Rex { +public abstract class RexCall extends RexBase { /** * Returns the function to invoke. */ - public fun getFunction(): Function.Instance + @NotNull + public abstract Function.Instance getFunction(); /** * Returns the list of function arguments. */ - public fun getArgs(): List - - + @NotNull + public abstract List getArgs(); @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitCall(this, ctx) -} - -/** - * Default [RexCall] implementation meant for extension. - */ -internal class RexCallImpl(function: Function.Instance, args: List) : RexCall { + protected RexType type() { + return new RexType(getFunction().returns); + } - // DO NOT USE FINAL - private var _function: Function.Instance = function - private var _args: List = args - private var _type: RexType = RexType(function.returns) - - override fun getFunction(): Function.Instance = _function - - override fun getArgs(): List = _args - - override fun getType(): RexType = _type + @Override + protected List children() { + List varargs = getArgs(); + return List.copyOf(varargs); + } - + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitCall(this, ctx); + } } + diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java deleted file mode 100644 index cfe96c5d6..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/RexCallDynamic.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.partiql.plan.rex - -import org.partiql.plan.Visitor -import org.partiql.spi.function.Function -import org.partiql.types.PType - -/** - * Logical operator for a dynamic dispatch call. - */ -public interface RexCallDynamic : Rex { - - /** - * Dynamic function name. - */ - public fun getName(): String - - /** - * Returns the functions to dispatch to. - */ - public fun getFunctions(): List - - /** - * Returns the list of function arguments. - */ - public fun getArgs(): List - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitCallDynamic(this, ctx) -} - -/** - * Default [RexCallDynamic] implementation meant for extension. - */ -internal class RexCallDynamicImpl( - private var name: String, - private var functions: List, - private var args: List, - type: PType = PType.dynamic() -) : RexCallDynamic { - - // DO NOT USE FINAL - private var _type: RexType = RexType(type) - - override fun getName(): String = name - - override fun getFunctions(): List = functions - - override fun getArgs(): List = args - - override fun getType(): RexType = _type - - -} 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 697a8b56b..4d1a8dba8 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 @@ -1,105 +1,77 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; + +import java.util.List; /** - * Representative of the simple CASE-WHEN. + * Logical case (switch) expression abstract base class. */ -public interface RexCase : Rex { - - public fun getMatch(): Rex? - - public fun getBranches(): List - - public fun getDefault(): Rex? - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitCase(this, ctx) - - - val children = mutableListOf() - val match = getMatch() - val branches = getBranches() - val default = getDefault() - if (match != null) { - children.add(match) - } - for (branch in branches) { - children.add(branch.getCondition()) - children.add(branch.getResult()) - } - if (default != null) { - children.add(default) - } - return children - } +public abstract class RexCase extends RexBase { /** - * TODO DOCUMENTATION + * @return the match expression, or {@code null} if none (child 0) */ - public interface Branch { - public fun getCondition(): Rex - public fun getResult(): Rex - } -} - -/** - * Internal implementation of [RexCase]. - */ -internal class RexCaseImpl(match: Rex?, branches: List, default: Rex?, type: RexType) : RexCase { + @Nullable + public abstract Rex getMatch(); - // DO NOT USE FINAL - private var _match = match - private var _branches = branches - private var _default = default - private var _children: Collection? = null - private var _type = type - - override fun getMatch(): Rex? = _match - - override fun getBranches(): List = _branches + /** + * @return the list of branches (not children). + */ + @NotNull + public abstract List getBranches(); - override fun getDefault(): Rex? = _default + /** + * @return the default expression, or {@code null} if none (child 1) + */ + @Nullable + public abstract Rex getDefault(); - - if (_children == null) { - _children = super.getChildren() - } - return _children!! + @NotNull + @Override + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } - override fun getType(): RexType = _type - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexCase) return false - if (_match != other.getMatch()) return false - if (_branches != other.getBranches()) return false - if (_default != other.getDefault()) return false - return true + @Override + protected List children() { + Rex c0 = getMatch(); + Rex c1 = getDefault(); + return List.of(c0, c1); } - override fun hashCode(): Int { - var result = _match.hashCode() - result = 31 * result + _branches.hashCode() - result = 31 * result + _default.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitCase(this, ctx); } /** - * CASE-WHEN branch - * - * @param condition - * @param result + * A branch of a case expression. */ - internal class Branch(condition: Rex, result: Rex) : RexCase.Branch { + public static class Branch { + + @NotNull + private final Rex condition; - // DO NOT USE FINAL - private var _condition = condition - private var _result = result + @NotNull + private final Rex result; - override fun getCondition(): Rex = _condition + public Branch(@NotNull Rex condition, @NotNull Rex result) { + this.condition = condition; + this.result = result; + } + + @NotNull + public Rex getCondition() { + return condition; + } - override fun getResult(): Rex = _result + @NotNull + public Rex getResult() { + return result; + } } } 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 ced96be5d..843b9e217 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,59 +1,33 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.types.PType +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; /** - * Logical `CAST` operator — ex: CAST( AS ). + * Logical cast expression abstract base class. */ -public interface RexCast : Rex { - - public fun getOperand(): Rex - - public fun getTarget(): PType - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitCast(this, ctx) -} - -/** - * Default [RexCast] implementation meant for extension. - */ -internal class RexCastImpl(operand: Rex, target: PType) : RexCast { - - // DO NOT USE FINAL - private var _operand = operand - private var _target = target - private var _children: List? = null - private var _type = RexType(_target) - - override fun getOperand(): Rex = _operand - - override fun getTarget(): PType = _target - - - if (_children == null) { - _children = listOf(_operand) - } - return _children!! +public abstract class RexCast extends RexBase { + + /** + * @return operand rex (child 0) + */ + @NotNull + public abstract Rex getOperand(); + + /** + * @return target type + */ + @NotNull + public abstract PType getTarget(); + + @NotNull + protected final RexType type() { + return new RexType(getTarget()); } - override fun getType(): RexType = _type - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexCast) return false - if (_operand != other.getOperand()) return false - if (_target != other.getTarget()) return false - return true - } - - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _operand.hashCode() - result = 31 * result + _target.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitCast(this, ctx); } } 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 af7b0550e..db5e8e25d 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,38 +1,35 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; + +import java.util.List; /** - * TODO DOCUMENTATION + * Logical coalesce expression abstract base class. */ -public interface RexCoalesce : Rex { - - public fun getArgs(): List +public abstract class RexCoalesce extends RexBase { - + /** + * @return the list of arguments (also the children). + */ + @NotNull + public abstract List getArgs(); @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitCoalesce(this, ctx) -} - -internal class RexCoalesceImpl(args: List, type: RexType) : RexCoalesce { - - // DO NOT USE FINAL - private var _args = args - private var _type = type - - override fun getArgs(): List = _args - - - - override fun getType(): RexType = _type + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexCoalesce) return false - if (_args != other.getArgs()) return false - return true + @Override + protected final List children() { + List varargs = getArgs(); + return List.copyOf(varargs); } - override fun hashCode(): Int = _args.hashCode() + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitCoalesce(this, ctx); + } } 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 new file mode 100644 index 000000000..0f37829f0 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/RexDispatch.java @@ -0,0 +1,46 @@ +package org.partiql.plan.rex; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.spi.function.Function; + +import java.util.List; + +/** + * Logical operator for a dynamic dispatch. + */ +public abstract class RexDispatch extends RexBase { + + /** + * Dynamic function name. + */ + public abstract String getName(); + + /** + * Returns the functions to dispatch to. + */ + public abstract List getFunctions(); + + /** + * Returns the list of function arguments. + */ + public abstract List getArgs(); + + @NotNull + @Override + protected final RexType type() { + return RexType.dynamic(); + } + + @Override + protected final List children() { + List varargs = getArgs(); + return List.copyOf(varargs); + } + + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitCallDynamic(this, ctx); + } +} 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 7467d72e5..adb28ee8b 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,19 +1,29 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; + +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; + +import java.util.List; /** * This represents scenarios in which certain operations are statically known to fail in strict mode but return missing * in permissive mode. */ -import org.partiql.plan.Visitor - -public interface RexError : Rex { +public abstract class RexError extends RexBase { - override fun getType(): RexType = RexType.dynamic() + @Override + protected RexType type() { + return new RexType(PType.unknown()); + } - + @Override + protected List children() { + return List.of(); + } @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitError(this, ctx) + public R accept(Visitor visitor, C ctx) { + return visitor.visitError(this, ctx); + } } - -internal class RexErrorImpl : RexError 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 fb8b0591e..3af906727 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,37 +1,33 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.spi.value.Datum +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.spi.value.Datum; + +import java.util.List; /** - * TODO DOCUMENTATION + * Literal value expression abstract base class. */ -public interface RexLit : Rex { - - public fun getValue(): Datum +public abstract class RexLit extends RexBase { - + @NotNull + public abstract Datum getDatum(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitLit(this, ctx) -} - -internal class RexLitImpl(value: Datum) : RexLit { - - // DO NOT USE FINAL - private var _value = value - private var _type = RexType(_value.type) - - override fun getValue(): Datum = _value - - override fun getType(): RexType = _type + protected final RexType type() { + return new RexType(getDatum().getType()); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexLit) return false - if (_value != other.getValue()) return false - return true + @Override + protected List children() { + return List.of(); } - override fun hashCode(): Int = _value.hashCode() + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitLit(this, ctx); + } } 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 a371df6a1..8ef173582 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,50 +1,43 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; -/** - * Logical operator for the SQL NULLIF special form. - */ -public interface RexNullIf : Rex { - - public fun getV1(): Rex - - public fun getV2(): Rex - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitNullIf(this, ctx) -} +import java.util.List; /** - * Internal + * Logical nullif expression abstraction base class. */ -internal class RexNullIfImpl(v1: Rex, v2: Rex) : RexNullIf { - - // DO NOT USE FINAL - private var _v1 = v1 - private var _v2 = v2 +public abstract class RexNullIf extends RexBase { - override fun getV1(): Rex = _v1 + /** + * @return v1 rex (child 0) + */ + @NotNull + public abstract Rex getV1(); - override fun getV2(): Rex = _v2 + /** + * @return v2 rex (child 1) + */ + @NotNull + public abstract Rex getV2(); - override fun getType(): RexType = _v1.getType() - - + @NotNull + @Override + protected final RexType type() { + return getV1().getType(); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexNullIf) return false - if (_v1 != other.getV1()) return false - if (_v2 != other.getV2()) return false - return true + @Override + protected final List children() { + Rex c0 = getV1(); + Rex c1 = getV2(); + return List.of(c0, c1); } - override fun hashCode(): Int { - var result = _v1.hashCode() - result = 31 * result + _v2.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitNullIf(this, ctx); } } 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 53d4f8003..67d0eaeea 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,35 +1,42 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; -/** - * Logical path index operator. - */ -public interface RexPathIndex : Rex { - - public fun getOperand(): Rex - - public fun getIndex(): Rex - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitPathIndex(this, ctx) -} +import java.util.List; /** - * Standard internal implementation for [RexPathIndex]. + * Logical path by index expression abstract base class. */ -internal class RexPathIndexImpl(operand: Rex, index: Rex, type: RexType) : RexPathIndex { +public abstract class RexPathIndex extends RexBase { - // DO NOT USE FINAL - private var _operand = operand - private var _index = index - private var _type = type + /** + * @return operand rex (child 0) + */ + @NotNull + public abstract Rex getOperand(); - override fun getOperand() = _operand + /** + * @return index rex (child 1) + */ + public abstract Rex getIndex(); - override fun getIndex() = _index + @Override + @NotNull + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); + } - override fun getType(): RexType = _type + @Override + protected final List children() { + Rex c0 = getOperand(); + Rex c1 = getIndex(); + return List.of(c0, c1); + } - + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitPathIndex(this, ctx); + } } 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 b59243a31..03555a7e0 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,35 +1,43 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; -/** - * Logical operator for path lookup by key. - */ -public interface RexPathKey : Rex { - - public fun getOperand(): Rex - - public fun getKey(): Rex - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitPathKey(this, ctx) -} +import java.util.List; /** - * Standard internal implementation for [RexPathKey]. + * Logical path by key lookup expression abstract base class. */ -internal class RexPathKeyImpl(operand: Rex, key: Rex, type: RexType) : RexPathKey { +public abstract class RexPathKey extends RexBase { - // DO NOT USE FINAL - private var _operand = operand - private var _key = key - private var _type = type + /** + * @return operand rex (child 0) + */ + @NotNull + public abstract Rex getOperand(); - override fun getOperand() = _operand + /** + * @return key rex (child 1) + */ + @NotNull + public abstract Rex getKey(); - override fun getKey() = _key + @Override + @NotNull + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); + } - override fun getType(): RexType = _type + @Override + protected List children() { + Rex c0 = getOperand(); + Rex c1 = getKey(); + return List.of(c0, c1); + } - + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitPathKey(this, ctx); + } } 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 0b9275568..0d8521986 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,35 +1,42 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; -/** - * Logical operator for path lookup by symbol. - */ -public interface RexPathSymbol : Rex { - - public fun getOperand(): Rex - - public fun getSymbol(): String - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitPathSymbol(this, ctx) -} +import java.util.List; /** - * Standard internal implementation for [RexPathSymbol]. + * Logical path by symbol lookup expression abstract base class. */ -internal class RexPathSymbolImpl(operand: Rex, symbol: String, type: RexType) : RexPathSymbol { +public abstract class RexPathSymbol extends RexBase { - // DO NOT USE FINAL - private var _operand = operand - private var _symbol = symbol - private var _type = type + /** + * @return operand rex (child 0) + */ + @NotNull + public abstract Rex getOperand(); - override fun getOperand() = _operand + /** + * @return symbol string + */ + @NotNull + public abstract String getSymbol(); - override fun getSymbol() = _symbol + @Override + @NotNull + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); + } - override fun getType(): RexType = _type + @Override + protected final List children() { + Rex c0 = getOperand(); + return List.of(c0); + } - + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitPathSymbol(this, ctx); + } } 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 b41e85670..b1eaa24b2 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,75 +1,52 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.plan.rel.Rel -import org.partiql.types.PType +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; +import org.partiql.types.PType; -/** - * TODO DOCUMENTATION - */ -public interface RexPivot : Rex { - - public fun getInput(): Rel - - public fun getKey(): Rex - - public fun getValue(): Rex - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitPivot(this, ctx) -} +import java.util.List; /** - * Default [RexPivot] operator. + * Logical pivot expression abstract base class. */ -internal class RexPivotImpl(input: Rel, key: Rex, value: Rex) : RexPivot { - - // DO NOT USE FINAL - private var _input = input - private var _key = key - private var _value = value - - private var children: List? = null - private var type: PType? = null - - override fun getInput(): Rel = _input - - override fun getKey(): Rex = _key - - override fun getValue(): Rex = _value - - override fun getType(): RexType { - if (type == null) { - type = PType.struct() - } - return RexType(type!!) - } - - - if (children == null) { - children = listOf(getKey(), getValue()) - } - return children!! +public abstract class RexPivot extends RexBase { + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return key rex (child 1) + */ + @NotNull + public abstract Rex getKey(); + + /** + * @return value rex (child 2) + */ + @NotNull + public abstract Rex getValue(); + + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.struct()); } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexPivot) return false - - if (_input != other.getInput()) return false - if (_key != other.getKey()) return false - if (_value != other.getValue()) return false - - return true + @Override + protected final List children() { + Rel c0 = getInput(); + Rex c1 = getKey(); + Rex c2 = getValue(); + return List.of(c0, c1, c2); } - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _input.hashCode() - result = 31 * result + _key.hashCode() - result = 31 * result + _value.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitPivot(this, ctx); } } 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 4ec74c5eb..50f529cc1 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,60 +1,45 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.plan.rel.Rel -import org.partiql.types.PType +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; +import org.partiql.types.PType; + +import java.util.List; /** - * TODO DOCUMENTATION + * Logical select expression abstract base class. */ -public interface RexSelect : Rex { - - public fun getInput(): Rel +public abstract class RexSelect extends RexBase { - public fun getConstructor(): Rex + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); - + /** + * @return constructor rex (child 1) + */ + public abstract Rex getConstructor(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSelect(this, ctx) -} - -internal class RexSelectImpl(input: Rel, constructor: Rex) : RexSelect { - - private var _input = input - private var _constructor = constructor - private var _type: RexType? = null - - override fun getInput(): Rel = _input - - override fun getConstructor(): Rex = _constructor - - override fun getType(): RexType { - // compute type - if (_type == null) { - val e = _constructor.getType().getPType() - _type = if (_input.isOrdered()) { - RexType(PType.array(e)) - } else { - RexType(PType.bag(e)) - } - } - return _type!! + protected final RexType type() { + return new RexType(PType.bag()); } - - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexSelect) return false - if (_input != other.getInput()) return false - if (_constructor != other.getConstructor()) return false - return true + @NotNull + @Override + protected final List children() { + Rel c0 = getInput(); + Rex c1 = getConstructor(); + return List.of(c0, c1); } - override fun hashCode(): Int { - var result = _input.hashCode() - result = 31 * result + _constructor.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitSelect(this, ctx); } } 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 4515b9969..547495bb0 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,44 +1,36 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; -/** - * TODO DOCUMENTATION - */ -public interface RexSpread : Rex { - - public fun getArgs(): List - - - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSpread(this, ctx) -} +import java.util.List; /** - * Default [RexSpread] operator intended for extension. + * Logical spread expression abstract base class. */ -internal class RexSpreadImpl(args: List, type: RexType) : RexSpread { - - // DO NOT USE FINAL - private var _args = args - private var _type = type +public abstract class RexSpread extends RexBase { - override fun getArgs(): List = _args + /** + * @return list of spread arguments (the children) + */ + public abstract List getArgs(); - override fun getType(): RexType = _type + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.struct()); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexSpreadImpl) return false - if (_args != other._args) return false - if (_type != other._type) return false - return true + @NotNull + @Override + protected final List children() { + List varargs = getArgs().stream().toList(); + return List.copyOf(varargs); } - override fun hashCode(): Int { - var result = _args.hashCode() - result = 31 * result + _type.hashCode() - return result + public R accept(Visitor visitor, C ctx) { + return visitor.visitSpread(this, 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 ec178cac1..1f9ee7157 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,65 +1,57 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.types.PType; + +import java.util.List; /** - * TODO DOCUMENTATION + * Logical struct expression abstract base class. */ -public interface RexStruct : Rex { +public abstract class RexStruct extends RexBase { - public fun getFields(): List + /** + * @return list of struct fields (NOT children) + */ + public abstract List getFields(); - - val children = mutableListOf() - for (field in getFields()) { - children.add(field.getKey()) - children.add(field.getValue()) - } - return children + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.struct()); } @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitStruct(this, ctx) - - /** - * TODO DOCUMENTATION - */ - public class Field( - private var key: Rex, - private var value: Rex, - ) { - public fun getKey(): Rex = key - public fun getValue(): Rex = value + protected List children() { + return List.of(); } -} -/** - * Default [RexStruct] implementation intended for extension. - */ -internal class RexStructImpl(fields: List, type: RexType) : RexStruct { + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitStruct(this, ctx); + } - // DO NOT USE FINAL - private var _fields = fields - private var _children: Collection? = null - private var _type = type + /** + * Struct expression field constructor. + */ + public static class Field { - override fun getFields(): List = _fields + private final Rex key; + private final Rex value; - override fun getType(): RexType = _type + public Field(Rex key, Rex value) { + this.key = key; + this.value = value; + } - - if (_children == null) { - _children = super.getChildren() + public Rex getKey() { + return key; } - return _children!! - } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexStruct) return false - if (_fields != other.getFields()) return false - return true + public Rex getValue() { + return value; + } } - - override fun hashCode(): Int = _fields.hashCode() } 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 3250bc70e..c91b14865 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,56 +1,43 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; + +import java.util.List; /** - * Scalar subquery coercion. + * Logical subquery expression abstract base class. */ -public interface RexSubquery : Rex { +public abstract class RexSubquery extends RexBase { - public fun getRel(): org.partiql.plan.rel.Rel + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES - public fun getConstructor(): Rex + public abstract Rex getConstructor(); // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES - public fun asScalar(): Boolean + public abstract boolean asScalar(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSubquery(this, ctx) -} - -/** - * Implementation of scalar subquery coercion. - */ -internal class RexSubqueryImpl(rel: org.partiql.plan.rel.Rel, constructor: Rex, asScalar: Boolean) : RexSubquery { - - // DO NOT USE FINAL - private var _rel = rel - private var _constructor = constructor - private var _asScalar = asScalar - - override fun getRel(): org.partiql.plan.rel.Rel = _rel - - override fun getConstructor(): Rex = _constructor - - override fun asScalar(): Boolean = _asScalar - - override fun getType(): RexType { - TODO("Not yet implemented") - } - - - TODO("Not yet implemented") + protected final RexType type() { + throw new UnsupportedOperationException("Derive type is not implemented"); } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexSubquery) return false - if (_rel != other.getRel()) return false - return true + @Override + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); } - override fun hashCode(): Int { - return _rel.hashCode() + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitSubquery(this, ctx); } -} +} \ No newline at end of file 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 799b64b13..8a3a0252a 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,86 +1,129 @@ -package org.partiql.plan.rex +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 +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; +import org.partiql.types.PType; + +import java.util.List; /** - * Logical operator for SQL subquery comparisons. - * - * - for subqueries. - * - . + * Logical subquery comparison expression abstract base class. + *

+ * See SQL-99 and . */ -public interface RexSubqueryComp : Rex { +public abstract class RexSubqueryComp extends RexBase { - public fun getArgs(): List + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); - public fun getComp(): Comp + /** + * @return collection comparison arguments (not children). + */ + @NotNull + public abstract List getArgs(); - public fun getQuantifier(): Quantifier? + /** + * @return subquery comparison operator + */ + @NotNull + public abstract Comparison getComparison(); - public fun getRel(): Rel + /** + * @return subquery comparison quantifier + */ + @NotNull + public abstract Quantifier getQuantifier(); + + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.bool()); + } @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryComp(this, ctx) + public R accept(Visitor visitor, C ctx) { + return visitor.visitSubqueryComp(this, ctx); + } /** * SQL for use in the . - * - * TODO transition to 1.0 enums. */ - public enum class Comp { - EQ, - NE, - LT, - LE, - GT, - GE, - OTHER; + public static class Comparison extends org.partiql.spi.Enum { + + private Comparison(int code) { + super(code); + } + + public static int UNKNOWN = 0; + public static int EQ = 1; + public static int NE = 2; + public static int LT = 3; + public static int LE = 4; + public static int GT = 5; + public static int GE = 6; + + @NotNull + public static Comparison EQ() { + return new Comparison(EQ); + } + + @NotNull + public static Comparison NE() { + return new Comparison(NE); + } + + @NotNull + public static Comparison LT() { + return new Comparison(LT); + } + + @NotNull + public static Comparison LE() { + return new Comparison(LE); + } + + @NotNull + public static Comparison GT() { + return new Comparison(GT); + } + + @NotNull + public static Comparison GE() { + return new Comparison(GE); + } } /** * SQL for use in the . - * - * TODO transition to 1.0 enums. */ - public enum class Quantifier { - ANY, - ALL, - SOME, - OTHER; + public static class Quantifier extends org.partiql.spi.Enum { + + private Quantifier(int code) { + super(code); + } + + public static int UNKNOWN = 0; + public static int ANY = 1; + public static int ALL = 2; + public static int SOME = 3; + + @NotNull + public static Quantifier ANY() { + return new Quantifier(ANY); + } + + @NotNull + public static Quantifier ALL() { + return new Quantifier(ALL); + } + + @NotNull + public static Quantifier SOME() { + return new Quantifier(SOME); + } } } - -/** - * Logical operator for SQL subquery comparisons. - * - * - for subqueries. - * - . - */ -internal class RexSubqueryCompImpl( - args: List, - comp: Comp, - quantifier: Quantifier?, - rel: Rel, -) : RexSubqueryComp { - - private var _args = args - private var _comp = comp - private var _quantifier = quantifier - private var _rel = rel - - override fun getType(): RexType = TODO("Not yet implemented") - - override fun getArgs(): List = _args - - override fun getComp(): Comp = _comp - - override fun getQuantifier(): Quantifier? = _quantifier - - override fun getRel(): Rel = _rel - - - - // TODO hashcode/equals? -} 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 704439274..dd6b8a947 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,36 +1,44 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.plan.rel.Rel +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; +import org.partiql.types.PType; -public interface RexSubqueryIn : Rex { - - public fun getArgs(): List - - public fun getRel(): Rel - - @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryIn(this, ctx) -} +import java.util.List; +import java.util.List; /** - * Logical operator for SQL subquery comparisons. - * - * - for subqueries. - * - . + * Logical subquery in expression abstract base class. */ -internal class RexSubqueryInImpl(args: List, rel: Rel) : RexSubqueryIn { +public abstract class RexSubqueryIn extends RexBase { - private var _args = args - private var _rel = rel + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); - override fun getType(): RexType = TODO("Not yet implemented") + /** + * @return collection comparison arguments (not children). + */ + @NotNull + public abstract List getArgs(); - override fun getArgs(): List = _args - - override fun getRel(): Rel = _rel + @Override + protected final RexType type() { + return new RexType(PType.bool()); + } - + @Override + protected List children() { + Rel c0 = getInput(); + return List.of(c0); + } - // TODO hashcode/equals? + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitSubqueryIn(this, ctx); + } } 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 fb398ac1c..c408aa4f1 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,55 +1,60 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.plan.rex.RexSubqueryTest.Test +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.plan.rel.Rel; +import org.partiql.types.PType; + +import java.util.List; /** - * Logical expression for subquery tests EXISTS and UNIQUE. - * + * Logical subquery test expression abstract base class. + *
+ *

  *  -     "Specify a test for a non-empty set."
  *  -     "Specify a test for the absence of duplicate rows."
+ * 
*/ -public interface RexSubqueryTest : Rex { +public abstract class RexSubqueryTest extends RexBase { + + /** + * @return input rel (child 0) + */ + @NotNull + public abstract Rel getInput(); + + /** + * @return subquery test + */ + @NotNull + public abstract Test getTest(); - public fun getTest(): Test + @NotNull + @Override + protected final RexType type() { + return new RexType(PType.bool()); + } - public fun getRel(): org.partiql.plan.rel.Rel + @Override + protected List children() { + Rel c0 = getInput(); + return List.of(c0); + } @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitSubqueryTest(this, ctx) + public R accept(Visitor visitor, C ctx) { + return visitor.visitSubqueryTest(this, ctx); + } /** * EXISTS and UNIQUE are defined by SQL. - * + *

* TODO use 1.0 enum modeling. */ - public enum class Test { + public enum Test { EXISTS, UNIQUE, OTHER; } } - -/** - * Logical operator for SQL subquery comparisons. - * - * - for subqueries. - * - . - */ -internal class RexSubqueryTestImpl(test: Test, rel: org.partiql.plan.rel.Rel) : RexSubqueryTest { - - private var _test = test - private var _rel = rel - - override fun getType(): RexType { - TODO("Not yet implemented") - } - - override fun getTest(): Test = _test - - override fun getRel(): org.partiql.plan.rel.Rel = _rel - - - - // TODO hashcode/equals? -} 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 b36085481..d28d37d42 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,44 +1,35 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor -import org.partiql.spi.catalog.Table +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; +import org.partiql.spi.catalog.Table; + +import java.util.List; /** * Global variable references e.g. tables and views. */ -public interface RexTable : Rex { - - public fun getTable(): Table +public abstract class RexTable extends RexBase { - + /** + * @return the table implementation. + */ + public abstract Table getTable(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitTable(this, ctx) -} - -/** - * Default [RexTable] implementation. - */ -internal class RexTableImpl(table: Table) : RexTable { - - // DO NOT USE FINAL - private var _table = table - private var _type = RexType(table.getSchema()) - - override fun getTable(): Table = _table - - override fun getType(): RexType = _type + protected final RexType type() { + return new RexType(getTable().getSchema()); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexTable) return false - if (_table != other.getTable()) return false - return true + @Override + protected final List children() { + return List.of(); } - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _table.hashCode() - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitTable(this, ctx); } -} +} \ No newline at end of file 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 b2f2dc9cf..9c651b34c 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 @@ -1,32 +1,53 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.types.PType +import org.partiql.types.PType; /** * [RexType] is a simple wrapper over [PType], but does not necessarily only hold a PType. - * - * + *

+ *

* Developer Note: In later releases, a [RexType] may hold metadata to aid custom planner implementations. */ -public class RexType public constructor(type: PType) { +public class RexType { - // PRIVATE VAR - private var _type: PType = type + private final PType type; - public fun getPType(): PType = _type + public RexType(PType type) { + this.type = type; + } - override fun equals(other: Any?): Boolean = _type == other + public PType getPType() { + return type; + } - override fun hashCode(): Int = _type.hashCode() + @Override + public int hashCode() { + return type.hashCode(); + } - override fun toString(): String = _type.toString() + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof RexType)) { + return false; + } + return type.equals(((RexType) obj).type); + } - public companion object { + @Override + public String toString() { + return type.toString(); + } - /** - * A [RexType] for an "untyped" logical plan node. - */ - @JvmStatic - public fun dynamic(): RexType = RexType(PType.dynamic()) + /** + * A [RexType] for an "untyped" logical plan node. + */ + public static RexType dynamic() { + return new RexType(PType.dynamic()); } } 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 8ddc4309b..c1d4a77b2 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,57 +1,40 @@ -package org.partiql.plan.rex +package org.partiql.plan.rex; -import org.partiql.plan.Visitor +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; +import org.partiql.plan.Visitor; + +import java.util.List; /** - * TODO DOCUMENTATION - * TODO NAMING?? + * Logical variable reference expression abstract base class. */ -public interface RexVar : Rex { +public abstract class RexVar extends RexBase { /** - * 0-indexed scope offset. + * @return 0-indexed scope offset. */ - public fun getDepth(): Int + public abstract int getDepth(); /** - * 0-index tuple offset. + * @return 0-index tuple offset. */ - public fun getOffset(): Int - - + public abstract int getOffset(); + @NotNull @Override - default public R accept(Visitor visitor, C ctx) { = visitor.visitVar(this, ctx) -} - -/** - * Default [RexVar] implementation intended for extension. - */ -internal class RexVarImpl(depth: Int, offset: Int, type: RexType) : RexVar { - - // DO NOT USE FINAL - private var _depth = depth - private var _offset = offset - private var _type = type - - override fun getDepth(): Int = _depth - - override fun getOffset(): Int = _offset - - override fun getType(): RexType = _type + protected final RexType type() { + // would need to lookup in context + throw new UnsupportedOperationException("Derive type is not implemented"); + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is RexVar) return false - if (_depth != other.getDepth()) return false - if (_offset != other.getOffset()) return false - return true + @Override + protected final List children() { + return List.of(); } - override fun hashCode(): Int { - var result = 1 - result = 31 * result + _depth - result = 31 * result + _offset - return result + @Override + public R accept(Visitor visitor, C ctx) { + return visitor.visitVar(this, 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 b901d12d2..3fffc7faf 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 @@ -45,7 +45,7 @@ import org.partiql.plan.rex.RexArrayImpl import org.partiql.plan.rex.RexBag import org.partiql.plan.rex.RexBagImpl import org.partiql.plan.rex.RexCall -import org.partiql.plan.rex.RexCallDynamic +import org.partiql.plan.rex.RexDispatch import org.partiql.plan.rex.RexCallDynamicImpl import org.partiql.plan.rex.RexCallImpl import org.partiql.plan.rex.RexCase @@ -389,14 +389,14 @@ public interface PlanFactory { public fun rexCall(function: Function.Instance, args: List): RexCall = RexCallImpl(function, args) /** - * Create a [RexCallDynamic] instance. + * Create a [RexDispatch] instance. * * @param name TODO * @param functions TODO * @param args TODO * @return TODO */ - public fun rexCallDynamic(name: String, functions: List, args: List): RexCallDynamic = + public fun rexCallDynamic(name: String, functions: List, args: List): RexDispatch = RexCallDynamicImpl(name, functions, args) /** @@ -632,31 +632,31 @@ public interface PlanFactory { * Create a [RexSubqueryComp] instance. * * @param args - * @param comp + * @param comparison * @param rel * @return */ public fun rexSubqueryComp( args: List, - comp: RexSubqueryComp.Comp, + comparison: RexSubqueryComp.Comparison, rel: Rel, - ): RexSubqueryComp = RexSubqueryCompImpl(args, comp, null, rel) + ): RexSubqueryComp = RexSubqueryCompImpl(args, comparison, null, rel) /** * Create a [RexSubqueryComp] instance. * * @param args - * @param comp + * @param comparison * @param quantifier * @param rel * @return */ public fun rexSubqueryComp( args: List, - comp: RexSubqueryComp.Comp, + comparison: RexSubqueryComp.Comparison, quantifier: RexSubqueryComp.Quantifier?, rel: Rel, - ): RexSubqueryComp = RexSubqueryCompImpl(args, comp, quantifier, rel) + ): RexSubqueryComp = RexSubqueryCompImpl(args, comparison, quantifier, rel) /** * Create a [RexSubqueryIn] instance for single argument. 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 a2013587e..24419814c 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt @@ -25,7 +25,7 @@ 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.RexDispatch import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexCast import org.partiql.plan.rex.RexCoalesce @@ -155,7 +155,7 @@ object PlanEquivalenceVisitor : Visitor { return super.visitCall(rex, other) } - override fun visitCallDynamic(rex: RexCallDynamic, other: Any): Boolean { + override fun visitCallDynamic(rex: RexDispatch, other: Any): Boolean { return super.visitCallDynamic(rex, other) } From 2b865d1634d126a0656d3fdb115b5386079911eb Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 18:28:17 -0500 Subject: [PATCH 04/19] Converts other plan APIs to java --- .../java/org/partiql/plan/AggregateCall.kt | 37 ---- .../main/java/org/partiql/plan/JoinType.java | 40 ++++ .../main/java/org/partiql/plan/JoinType.kt | 13 -- .../main/java/org/partiql/plan/Operation.java | 22 +++ .../main/java/org/partiql/plan/Operation.kt | 26 --- .../src/main/java/org/partiql/plan/Plan.java | 23 +++ .../src/main/java/org/partiql/plan/Plan.kt | 25 --- .../partiql/plan/{Version.kt => Version.java} | 5 +- .../main/java/org/partiql/plan/Visitor.java | 186 ++++++++++++++++++ .../src/main/java/org/partiql/plan/Visitor.kt | 143 -------------- .../org/partiql/plan/rex/RexSubqueryComp.java | 27 +-- .../org/partiql/plan/rex/RexSubqueryIn.java | 1 - .../org/partiql/plan/rex/RexSubqueryTest.java | 26 ++- 13 files changed, 308 insertions(+), 266 deletions(-) delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt create mode 100644 partiql-plan/src/main/java/org/partiql/plan/JoinType.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/JoinType.kt create mode 100644 partiql-plan/src/main/java/org/partiql/plan/Operation.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/Operation.kt create mode 100644 partiql-plan/src/main/java/org/partiql/plan/Plan.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/Plan.kt rename partiql-plan/src/main/java/org/partiql/plan/{Version.kt => Version.java} (67%) create mode 100644 partiql-plan/src/main/java/org/partiql/plan/Visitor.java delete mode 100644 partiql-plan/src/main/java/org/partiql/plan/Visitor.kt diff --git a/partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt b/partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt deleted file mode 100644 index 7d1cf0b8f..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/AggregateCall.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.partiql.plan - -import org.partiql.plan.rex.Rex -import org.partiql.spi.function.Aggregation - -/** - * TODO DOCUMENTATION - * - * TODO this does not need to be an interface. - */ -public interface AggregateCall { - - public fun getAgg(): Aggregation - - public fun getArgs(): List - - public fun isDistinct(): Boolean -} - -/** - * Internal standard implementation of [AggregateCall]. - * - * DO NOT USE FINAL. - * - * @property agg - * @property args - * @property isDistinct - */ -internal class RelAggregateCallImpl( - private var agg: Aggregation, - private var args: List, - private var isDistinct: Boolean, -) : AggregateCall { - override fun getAgg(): Aggregation = agg - override fun getArgs(): List = args - override fun isDistinct(): Boolean = isDistinct -} diff --git a/partiql-plan/src/main/java/org/partiql/plan/JoinType.java b/partiql-plan/src/main/java/org/partiql/plan/JoinType.java new file mode 100644 index 000000000..76006de9e --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/JoinType.java @@ -0,0 +1,40 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; +import org.partiql.spi.Enum; + +/** + * PartiQL JOIN types. + */ +public class JoinType extends Enum { + + public static final int UNKNOWN = 0; + public static final int INNER = 1; + public static final int LEFT = 2; + public static final int RIGHT = 3; + public static final int FULL = 4; + + private JoinType(int value) { + super(value); + } + + @NotNull + public static JoinType INNER() { + return new JoinType(INNER); + } + + @NotNull + public static JoinType LEFT() { + return new JoinType(LEFT); + } + + @NotNull + public static JoinType RIGHT() { + return new JoinType(RIGHT); + } + + @NotNull + public static JoinType FULL() { + return new JoinType(FULL); + } +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/JoinType.kt b/partiql-plan/src/main/java/org/partiql/plan/JoinType.kt deleted file mode 100644 index 4fd9c8302..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/JoinType.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.partiql.plan - -/** - * PartiQL JOIN types. - * - * TODO use 1.0 enum modeling. - */ -public enum class JoinType { - INNER, - LEFT, - RIGHT, - FULL, -} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Operation.java b/partiql-plan/src/main/java/org/partiql/plan/Operation.java new file mode 100644 index 000000000..2cdc8e5e4 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/Operation.java @@ -0,0 +1,22 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.rex.Rex; + +/** + * TODO DOCUMENTATION + */ +public interface Operation { + + /** + * PartiQL Query Statement — i.e. SELECT-FROM + */ + public interface Query extends Operation { + + /** + * Returns the root expression of the query. + */ + @NotNull + public Rex getRex(); + } +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Operation.kt b/partiql-plan/src/main/java/org/partiql/plan/Operation.kt deleted file mode 100644 index ae4482401..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/Operation.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.partiql.plan - -import org.partiql.plan.rex.Rex -import org.partiql.plan.rex.RexType - -/** - * TODO DOCUMENTATION - */ -public interface Operation { - - /** - * PartiQL Query Statement — i.e. SELECT-FROM - */ - public interface Query : Operation { - - /** - * Returns the root expression of the query. - */ - public fun getRex(): Rex - - /** - * Returns the type of the root expression of the query. - */ - public fun getType(): RexType = getRex().getType() - } -} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Plan.java b/partiql-plan/src/main/java/org/partiql/plan/Plan.java new file mode 100644 index 000000000..1ed8d1269 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/Plan.java @@ -0,0 +1,23 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * A plan holds operations that can be executed. + */ +public interface Plan { + + /** + * @return version for serialization and debugging. + */ + @NotNull + public Version getVersion(); + + /** + * @return operations to execute. + */ + @NotNull + public List getOperations(); +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Plan.kt b/partiql-plan/src/main/java/org/partiql/plan/Plan.kt deleted file mode 100644 index 5003e92ac..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/Plan.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.partiql.plan - -/** - * A [Plan] holds operations that can be executed. - */ -public interface Plan { - - /** - * The plan version for serialization and debugging. - * - * @return - */ - public fun getVersion(): Version = object : Version { - override fun toString(): String = "1" - } - - /** - * The plan operation to execute. - * - * TODO consider `getOperations(): List`. - * - * @return - */ - public fun getOperation(): Operation -} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Version.kt b/partiql-plan/src/main/java/org/partiql/plan/Version.java similarity index 67% rename from partiql-plan/src/main/java/org/partiql/plan/Version.kt rename to partiql-plan/src/main/java/org/partiql/plan/Version.java index ff24df802..07fbbc77b 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Version.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/Version.java @@ -1,4 +1,4 @@ -package org.partiql.plan +package org.partiql.plan; /** * Marker interface for some version structure. @@ -8,5 +8,6 @@ public interface Version { /** * The only required method is toString. */ - override fun toString(): String + @Override + public String toString(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/Visitor.java b/partiql-plan/src/main/java/org/partiql/plan/Visitor.java new file mode 100644 index 000000000..7796d2bae --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/Visitor.java @@ -0,0 +1,186 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.rel.*; +import org.partiql.plan.rex.*; + +/** + * A visitor for a logical [Operator] tree. + * + * @param Visit return type + * @param Context parameter type + */ +public interface Visitor { + + default R defaultVisit(Operator operator, C ctx) { + for (Operator child : operator.getChildren()) { + child.accept(this, ctx); + } + return defaultReturn(operator, ctx); + } + + R defaultReturn(@NotNull Operator operator, C ctx); + + default R visit(@NotNull Operator operator, C ctx) { + return operator.accept(this, ctx); + } + + // --[Rel]----------------------------------------------------------------------------------------------------------- + + default R visitAggregate(@NotNull RelAggregate rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitDistinct(@NotNull RelDistinct rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitExcept(@NotNull RelExcept rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitExclude(@NotNull RelExclude rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitFilter(@NotNull RelFilter rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitIntersect(@NotNull RelIntersect rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitIterate(@NotNull RelIterate rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitJoin(@NotNull RelJoin rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitCorrelate(@NotNull RelCorrelate rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitLimit(@NotNull RelLimit rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitOffset(@NotNull RelOffset rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitProject(@NotNull RelProject rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitScan(@NotNull RelScan rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitSort(@NotNull RelSort rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitUnion(@NotNull RelUnion rel, C ctx) { + return defaultVisit(rel, ctx); + } + + default R visitUnpivot(@NotNull RelUnpivot rel, C ctx) { + return defaultVisit(rel, ctx); + } + // --[Rex]----------------------------------------------------------------------------------------------------------- + + default R visitArray(@NotNull RexArray rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitBag(@NotNull RexBag rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitCall(@NotNull RexCall rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitCallDynamic(@NotNull RexDispatch rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitCase(@NotNull RexCase rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitCast(@NotNull RexCast rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitCoalesce(@NotNull RexCoalesce rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitError(@NotNull RexError rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitLit(@NotNull RexLit rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitNullIf(@NotNull RexNullIf rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitPathIndex(@NotNull RexPathIndex rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitPathKey(@NotNull RexPathKey rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitPathSymbol(@NotNull RexPathSymbol rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitPivot(@NotNull RexPivot rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSelect(@NotNull RexSelect rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitStruct(@NotNull RexStruct rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSubquery(@NotNull RexSubquery rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSubqueryComp(@NotNull RexSubqueryComp rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSubqueryIn(@NotNull RexSubqueryIn rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSubqueryTest(@NotNull RexSubqueryTest rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitSpread(@NotNull RexSpread rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitTable(@NotNull RexTable rex, C ctx) { + return defaultVisit(rex, ctx); + } + + default R visitVar(@NotNull RexVar rex, C ctx) { + return defaultVisit(rex, ctx); + } +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt b/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt deleted file mode 100644 index 485e37f84..000000000 --- a/partiql-plan/src/main/java/org/partiql/plan/Visitor.kt +++ /dev/null @@ -1,143 +0,0 @@ -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.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.RexDispatch -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.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 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: RexDispatch, 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 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/java/org/partiql/plan/rex/RexSubqueryComp.java b/partiql-plan/src/main/java/org/partiql/plan/rex/RexSubqueryComp.java index 8a3a0252a..2f907b78b 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 @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Visitor; import org.partiql.plan.rel.Rel; +import org.partiql.spi.Enum; import org.partiql.types.PType; import java.util.List; @@ -52,19 +53,19 @@ public R accept(Visitor visitor, C ctx) { /** * SQL for use in the . */ - public static class Comparison extends org.partiql.spi.Enum { + public static class Comparison extends Enum { private Comparison(int code) { super(code); } - public static int UNKNOWN = 0; - public static int EQ = 1; - public static int NE = 2; - public static int LT = 3; - public static int LE = 4; - public static int GT = 5; - public static int GE = 6; + public static final int UNKNOWN = 0; + public static final int EQ = 1; + public static final int NE = 2; + public static final int LT = 3; + public static final int LE = 4; + public static final int GT = 5; + public static final int GE = 6; @NotNull public static Comparison EQ() { @@ -100,16 +101,16 @@ public static Comparison GE() { /** * SQL for use in the . */ - public static class Quantifier extends org.partiql.spi.Enum { + public static class Quantifier extends Enum { private Quantifier(int code) { super(code); } - public static int UNKNOWN = 0; - public static int ANY = 1; - public static int ALL = 2; - public static int SOME = 3; + public static final int UNKNOWN = 0; + public static final int ANY = 1; + public static final int ALL = 2; + public static final int SOME = 3; @NotNull public static Quantifier ANY() { 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 dd6b8a947..bdc1a77ef 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 @@ -6,7 +6,6 @@ import org.partiql.plan.rel.Rel; import org.partiql.types.PType; -import java.util.List; import java.util.List; /** 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 c408aa4f1..642ee71c4 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 @@ -4,6 +4,7 @@ import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rel.Rel; +import org.partiql.spi.Enum; import org.partiql.types.PType; import java.util.List; @@ -49,12 +50,25 @@ public R accept(Visitor visitor, C ctx) { /** * EXISTS and UNIQUE are defined by SQL. - *

- * TODO use 1.0 enum modeling. */ - public enum Test { - EXISTS, - UNIQUE, - OTHER; + public static class Test extends Enum { + + public static final int UKNOWNN = 0; + public static final int EXISTS = 1; + public static final int UNIQUE = 2; + + private Test(int code) { + super(code); + } + + @NotNull + public static Test EXISTS() { + return new Test(EXISTS); + } + + @NotNull + public static Test UNIQUE() { + return new Test(UNIQUE); + } } } From 3f4d4e1d1cfbab836be0c0facec11dcae8125060 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 19:04:31 -0500 Subject: [PATCH 05/19] Adds standard impls with named constructor --- .../internal/compiler/StandardCompiler.kt | 2 +- .../org/partiql/plan/rel/RelAggregate.java | 43 +++++++++++++- .../org/partiql/plan/rel/RelCorrelate.java | 39 ++++++++++++ .../org/partiql/plan/rel/RelDistinct.java | 23 ++++++++ .../java/org/partiql/plan/rel/RelExcept.java | 42 ++++++++++++- .../java/org/partiql/plan/rel/RelExclude.java | 32 ++++++++++ .../java/org/partiql/plan/rel/RelFilter.java | 31 ++++++++++ .../org/partiql/plan/rel/RelIntersect.java | 42 ++++++++++++- .../java/org/partiql/plan/rel/RelIterate.java | 23 ++++++++ .../java/org/partiql/plan/rel/RelJoin.java | 52 ++++++++++++++++ .../java/org/partiql/plan/rel/RelLimit.java | 33 ++++++++++- .../java/org/partiql/plan/rel/RelOffset.java | 34 ++++++++++- .../java/org/partiql/plan/rel/RelProject.java | 31 ++++++++++ .../java/org/partiql/plan/rel/RelScan.java | 23 ++++++++ .../java/org/partiql/plan/rel/RelSort.java | 33 ++++++++++- .../java/org/partiql/plan/rel/RelUnion.java | 38 ++++++++++++ .../java/org/partiql/plan/rel/RelUnpivot.java | 23 ++++++++ .../java/org/partiql/plan/rex/RexArray.java | 23 ++++++++ .../java/org/partiql/plan/rex/RexBag.java | 23 ++++++++ .../java/org/partiql/plan/rex/RexCall.java | 28 +++++++++ .../java/org/partiql/plan/rex/RexCase.java | 35 +++++++++++ .../java/org/partiql/plan/rex/RexCast.java | 38 ++++++++++++ .../org/partiql/plan/rex/RexCoalesce.java | 23 ++++++++ .../org/partiql/plan/rex/RexDispatch.java | 36 +++++++++++ .../java/org/partiql/plan/rex/RexError.java | 13 ++++ .../java/org/partiql/plan/rex/RexLit.java | 23 ++++++++ .../java/org/partiql/plan/rex/RexNullIf.java | 31 ++++++++++ .../org/partiql/plan/rex/RexPathIndex.java | 31 ++++++++++ .../java/org/partiql/plan/rex/RexPathKey.java | 31 ++++++++++ .../org/partiql/plan/rex/RexPathSymbol.java | 31 ++++++++++ .../java/org/partiql/plan/rex/RexPivot.java | 39 ++++++++++++ .../java/org/partiql/plan/rex/RexSelect.java | 31 ++++++++++ .../java/org/partiql/plan/rex/RexSpread.java | 22 +++++++ .../java/org/partiql/plan/rex/RexStruct.java | 35 ++++++++++- .../org/partiql/plan/rex/RexSubquery.java | 43 +++++++++++++- .../org/partiql/plan/rex/RexSubqueryComp.java | 59 +++++++++++++++++++ .../org/partiql/plan/rex/RexSubqueryIn.java | 33 ++++++++++- .../org/partiql/plan/rex/RexSubqueryTest.java | 33 ++++++++++- .../java/org/partiql/plan/rex/RexTable.java | 24 +++++++- .../java/org/partiql/plan/rex/RexVar.java | 29 +++++++++ .../org/partiql/plan/builder/RelBuilder.kt | 12 ++-- 41 files changed, 1248 insertions(+), 22 deletions(-) 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 4a581e749..42822943b 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 @@ -462,7 +462,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun visitSubquery(rex: RexSubquery, ctx: Unit): ExprValue { val rel = compile(rex.getInput(), ctx) val constructor = compile(rex.getConstructor(), ctx) - return when (rex.asScalar()) { + return when (rex.isScalar()) { true -> ExprSubquery(rel, constructor) else -> ExprSubqueryRow(rel, constructor) } 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 2c6635eea..0f51a0188 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 @@ -8,12 +8,20 @@ import java.util.List; +// TODO GROUP STRATEGY: https://github.com/partiql/partiql-lang-kotlin/issues/1664 + /** * The logical aggregation abstract base class. */ public abstract class RelAggregate extends RelBase { - // TODO GROUP STRATEGY: https://github.com/partiql/partiql-lang-kotlin/issues/1664 + /** + * @return new {@link RelAggregate} instance + */ + @NotNull + public static RelAggregate create(@NotNull Rel input, @NotNull List measures, @NotNull List groups) { + return new Impl(input, measures, groups); + } /** * @return the input (child 0) @@ -47,6 +55,8 @@ public R accept(@NotNull Visitor visitor, C ctx) { /** * An aggregation function along with its arguments and any additional filters (e.g. DISTINCT). + *
+ * TODO unnest ?? */ public static class Measure { @@ -75,4 +85,35 @@ public Boolean isDistinct() { return distinct; } } + + private static class Impl extends RelAggregate { + + private final Rel input; + private final List measures; + private final List groups; + + public Impl(Rel input, List measures, List groups) { + this.input = input; + this.measures = measures; + this.groups = groups; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getMeasures() { + return measures; + } + + @NotNull + @Override + public List getGroups() { + return groups; + } + } } 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 364d0caa2..1722d3ae5 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 @@ -12,6 +12,14 @@ */ public abstract class RelCorrelate extends RelBase { + /** + * @return new {@link RelCorrelate} instance + */ + @NotNull + public static RelCorrelate create(@NotNull Rel left, @NotNull Rel right, @NotNull JoinType joinType) { + return new Impl(left, right, joinType); + } + /** * @return the left input (child 0) */ @@ -45,4 +53,35 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitCorrelate(this, ctx); } + + private static class Impl extends RelCorrelate { + + private final Rel left; + private final Rel right; + private final JoinType joinType; + + public Impl(Rel left, Rel right, JoinType joinType) { + this.left = left; + this.right = right; + this.joinType = joinType; + } + + @NotNull + @Override + public Rel getLeft() { + return left; + } + + @NotNull + @Override + public Rel getRight() { + return right; + } + + @NotNull + @Override + public JoinType getJoinType() { + return joinType; + } + } } 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 d5119c340..14be950c4 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 @@ -11,6 +11,14 @@ */ public abstract class RelDistinct extends RelBase { + /** + * @return new {@link RelDistinct} instance + */ + @NotNull + public static RelDistinct create(@NotNull Rel input) { + return new Impl(input); + } + /** * @return input rel (child 0) */ @@ -34,4 +42,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitDistinct(this, ctx); } + + private static class Impl extends RelDistinct { + + private final Rel input; + + public Impl(Rel input) { + this.input = input; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + } } 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 9c22fa30c..8c3a8096a 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 @@ -12,9 +12,12 @@ public abstract class RelExcept extends RelBase { /** - * @return true if ALL else DISTINCT. + * @return new {@link RelExcept} instance */ - public abstract boolean isAll(); + @NotNull + public static RelExcept create(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } /** * @return left input (child 0) @@ -28,6 +31,11 @@ public abstract class RelExcept extends RelBase { @NotNull public abstract Rel getRight(); + /** + * @return true if ALL else DISTINCT. + */ + public abstract boolean isAll(); + @NotNull @Override protected final RelType type() { @@ -46,4 +54,34 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitExcept(this, ctx); } + + private static class Impl extends RelExcept { + + private final Rel left; + private final Rel right; + private final boolean all; + + public Impl(Rel left, Rel right, boolean all) { + this.left = left; + this.right = right; + this.all = all; + } + + @NotNull + @Override + public Rel getLeft() { + return left; + } + + @NotNull + @Override + public Rel getRight() { + return right; + } + + @Override + public boolean isAll() { + return all; + } + } } 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 9c8a9b004..a489a249b 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 @@ -12,6 +12,14 @@ */ public abstract class RelExclude extends RelBase { + /** + * @return new {@link RelExclude} instance + */ + @NotNull + public static RelExclude create(@NotNull Rel input, @NotNull List exclusions) { + return new Impl(input, exclusions); + } + /** * @return input rel (child 0) */ @@ -41,4 +49,28 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitExclude(this, ctx); } + + private static class Impl extends RelExclude { + + private final Rel input; + private final List exclusions; + + public Impl(Rel input, List exclusions) { + this.input = input; + this.exclusions = exclusions; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getExclusions() { + return exclusions; + } + } + } 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 2aa50813b..9834958c6 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 @@ -12,6 +12,14 @@ */ public abstract class RelFilter extends RelBase { + /** + * @return new {@link RelFilter} instance + */ + @NotNull + public static RelFilter create(@NotNull Rel input, @NotNull Rex predicate) { + return new Impl(input, predicate); + } + /** * @return input rel (child 0) */ @@ -42,4 +50,27 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitFilter(this, ctx); } + + private static class Impl extends RelFilter { + + private final Rel input; + private final Rex predicate; + + public Impl(Rel input, Rex predicate) { + this.input = input; + this.predicate = predicate; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getPredicate() { + return predicate; + } + } } 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 d5b15c4a5..47e26bd57 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 @@ -12,9 +12,12 @@ public abstract class RelIntersect extends RelBase { /** - * @return true if ALL else DISTINCT. + * @return new {@link RelIntersect} instance */ - public abstract boolean isAll(); + @NotNull + public static RelIntersect create(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } /** * @return left rel (child 0) @@ -28,6 +31,11 @@ public abstract class RelIntersect extends RelBase { @NotNull public abstract Rel getRight(); + /** + * @return true if ALL else DISTINCT. + */ + public abstract boolean isAll(); + @NotNull @Override protected final RelType type() { @@ -46,4 +54,34 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitIntersect(this, ctx); } + + private static class Impl extends RelIntersect { + + private final Rel left; + private final Rel right; + private final boolean all; + + public Impl(Rel left, Rel right, boolean all) { + this.left = left; + this.right = right; + this.all = all; + } + + @NotNull + @Override + public Rel getLeft() { + return left; + } + + @NotNull + @Override + public Rel getRight() { + return right; + } + + @Override + public boolean isAll() { + return all; + } + } } 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 067fc07c7..7c85bafdd 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 @@ -12,6 +12,14 @@ */ public abstract class RelIterate extends RelBase { + /** + * @return new {@link RelIterate} instance + */ + @NotNull + public static RelIterate create(@NotNull Rex rex) { + return new Impl(rex); + } + /** * @return input rex (child 0) */ @@ -35,4 +43,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitIterate(this, ctx); } + + private static class Impl extends RelIterate { + + private final Rex rex; + + public Impl(Rex rex) { + this.rex = rex; + } + + @NotNull + @Override + public Rex getRex() { + return rex; + } + } } 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 5b3384552..1447e985c 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 @@ -14,6 +14,14 @@ */ public abstract class RelJoin extends RelBase { + /** + * @return new {@link RelJoin} instance + */ + @NotNull + public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @Nullable Rex condition, @NotNull JoinType joinType) { + return new Impl(left, right, condition, joinType); + } + /** * @return left input (child 0) */ @@ -38,6 +46,11 @@ public abstract class RelJoin extends RelBase { @NotNull public abstract JoinType getJoinType(); + @Override + protected RelType type() { + throw new UnsupportedOperationException("compute join type"); + } + @NotNull @Override protected final List children() { @@ -51,4 +64,43 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitJoin(this, ctx); } + + private static class Impl extends RelJoin { + + private final Rel left; + private final Rel right; + private final Rex condition; + private final JoinType joinType; + + public Impl(Rel left, Rel right, Rex condition, JoinType joinType) { + this.left = left; + this.right = right; + this.condition = condition; + this.joinType = joinType; + } + + @NotNull + @Override + public Rel getLeft() { + return left; + } + + @NotNull + @Override + public Rel getRight() { + return right; + } + + @Nullable + @Override + public Rex getCondition() { + return condition; + } + + @NotNull + @Override + public JoinType getJoinType() { + return joinType; + } + } } 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 49d439c96..22475108f 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 @@ -12,6 +12,14 @@ */ public abstract class RelLimit extends RelBase { + /** + * @return new {@link RelLimit} instance + */ + @NotNull + public static RelLimit create(@NotNull Rel input, @NotNull Rex limit) { + return new Impl(input, limit); + } + /** * @return input rel (child 0) */ @@ -27,7 +35,7 @@ public abstract class RelLimit extends RelBase { @NotNull @Override protected final RelType type() { - throw new UnsupportedOperationException("Derive type is not implemented"); + return getInput().getType(); } @NotNull @@ -42,4 +50,27 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitLimit(this, ctx); } + + private static class Impl extends RelLimit { + + private final Rel input; + private final Rex limit; + + public Impl(Rel input, Rex limit) { + this.input = input; + this.limit = limit; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getLimit() { + return limit; + } + } } 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 4def97fcc..5cad94486 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 @@ -12,6 +12,14 @@ */ public abstract class RelOffset extends RelBase { + /** + * @return new {@link RelOffset} instance + */ + @NotNull + public static RelOffset create(@NotNull Rel input, @NotNull Rex offset) { + return new Impl(input, offset); + } + /** * @return input rel (child 0) */ @@ -27,7 +35,7 @@ public abstract class RelOffset extends RelBase { @NotNull @Override protected final RelType type() { - throw new UnsupportedOperationException("Derive type is not implemented"); + return getInput().getType(); } @NotNull @@ -42,5 +50,27 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitOffset(this, ctx); } -} + private static class Impl extends RelOffset { + + private final Rel input; + private final Rex offset; + + public Impl(Rel input, Rex offset) { + this.input = input; + this.offset = offset; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getOffset() { + return offset; + } + } +} 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 9fcba7add..591e56677 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 @@ -12,6 +12,14 @@ */ public abstract class RelProject extends RelBase { + /** + * @return new {@link RelProject} instance + */ + @NotNull + public static RelProject create(Rel input, List projections) { + return new Impl(input, projections); + } + /** * @return input rel (child 0) */ @@ -41,4 +49,27 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitProject(this, ctx); } + + private static class Impl extends RelProject { + + private final Rel input; + private final List projections; + + public Impl(Rel input, List projections) { + this.input = input; + this.projections = projections; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getProjections() { + return projections; + } + } } 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 e5e247415..6be7c2b16 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 @@ -12,6 +12,14 @@ */ public abstract class RelScan extends RelBase { + /** + * @return new {@link RelScan} instance + */ + @NotNull + public static RelScan create(@NotNull Rex rex) { + return new Impl(rex); + } + /** * @return input rex (child 0) */ @@ -35,4 +43,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitScan(this, ctx); } + + private static class Impl extends RelScan { + + private final Rex rex; + + public Impl(Rex rex) { + this.rex = rex; + } + + @NotNull + @Override + public Rex getRex() { + return rex; + } + } } 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 eecc771e2..f10eb8a5e 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 @@ -12,6 +12,14 @@ */ public abstract class RelSort extends RelBase { + /** + * @return new {@link RelSort} instance + */ + @NotNull + public static RelSort create(@NotNull Rel input, @NotNull List collations) { + return new Impl(input, collations); + } + @NotNull public abstract Rel getInput(); @@ -21,7 +29,7 @@ public abstract class RelSort extends RelBase { @NotNull @Override protected final RelType type() { - throw new UnsupportedOperationException("Derive type is not implemented"); + return getInput().getType(); } @NotNull @@ -35,4 +43,27 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitSort(this, ctx); } + + private static class Impl extends RelSort { + + private final Rel input; + private final List collations; + + public Impl(Rel input, List collations) { + this.input = input; + this.collations = collations; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getCollations() { + return collations; + } + } } 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 6305acab9..e60ac4215 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 @@ -11,6 +11,14 @@ */ public abstract class RelUnion extends RelBase { + /** + * @return new {@link RelUnion} instance + */ + @NotNull + public static RelUnion create(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } + /** * @return true if ALL else DISTINCT. */ @@ -46,4 +54,34 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitUnion(this, ctx); } + + private static class Impl extends RelUnion { + + private final Rel left; + private final Rel right; + private final boolean all; + + public Impl(Rel left, Rel right, boolean all) { + this.left = left; + this.right = right; + this.all = all; + } + + @Override + public boolean isAll() { + return all; + } + + @NotNull + @Override + public Rel getLeft() { + return left; + } + + @NotNull + @Override + public Rel getRight() { + return right; + } + } } 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 5e0ce16b2..45d12c452 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 @@ -12,6 +12,14 @@ */ public abstract class RelUnpivot extends RelBase { + /** + * @return new {@link RelUnpivot} instance + */ + @NotNull + public static RelUnpivot create(@NotNull Rex rex) { + return new Impl(rex); + } + /** * @return input rex (child 0) */ @@ -35,4 +43,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitUnpivot(this, ctx); } + + private static class Impl extends RelUnpivot { + + private final Rex rex; + + public Impl(Rex rex) { + this.rex = rex; + } + + @NotNull + @Override + public Rex getRex() { + return rex; + } + } } 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 3355c11c3..1baf206f8 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 @@ -12,6 +12,14 @@ */ public abstract class RexArray extends RexBase { + /** + * @return new RexArray instance + */ + @NotNull + public static RexArray create(@NotNull List values) { + return new Impl(values); + } + /** * @return the values of the array, also the children. */ @@ -35,4 +43,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitArray(this, ctx); } + + private static class Impl extends RexArray { + + private final List values; + + private Impl(List values) { + this.values = values; + } + + @NotNull + @Override + public List getValues() { + return values; + } + } } 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 38f328557..a4797dbbc 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 @@ -12,6 +12,14 @@ */ public abstract class RexBag extends RexBase { + /** + * @return new RexBag instance + */ + @NotNull + public static RexBag create(@NotNull List values) { + return new Impl(values); + } + /** * @return the values of the array, also the children. */ @@ -35,4 +43,19 @@ protected final List children() { public R accept(@NotNull Visitor visitor, C ctx) { return visitor.visitBag(this, ctx); } + + private static class Impl extends RexBag { + + private final List values; + + private Impl(List values) { + this.values = values; + } + + @NotNull + @Override + public List getValues() { + return values; + } + } } 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 230a5bd58..ce1eb0e44 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 @@ -12,6 +12,11 @@ */ public abstract class RexCall extends RexBase { + @NotNull + public static RexCall create(@NotNull Function.Instance function, @NotNull List args) { + return new Impl(function, args); + } + /** * Returns the function to invoke. */ @@ -39,5 +44,28 @@ protected List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitCall(this, ctx); } + + private static class Impl extends RexCall { + + private final Function.Instance function; + private final List args; + + private Impl(Function.Instance function, List args) { + this.function = function; + this.args = args; + } + + @NotNull + @Override + public Function.Instance getFunction() { + return function; + } + + @NotNull + @Override + public List getArgs() { + return args; + } + } } 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 4d1a8dba8..2258a0ce6 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 @@ -12,6 +12,11 @@ */ public abstract class RexCase extends RexBase { + @NotNull + public static RexCase create(@Nullable Rex match, @NotNull List branches, @Nullable Rex def) { + return new Impl(match, branches, def); + } + /** * @return the match expression, or {@code null} if none (child 0) */ @@ -74,4 +79,34 @@ public Rex getResult() { return result; } } + + private static class Impl extends RexCase { + private final Rex match; + private final List branches; + private final Rex def; + + private Impl(Rex match, List branches, Rex def) { + this.match = match; + this.branches = branches; + this.def = def; + } + + @Nullable + @Override + public Rex getMatch() { + return match; + } + + @NotNull + @Override + public List getBranches() { + return branches; + } + + @Nullable + @Override + public Rex getDefault() { + return def; + } + } } 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 843b9e217..c775ea870 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,14 +1,25 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.types.PType; +import java.util.List; + /** * Logical cast expression abstract base class. */ public abstract class RexCast extends RexBase { + /** + * @return new RexCast instance + */ + @NotNull + public static RexCast create(@NotNull Rex operand, @NotNull PType target) { + return new Impl(operand, target); + } + /** * @return operand rex (child 0) */ @@ -26,8 +37,35 @@ protected final RexType type() { return new RexType(getTarget()); } + @Override + protected List children() { + return List.of(); + } + @Override public R accept(Visitor visitor, C ctx) { return visitor.visitCast(this, ctx); } + + private static class Impl extends RexCast { + private final Rex operand; + private final PType target; + + private Impl(@NotNull Rex operand, @NotNull PType target) { + this.operand = operand; + this.target = target; + } + + @NotNull + @Override + public Rex getOperand() { + return operand; + } + + @NotNull + @Override + public PType getTarget() { + return target; + } + } } 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 db5e8e25d..dc91dcc65 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 @@ -11,6 +11,14 @@ */ public abstract class RexCoalesce extends RexBase { + /** + * @return new RexCoalesce instance + */ + @NotNull + public static RexCoalesce create(List args) { + return new Impl(args); + } + /** * @return the list of arguments (also the children). */ @@ -32,4 +40,19 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitCoalesce(this, ctx); } + + private static class Impl extends RexCoalesce { + + private final List args; + + private Impl(List args) { + this.args = args; + } + + @NotNull + @Override + public List getArgs() { + return args; + } + } } 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 0f37829f0..c83be1a5f 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 @@ -12,6 +12,14 @@ */ public abstract class RexDispatch extends RexBase { + /** + * @return new RexDispatch instance + */ + @NotNull + public static RexDispatch create(String name, List functions, List args) { + return new Impl(name, functions, args); + } + /** * Dynamic function name. */ @@ -43,4 +51,32 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitCallDynamic(this, ctx); } + + private static class Impl extends RexDispatch { + + private final String name; + private final List functions; + private final List args; + + private Impl(String name, List functions, List args) { + this.name = name; + this.functions = functions; + this.args = args; + } + + @Override + public String getName() { + return name; + } + + @Override + public List getFunctions() { + return functions; + } + + @Override + public List getArgs() { + return args; + } + } } 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 adb28ee8b..9d000eeca 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,5 +1,6 @@ package org.partiql.plan.rex; +import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.types.PType; @@ -12,6 +13,14 @@ */ public abstract class RexError extends RexBase { + /** + * @return new RexError instance + */ + @NotNull + public static RexError create() { + return new Impl(); + } + @Override protected RexType type() { return new RexType(PType.unknown()); @@ -26,4 +35,8 @@ protected List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitError(this, ctx); } + + private static class Impl extends RexError { + // empty + } } 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 3af906727..011faac30 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 @@ -12,6 +12,14 @@ */ public abstract class RexLit extends RexBase { + /** + * @return new RexLit instance + */ + @NotNull + public static RexLit create(@NotNull Datum value) { + return new Impl(value); + } + @NotNull public abstract Datum getDatum(); @@ -30,4 +38,19 @@ protected List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitLit(this, ctx); } + + private static class Impl extends RexLit { + + private final Datum value; + + private Impl(Datum value) { + this.value = value; + } + + @NotNull + @Override + public Datum getDatum() { + return value; + } + } } 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 8ef173582..5356c7391 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 @@ -11,6 +11,14 @@ */ public abstract class RexNullIf extends RexBase { + /** + * @return new RexNullIf instance + */ + @NotNull + public static RexNullIf create(@NotNull Rex v1, @NotNull Rex v2) { + return new Impl(v1, v2); + } + /** * @return v1 rex (child 0) */ @@ -40,4 +48,27 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitNullIf(this, ctx); } + + private static class Impl extends RexNullIf { + + private final Rex v1; + private final Rex v2; + + private Impl(Rex v1, Rex v2) { + this.v1 = v1; + this.v2 = v2; + } + + @NotNull + @Override + public Rex getV1() { + return v1; + } + + @NotNull + @Override + public Rex getV2() { + return v2; + } + } } 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 67d0eaeea..24af36e1e 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 @@ -11,6 +11,14 @@ */ public abstract class RexPathIndex extends RexBase { + /** + * @return new RexPathIndex instance + */ + @NotNull + public static RexPathIndex create(@NotNull Rex operand, @NotNull Rex index) { + return new Impl(operand, index); + } + /** * @return operand rex (child 0) */ @@ -39,4 +47,27 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitPathIndex(this, ctx); } + + private static class Impl extends RexPathIndex { + + private final Rex operand; + private final Rex index; + + private Impl(@NotNull Rex operand, @NotNull Rex index) { + this.operand = operand; + this.index = index; + } + + @NotNull + @Override + public Rex getOperand() { + return operand; + } + + @NotNull + @Override + public Rex getIndex() { + return index; + } + } } 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 03555a7e0..ec1ff61dc 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 @@ -11,6 +11,14 @@ */ public abstract class RexPathKey extends RexBase { + /** + * @return new RexPathKey instance + */ + @NotNull + public static RexPathKey create(@NotNull Rex operand, @NotNull Rex key) { + return new Impl(operand, key); + } + /** * @return operand rex (child 0) */ @@ -40,4 +48,27 @@ protected List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitPathKey(this, ctx); } + + private static class Impl extends RexPathKey { + + private final Rex operand; + private final Rex key; + + private Impl(@NotNull Rex operand, @NotNull Rex key) { + this.operand = operand; + this.key = key; + } + + @NotNull + @Override + public Rex getOperand() { + return operand; + } + + @NotNull + @Override + public Rex getKey() { + return key; + } + } } 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 0d8521986..89a48f713 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 @@ -11,6 +11,14 @@ */ public abstract class RexPathSymbol extends RexBase { + /** + * @return new RexPathSymbol instance + */ + @NotNull + public static RexPathSymbol create(@NotNull Rex operand, @NotNull String symbol) { + return new Impl(operand, symbol); + } + /** * @return operand rex (child 0) */ @@ -39,4 +47,27 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitPathSymbol(this, ctx); } + + private static class Impl extends RexPathSymbol { + + private final Rex operand; + private final String symbol; + + private Impl(@NotNull Rex operand, @NotNull String symbol) { + this.operand = operand; + this.symbol = symbol; + } + + @NotNull + @Override + public Rex getOperand() { + return operand; + } + + @NotNull + @Override + public String getSymbol() { + return symbol; + } + } } 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 b1eaa24b2..97806a21e 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 @@ -13,6 +13,14 @@ */ public abstract class RexPivot extends RexBase { + /** + * @return new RexPivot instance + */ + @NotNull + public static RexPivot create(@NotNull Rel input, @NotNull Rex key, @NotNull Rex value) { + return new Impl(input, key, value); + } + /** * @return input rel (child 0) */ @@ -49,4 +57,35 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitPivot(this, ctx); } + + private static class Impl extends RexPivot { + + private final Rel input; + private final Rex key; + private final Rex value; + + private Impl(Rel input, Rex key, Rex value) { + this.input = input; + this.key = key; + this.value = value; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getKey() { + return key; + } + + @NotNull + @Override + public Rex getValue() { + return value; + } + } } 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 50f529cc1..52636adfb 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 @@ -13,6 +13,14 @@ */ public abstract class RexSelect extends RexBase { + /** + * @return new RexSelect instance + */ + @NotNull + public static RexSelect create(@NotNull Rel input, @NotNull Rex constructor) { + return new Impl(input, constructor); + } + /** * @return input rel (child 0) */ @@ -42,4 +50,27 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitSelect(this, ctx); } + + private static class Impl extends RexSelect { + + private final Rel input; + private final Rex constructor; + + private Impl(Rel input, Rex constructor) { + this.input = input; + this.constructor = constructor; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getConstructor() { + return constructor; + } + } } 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 547495bb0..57ca437ef 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 @@ -12,6 +12,14 @@ */ public abstract class RexSpread extends RexBase { + /** + * @return new RexSpread instance + */ + @NotNull + public static RexSpread create(@NotNull List args) { + return new Impl(args); + } + /** * @return list of spread arguments (the children) */ @@ -33,4 +41,18 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitSpread(this, ctx); } + + private static class Impl extends RexSpread { + + private final List args; + + private Impl(List args) { + this.args = args; + } + + @Override + public List getArgs() { + return args; + } + } } 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 1f9ee7157..d70696ec2 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 @@ -12,9 +12,26 @@ */ public abstract class RexStruct extends RexBase { + /** + * @return new RexStruct instance + */ + @NotNull + public static RexStruct create(@NotNull List fields) { + return new Impl(fields); + } + + /** + * @return a field constructor instance + */ + @NotNull + public static Field field(Rex key, Rex value) { + return new Field(key, value); + } + /** * @return list of struct fields (NOT children) */ + @NotNull public abstract List getFields(); @NotNull @@ -41,7 +58,7 @@ public static class Field { private final Rex key; private final Rex value; - public Field(Rex key, Rex value) { + private Field(Rex key, Rex value) { this.key = key; this.value = value; } @@ -54,4 +71,20 @@ public Rex getValue() { return value; } } + + private static class Impl extends RexStruct { + + @NotNull + private final List fields; + + private Impl(@NotNull List fields) { + this.fields = fields; + } + + @Override + @NotNull + public List getFields() { + return fields; + } + } } 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 c91b14865..a6e349f31 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 @@ -12,6 +12,14 @@ */ public abstract class RexSubquery extends RexBase { + /** + * @return new RexSubquery instance + */ + @NotNull + public static RexSubquery create(@NotNull Rel input, @NotNull Rex constructor, boolean scalar) { + return new Impl(input, constructor, scalar); + } + /** * @return input rel (child 0) */ @@ -19,10 +27,11 @@ public abstract class RexSubquery extends RexBase { public abstract Rel getInput(); // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES + @NotNull public abstract Rex getConstructor(); // TODO REMOVE ME – TEMPORARY UNTIL PLANNER PROPERLY HANDLES SUBQUERIES - public abstract boolean asScalar(); + public abstract boolean isScalar(); @NotNull @Override @@ -40,4 +49,34 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitSubquery(this, ctx); } -} \ No newline at end of file + + private static class Impl extends RexSubquery { + + private final Rel input; + private final Rex constructor; + private final boolean scalar; + + private Impl(Rel input, Rex constructor, boolean scalar) { + this.input = input; + this.constructor = constructor; + this.scalar = scalar; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Rex getConstructor() { + return constructor; + } + + @Override + public boolean isScalar() { + return scalar; + } + } +} 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 2f907b78b..3cfcef706 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,6 +1,7 @@ package org.partiql.plan.rex; import org.jetbrains.annotations.NotNull; +import org.partiql.plan.Operator; import org.partiql.plan.Visitor; import org.partiql.plan.rel.Rel; import org.partiql.spi.Enum; @@ -15,6 +16,19 @@ */ public abstract class RexSubqueryComp extends RexBase { + /** + * @return new RexSubqueryComp instance + */ + @NotNull + public static RexSubqueryComp create( + @NotNull Rel input, + @NotNull List args, + @NotNull Comparison comparison, + @NotNull Quantifier quantifier + ) { + return new Impl(input, args, comparison, quantifier); + } + /** * @return input rel (child 0) */ @@ -45,6 +59,12 @@ protected final RexType type() { return new RexType(PType.bool()); } + @Override + protected final List children() { + Rel c0 = getInput(); + return List.of(c0); + } + @Override public R accept(Visitor visitor, C ctx) { return visitor.visitSubqueryComp(this, ctx); @@ -127,4 +147,43 @@ public static Quantifier SOME() { return new Quantifier(SOME); } } + + private static class Impl extends RexSubqueryComp { + + private final Rel input; + private final List args; + private final Comparison comparison; + private final Quantifier quantifier; + + private Impl(Rel input, List args, Comparison comparison, Quantifier quantifier) { + this.input = input; + this.args = args; + this.comparison = comparison; + this.quantifier = quantifier; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getArgs() { + return args; + } + + @NotNull + @Override + public Comparison getComparison() { + return comparison; + } + + @NotNull + @Override + public Quantifier getQuantifier() { + return quantifier; + } + } } 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 bdc1a77ef..d4cbf67ac 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 @@ -13,6 +13,14 @@ */ public abstract class RexSubqueryIn extends RexBase { + /** + * @return new RexSubqueryIn instance + */ + @NotNull + public static RexSubqueryIn create(@NotNull Rel input, @NotNull List args) { + return new Impl(input, args); + } + /** * @return input rel (child 0) */ @@ -31,7 +39,7 @@ protected final RexType type() { } @Override - protected List children() { + protected final List children() { Rel c0 = getInput(); return List.of(c0); } @@ -40,4 +48,27 @@ protected List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitSubqueryIn(this, ctx); } + + private static class Impl extends RexSubqueryIn { + + private final Rel input; + private final List args; + + private Impl(Rel input, List args) { + this.input = input; + this.args = args; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public List getArgs() { + return args; + } + } } 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 642ee71c4..a25259347 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 @@ -19,6 +19,14 @@ */ public abstract class RexSubqueryTest extends RexBase { + /** + * @return new RexSubqueryTest instance + */ + @NotNull + public static RexSubqueryTest create(@NotNull Rel input, @NotNull Test test) { + return new Impl(input, test); + } + /** * @return input rel (child 0) */ @@ -53,7 +61,7 @@ public R accept(Visitor visitor, C ctx) { */ public static class Test extends Enum { - public static final int UKNOWNN = 0; + public static final int UNKNOWN = 0; public static final int EXISTS = 1; public static final int UNIQUE = 2; @@ -71,4 +79,27 @@ public static Test UNIQUE() { return new Test(UNIQUE); } } + + private static class Impl extends RexSubqueryTest { + + private final Rel input; + private final Test test; + + private Impl(Rel input, Test test) { + this.input = input; + this.test = test; + } + + @NotNull + @Override + public Rel getInput() { + return input; + } + + @NotNull + @Override + public Test getTest() { + return test; + } + } } 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 d28d37d42..0c25ffbaf 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 @@ -12,6 +12,14 @@ */ public abstract class RexTable extends RexBase { + /** + * @return new RexTable instance + */ + @NotNull + public static RexTable create(@NotNull Table table) { + return new Impl(table); + } + /** * @return the table implementation. */ @@ -32,4 +40,18 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitTable(this, ctx); } -} \ No newline at end of file + + private static class Impl extends RexTable { + + private final Table table; + + private Impl(Table table) { + this.table = table; + } + + @Override + public Table getTable() { + return table; + } + } +} 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 c1d4a77b2..c6904d623 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 @@ -11,6 +11,14 @@ */ public abstract class RexVar extends RexBase { + /** + * @return new variable reference expression. + */ + @NotNull + public static RexVar create(int depth, int offset) { + return new Impl(depth, offset); + } + /** * @return 0-indexed scope offset. */ @@ -37,4 +45,25 @@ protected final List children() { public R accept(Visitor visitor, C ctx) { return visitor.visitVar(this, ctx); } + + private static class Impl extends RexVar { + + private final int depth; + private final int offset; + + private Impl(int depth, int offset) { + this.depth = depth; + this.offset = offset; + } + + @Override + public int getDepth() { + return depth; + } + + @Override + public int getOffset() { + return offset; + } + } } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt index 2fe7291b6..81afdbc87 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt @@ -1,10 +1,10 @@ package org.partiql.plan.builder -import org.partiql.plan.AggregateCall import org.partiql.plan.Collation import org.partiql.plan.Exclusion import org.partiql.plan.JoinType import org.partiql.plan.rel.Rel +import org.partiql.plan.rel.RelAggregate /** * DataFrame style fluent-builder for PartiQL logical plans. @@ -64,13 +64,13 @@ public class RelBuilder private constructor(builder: Builder) { * Appends a RelAggregate to the current operator builder. */ public fun aggregate( - calls: List, + measures: List, groups: List, ): RelBuilder = RelBuilder { val _input = self.build(it) - val _calls = calls // TODO calls needs to be builder + val _measures = measures val _groups = groups.map { group -> group.build(it) } - it.relAggregate(_input, _calls, _groups) + it.relAggregate(_input, _measures, _groups) } public fun distinct(): RelBuilder = RelBuilder { @@ -115,7 +115,7 @@ public class RelBuilder private constructor(builder: Builder) { /** * Appends a RelJoin to the current operator builder for LATERAL CROSS JOIN. */ - public fun join(rhs: RelBuilder): RelBuilder = join(rhs, null, JoinType.INNER) + public fun join(rhs: RelBuilder): RelBuilder = join(rhs, null, JoinType.INNER()) /** * Appends a RelJoin to the current operator builder for INNER JOIN ON . @@ -127,7 +127,7 @@ public class RelBuilder private constructor(builder: Builder) { public fun join( rhs: RelBuilder, condition: RexBuilder, - ): RelBuilder = join(rhs, condition, JoinType.INNER) + ): RelBuilder = join(rhs, condition, JoinType.INNER()) /** * Appends a RelJoin to the current operator builder for [LEFT|RIGHT|INNER|FULL] JOIN. From 571f978e4cf9e637cc31fd9628e62109fdd642b8 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 2 Dec 2024 09:48:45 -0800 Subject: [PATCH 06/19] Updates standard operator factory; removes builders --- .../main/java/org/partiql/plan/Collation.java | 3 +- .../org/partiql/plan/rel/RelCorrelate.java | 5 +- .../java/org/partiql/plan/rel/RelJoin.java | 33 +- .../java/org/partiql/plan/rex/RexBag.java | 15 +- .../java/org/partiql/plan/rex/RexVar.java | 21 +- .../org/partiql/plan/builder/Operators.kt | 448 +++++++++++ .../org/partiql/plan/builder/PlanFactory.kt | 695 ------------------ .../org/partiql/plan/builder/RelBuilder.kt | 240 ------ .../org/partiql/plan/builder/RexBuilder.kt | 203 ----- .../partiql/planner/internal/SqlPlanner.kt | 4 +- .../internal/transforms/PlanTransform.kt | 2 +- .../internal/exclude/SubsumptionTest.kt | 4 +- 12 files changed, 493 insertions(+), 1180 deletions(-) create mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt delete mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/builder/RexBuilder.kt diff --git a/partiql-plan/src/main/java/org/partiql/plan/Collation.java b/partiql-plan/src/main/java/org/partiql/plan/Collation.java index ee68494b1..f1006b62c 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Collation.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Collation.java @@ -12,8 +12,7 @@ public interface Collation { /** * API WARNING – THIS WILL BE REPLACED WITH AN `int` IN 1.0. *
- * TODO replace with an `int` in 1.0 - * TODO ... + * TODO replace with an `int` in 1.0 * * @return the column to sort by */ 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 1722d3ae5..e529a4f56 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 @@ -8,7 +8,10 @@ import java.util.List; /** - * Logical nested-loop joins (correlated subqueries // lateral joins) abstract base class. + * Logical nested-loop joins (correlated subqueries, lateral joins, and cross joins) abstract base class. + *

+ *     l, r <=> l CROSS JOIN r <=> l JOIN r ON TRUE
+ * 
*/ public abstract class RelCorrelate extends RelBase { 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 1447e985c..857475ed3 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 @@ -1,7 +1,6 @@ package org.partiql.plan.rel; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.partiql.plan.JoinType; import org.partiql.plan.Operator; import org.partiql.plan.Visitor; @@ -10,7 +9,7 @@ import java.util.List; /** - * Logical join abstract base class. + * Logical theta-join abstract base class. */ public abstract class RelJoin extends RelBase { @@ -18,8 +17,8 @@ public abstract class RelJoin extends RelBase { * @return new {@link RelJoin} instance */ @NotNull - public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @Nullable Rex condition, @NotNull JoinType joinType) { - return new Impl(left, right, condition, joinType); + public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull JoinType joinType, @NotNull Rex condition) { + return new Impl(left, right, joinType, condition); } /** @@ -35,16 +34,16 @@ public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @Nullable Re public abstract Rel getRight(); /** - * @return the join condition (child 2), or null if there is no condition. + * @return JoinType */ - @Nullable - public abstract Rex getCondition(); + @NotNull + public abstract JoinType getJoinType(); /** - * @return JoinType + * @return the join condition (child 2), or null if there is no condition. */ @NotNull - public abstract JoinType getJoinType(); + public abstract Rex getCondition(); @Override protected RelType type() { @@ -69,14 +68,14 @@ private static class Impl extends RelJoin { private final Rel left; private final Rel right; - private final Rex condition; private final JoinType joinType; + private final Rex condition; - public Impl(Rel left, Rel right, Rex condition, JoinType joinType) { + public Impl(Rel left, Rel right, JoinType joinType, Rex condition) { this.left = left; this.right = right; - this.condition = condition; this.joinType = joinType; + this.condition = condition; } @NotNull @@ -91,16 +90,16 @@ public Rel getRight() { return right; } - @Nullable + @NotNull @Override - public Rex getCondition() { - return condition; + public JoinType getJoinType() { + return joinType; } @NotNull @Override - public JoinType getJoinType() { - return joinType; + public Rex getCondition() { + return condition; } } } 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 a4797dbbc..4600545e0 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 @@ -5,6 +5,7 @@ import org.partiql.plan.Visitor; import org.partiql.types.PType; +import java.util.Collection; import java.util.List; /** @@ -16,15 +17,15 @@ public abstract class RexBag extends RexBase { * @return new RexBag instance */ @NotNull - public static RexBag create(@NotNull List values) { + public static RexBag create(@NotNull Collection values) { return new Impl(values); } /** - * @return the values of the array, also the children. + * @return the values of the bag, also the children (unordered). */ @NotNull - public abstract List getValues(); + public abstract Collection getValues(); @NotNull @Override @@ -35,7 +36,7 @@ protected final RexType type() { @NotNull @Override protected final List children() { - List varargs = getValues(); + List varargs = getValues().stream().toList(); return List.copyOf(varargs); } @@ -46,15 +47,15 @@ public R accept(@NotNull Visitor visitor, C ctx) { private static class Impl extends RexBag { - private final List values; + private final Collection values; - private Impl(List values) { + private Impl(Collection values) { this.values = values; } @NotNull @Override - public List getValues() { + public Collection getValues() { return values; } } 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 c6904d623..dd0f172a9 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 @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; import org.partiql.plan.Visitor; +import org.partiql.types.PType; import java.util.List; @@ -15,8 +16,8 @@ public abstract class RexVar extends RexBase { * @return new variable reference expression. */ @NotNull - public static RexVar create(int depth, int offset) { - return new Impl(depth, offset); + public static RexVar create(int depth, int offset, PType type) { + return new Impl(depth, offset, type); } /** @@ -29,13 +30,6 @@ public static RexVar create(int depth, int offset) { */ public abstract int getOffset(); - @NotNull - @Override - protected final RexType type() { - // would need to lookup in context - throw new UnsupportedOperationException("Derive type is not implemented"); - } - @Override protected final List children() { return List.of(); @@ -50,10 +44,17 @@ private static class Impl extends RexVar { private final int depth; private final int offset; + private final PType type; - private Impl(int depth, int offset) { + private Impl(int depth, int offset, PType type) { this.depth = depth; this.offset = offset; + this.type = type; + } + + @Override + protected RexType type() { + return new RexType(type); } @Override diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt new file mode 100644 index 000000000..8ec09e96f --- /dev/null +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt @@ -0,0 +1,448 @@ +package org.partiql.plan.builder + +import org.partiql.plan.Collation +import org.partiql.plan.Exclusion +import org.partiql.plan.JoinType +import org.partiql.plan.rel.Rel +import org.partiql.plan.rel.RelAggregate +import org.partiql.plan.rel.RelAggregate.Measure +import org.partiql.plan.rel.RelCorrelate +import org.partiql.plan.rel.RelDistinct +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.Rex +import org.partiql.plan.rex.RexArray +import org.partiql.plan.rex.RexBag +import org.partiql.plan.rex.RexCall +import org.partiql.plan.rex.RexCase +import org.partiql.plan.rex.RexCast +import org.partiql.plan.rex.RexCoalesce +import org.partiql.plan.rex.RexDispatch +import org.partiql.plan.rex.RexError +import org.partiql.plan.rex.RexLit +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 +import org.partiql.spi.catalog.Table +import org.partiql.spi.function.Function +import org.partiql.spi.value.Datum +import org.partiql.types.PType + +/** + * The [Operators] interface is a factory to instantiate operator implementations. + * + * There is only ONE factory method per operators – i.e. no overloads or defaults. + */ +public interface Operators { + + // ALL MEMBERS SHOULD BE @JvmStatic + public companion object { + + /** + * A singleton of the [Operators] with all the standard implementations. + */ + @JvmStatic + public val STANDARD: Operators = object : Operators {} + } + + // --- REL OPERATORS ----------------------------------------------------------------------------------------------- + + /** + * Create a [RelAggregate] instance. + * + * @param input + * @param measures + * @param groups + * + * @param input + */ + public fun relAggregate( + input: Rel, + measures: List, + groups: List, + ): RelAggregate = RelAggregate.create(input, measures, groups) + + /** + * Create a [RelCorrelate] instance for a lateral join or correlated subquery. + * + * @param lhs + * @param rhs + * @param joinType + * @return + */ + public fun relCorrelate( + lhs: Rel, + rhs: Rel, + joinType: JoinType, + ): RelCorrelate = RelCorrelate.create(lhs, rhs, joinType) + + /** + * Create a [RelDistinct] instance. + * + * @param input + * @return + */ + public fun relDistinct(input: Rel): RelDistinct = RelDistinct.create(input) + + /** + * Create a [RelExcept] instance for EXCEPT [ALL|DISTINCT]. + * + * @param lhs + * @param rhs + * @return + */ + public fun relExcept( + lhs: Rel, + rhs: Rel, + all: Boolean, + ): RelExcept = RelExcept.create(lhs, rhs, all) + + /** + * Create a [RelExclude] instance. + * + * @param input + * @param exclusions + * @return + */ + public fun relExclude(input: Rel, exclusions: List): RelExclude = RelExclude.create(input, exclusions) + + /** + * Create a [RelFilter] instance. + * + * @param input + * @param predicate + * @return + */ + public fun relFilter(input: Rel, predicate: Rex): RelFilter = RelFilter.create(input, predicate) + + /** + * Create a [RelIntersect] instance for INTERSECT [ALL|DISTINCT]. + * + * @param lhs + * @param rhs + * @param all + * @return + */ + public fun relIntersect( + lhs: Rel, + rhs: Rel, + all: Boolean, + ): RelIntersect = RelIntersect.create(lhs, rhs, all) + + /** + * Create a [RelIterate] instance. + * + * @param rex + * @return + */ + public fun relIterate(rex: Rex): RelIterate = RelIterate.create(rex) + + /** + * Create a [RelJoin] instance. + * + * @param lhs + * @param rhs + * @param condition + * @param type + * @return + */ + public fun relJoin( + lhs: Rel, + rhs: Rel, + type: JoinType, + condition: Rex, + ): RelJoin = RelJoin.create(lhs, rhs, type, condition) + + /** + * Create a [RelLimit] instance. + * + * @param input + * @param limit + * @return + */ + public fun relLimit(input: Rel, limit: Rex): RelLimit = RelLimit.create(input, limit) + + /** + * Create a [RelLimit] instance. + * + * @param input + * @param offset + * @return + */ + public fun relOffset(input: Rel, offset: Rex): RelOffset = RelOffset.create(input, offset) + + /** + * Create a [RelProject] instance. + * + * @param input + * @param projections + * @return + */ + public fun relProject(input: Rel, projections: List): RelProject = RelProject.create(input, projections) + + /** + * Create a [RelScan] instance. + * + * @param rex + * @return + */ + public fun relScan(rex: Rex): RelScan = RelScan.create(rex) + + /** + * Create a [RelSort] instance. + * + * @param input + * @param collations + * @return + */ + public fun relSort(input: Rel, collations: List): RelSort = RelSort.create(input, collations) + + /** + * Create a [RelUnion] instance for UNION [ALL|DISTINCT]. + * + * @param lhs + * @param rhs + * @return + */ + public fun relUnion(lhs: Rel, rhs: Rel, all: Boolean): RelUnion = RelUnion.create(lhs, rhs, all) + + /** + * Create a [RelUnpivot] instance. + * + * @param input + * @return + */ + public fun relUnpivot(input: Rex): RelUnpivot = RelUnpivot.create(input) + + // --- REX OPERATORS ----------------------------------------------------------------------------------------------- + + /** + * Create a [RexArray] instance. + * + * @param values + * @return + */ + public fun rexArray(values: List): RexArray = RexArray.create(values) + + /** + * Create a [RexBag] instance. + * + * @param values + * @return + */ + public fun rexBag(values: Collection): RexBag = RexBag.create(values) + + /** + * Create a [RexCall] instance. + * + * @param function + * @param args + * @return + */ + public fun rexCall(function: Function.Instance, args: List): RexCall = RexCall.create(function, args) + + /** + * Create a [RexCase] instance for a case-when with dynamic type. + * + * @param match + * @param branches + * @param default + * @return + */ + public fun rexCase(match: Rex?, branches: List, default: Rex?): RexCase = + RexCase.create(match, branches, default) + + /** + * Create a [RexCast] instance. + * + * @param operand + * @param target + * @return + */ + public fun rexCast(operand: Rex, target: PType): RexCast = RexCast.create(operand, target) + + /** + * Create a [RexCoalesce] instance. + * + * @param args + * @return + */ + public fun rexCoalesce(args: List): RexCoalesce = RexCoalesce.create(args) + + /** + * Create a [RexDispatch] instance. + * + * @param name + * @param functions + * @param args + * @return + */ + public fun rexDispatch(name: String, functions: List, args: List): RexDispatch = + RexDispatch.create(name, functions, args) + + /** + * Create a [RexError] instance. + */ + public fun rexError(type: PType): RexError = RexError.create() + + /** + * Create a [RexLit] instance. + * + * @param value + * @return + */ + public fun rexLit(value: Datum): RexLit = RexLit.create(value) + + /** + * Create a [RexNullIf] instance. + */ + public fun rexNullIf(v1: Rex, v2: Rex): RexNullIf = RexNullIf.create(v1, v2) + + /** + * Create a [RexPathIndex] instance. + * + * @param operand + * @param index + * @return + */ + public fun rexPathIndex(operand: Rex, index: Rex): RexPathIndex = RexPathIndex.create(operand, index) + + /** + * Create a [RexPathKey] instance. + * + * @param operand + * @param key + * @return + */ + public fun rexPathKey(operand: Rex, key: Rex): RexPathKey = RexPathKey.create(operand, key) + + /** + * Create a [RexPathSymbol] instance. + * + * @param operand + * @param symbol + * @return + */ + public fun rexPathSymbol(operand: Rex, symbol: String): RexPathSymbol = RexPathSymbol.create(operand, symbol) + + /** + * Create a [RexPivot] instance. + * + * @param input + * @param key + * @param value + * @return + */ + public fun rexPivot(input: Rel, key: Rex, value: Rex): RexPivot = RexPivot.create(input, key, value) + + /** + * Create a [RexSelect] instance. + * + * @param input + * @param constructor + * @return + */ + public fun rexSelect(input: Rel, constructor: Rex): RexSelect = RexSelect.create(input, constructor) + + /** + * Create a [RexSpread] instance with open struct type. + * + * @param args + * @return + */ + public fun rexSpread(args: List): RexSpread = RexSpread.create(args) + + /** + * Create a [RexStruct] instance. + * + * @param fields + * @return + */ + public fun rexStruct(fields: List): RexStruct = RexStruct.create(fields) + + /** + * Create a [RexSubquery] instance. + * + * TODO REMOVE constructor AND scalar – TEMPORARY UNTIL SUBQUERIES ARE FIXED IN THE PLANNER. + * + * @param input + * @return + */ + public fun rexSubquery(input: Rel, constructor: Rex, scalar: Boolean): RexSubquery = + RexSubquery.create(input, constructor, scalar) + + /** + * Create a [RexSubqueryComp] instance. + * + * @param input + * @param args + * @param comparison + * @param quantifier + * @return + */ + public fun rexSubqueryComp( + input: Rel, + args: List, + comparison: RexSubqueryComp.Comparison, + quantifier: RexSubqueryComp.Quantifier, + ): RexSubqueryComp = RexSubqueryComp.create(input, args, comparison, quantifier) + + /** + * Create a [RexSubqueryIn] instance for a list argument. + * + * @param input + * @param args + * @return + */ + public fun rexSubqueryIn(input: Rel, args: List): RexSubqueryIn = RexSubqueryIn.create(input, args) + + /** + * Create a [RexSubqueryTest] instance. + * + * @param input + * @param test + * @return + */ + public fun rexSubqueryTest(input: Rel, test: RexSubqueryTest.Test): RexSubqueryTest = + RexSubqueryTest.create(input, test) + + /** + * Create a [RexTable] instance. + * + * @param table + * @return + */ + public fun rexTable(table: Table): RexTable = RexTable.create(table) + + /** + * Create a [RexVar] instance (requires a type). + * + * @param depth + * @param offset + * @param type + * @return + */ + public fun rexVar(depth: Int, offset: Int, type: PType): RexVar = RexVar.create(depth, offset, type) +} 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 deleted file mode 100644 index 3fffc7faf..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/PlanFactory.kt +++ /dev/null @@ -1,695 +0,0 @@ -package org.partiql.plan.builder - -import org.partiql.plan.AggregateCall -import org.partiql.plan.Collation -import org.partiql.plan.Exclusion -import org.partiql.plan.JoinType -import org.partiql.plan.RelAggregateCallImpl -import org.partiql.plan.rel.Rel -import org.partiql.plan.rel.RelAggregate -import org.partiql.plan.impl.RelAggregateImpl -import org.partiql.plan.rel.RelCorrelate -import org.partiql.plan.impl.RelCorrelateImpl -import org.partiql.plan.rel.RelDistinct -import org.partiql.plan.impl.RelDistinctImpl -import org.partiql.plan.rel.RelExcept -import org.partiql.plan.impl.RelExceptImpl -import org.partiql.plan.rel.RelExclude -import org.partiql.plan.impl.RelExcludeImpl -import org.partiql.plan.rel.RelFilter -import org.partiql.plan.impl.RelFilterImpl -import org.partiql.plan.rel.RelIntersect -import org.partiql.plan.impl.RelIntersectImpl -import org.partiql.plan.rel.RelIterate -import org.partiql.plan.impl.RelIterateImpl -import org.partiql.plan.rel.RelJoin -import org.partiql.plan.impl.RelJoinImpl -import org.partiql.plan.rel.RelLimit -import org.partiql.plan.impl.RelLimitImpl -import org.partiql.plan.rel.RelOffset -import org.partiql.plan.impl.RelOffsetImpl -import org.partiql.plan.rel.RelProject -import org.partiql.plan.impl.RelProjectImpl -import org.partiql.plan.rel.RelScan -import org.partiql.plan.impl.RelScanImpl -import org.partiql.plan.rel.RelSort -import org.partiql.plan.impl.RelSortImpl -import org.partiql.plan.rel.RelType -import org.partiql.plan.rel.RelUnion -import org.partiql.plan.impl.RelUnionImpl -import org.partiql.plan.rel.RelUnpivot -import org.partiql.plan.impl.RelUnpivotImpl -import org.partiql.plan.rex.Rex -import org.partiql.plan.rex.RexArray -import org.partiql.plan.rex.RexArrayImpl -import org.partiql.plan.rex.RexBag -import org.partiql.plan.rex.RexBagImpl -import org.partiql.plan.rex.RexCall -import org.partiql.plan.rex.RexDispatch -import org.partiql.plan.rex.RexCallDynamicImpl -import org.partiql.plan.rex.RexCallImpl -import org.partiql.plan.rex.RexCase -import org.partiql.plan.rex.RexCaseImpl -import org.partiql.plan.rex.RexCast -import org.partiql.plan.rex.RexCastImpl -import org.partiql.plan.rex.RexCoalesce -import org.partiql.plan.rex.RexCoalesceImpl -import org.partiql.plan.rex.RexError -import org.partiql.plan.rex.RexErrorImpl -import org.partiql.plan.rex.RexLit -import org.partiql.plan.rex.RexLitImpl -import org.partiql.plan.rex.RexNullIf -import org.partiql.plan.rex.RexNullIfImpl -import org.partiql.plan.rex.RexPathIndex -import org.partiql.plan.rex.RexPathIndexImpl -import org.partiql.plan.rex.RexPathKey -import org.partiql.plan.rex.RexPathKeyImpl -import org.partiql.plan.rex.RexPathSymbol -import org.partiql.plan.rex.RexPathSymbolImpl -import org.partiql.plan.rex.RexPivot -import org.partiql.plan.rex.RexPivotImpl -import org.partiql.plan.rex.RexSelect -import org.partiql.plan.rex.RexSelectImpl -import org.partiql.plan.rex.RexSpread -import org.partiql.plan.rex.RexSpreadImpl -import org.partiql.plan.rex.RexStruct -import org.partiql.plan.rex.RexStructImpl -import org.partiql.plan.rex.RexSubquery -import org.partiql.plan.rex.RexSubqueryComp -import org.partiql.plan.rex.RexSubqueryCompImpl -import org.partiql.plan.rex.RexSubqueryImpl -import org.partiql.plan.rex.RexSubqueryIn -import org.partiql.plan.rex.RexSubqueryInImpl -import org.partiql.plan.rex.RexSubqueryTest -import org.partiql.plan.rex.RexSubqueryTestImpl -import org.partiql.plan.rex.RexTable -import org.partiql.plan.rex.RexTableImpl -import org.partiql.plan.rex.RexType -import org.partiql.plan.rex.RexVar -import org.partiql.plan.rex.RexVarImpl -import org.partiql.spi.catalog.Table -import org.partiql.spi.function.Aggregation -import org.partiql.spi.function.Function -import org.partiql.spi.value.Datum -import org.partiql.types.PType - -/** - * The [PlanFactory] factory is used by builders and readers to provide concrete implementations of plan interfaces. - * - * This is an interface with default implementations; we cannot use default values or @JvmOverloads. There are a handful - * of overloads where default values are inserted (such as set operator quantifiers) or where omission of certain fields - * changes the logical operator - */ -public interface PlanFactory { - - // ALL MEMBERS SHOULD BE @JvmStatic - public companion object { - - /** - * A singleton of the [PlanFactory] with all the default implementations. - */ - @JvmStatic - public val STANDARD: PlanFactory = object : PlanFactory {} - } - - // --- REL OPERATORS ------------------------------------------------------------------------------------------------ - - /** - * Create a [RelAggregate] instance. - * - * @param input - * @param calls [RelAggregateCall - * - * @param input - */ - public fun relAggregate( - input: Rel, - calls: List, - groups: List, - ): RelAggregate = RelAggregateImpl(input, calls, groups) - - /** - * Create a [AggregateCall] instance. - * - * @param aggregation - * @param args - * @param isDistinct - * @return - */ - public fun relAggregateCall( - aggregation: Aggregation, - args: List, - isDistinct: Boolean = false, - ): AggregateCall = RelAggregateCallImpl(aggregation, args, isDistinct) - - /** - * Create a [RelCorrelate] instance for a lateral cross join. - * - * @param lhs - * @param rhs - * @return - */ - public fun relCorrelate(lhs: Rel, rhs: Rel): RelCorrelate = relCorrelate(lhs, rhs, JoinType.INNER) - - /** - * Create a [RelCorrelate] instance for a lateral join. - * - * @param lhs - * @param rhs - * @param joinType - * @return - */ - public fun relCorrelate(lhs: Rel, rhs: Rel, joinType: JoinType): RelCorrelate = RelCorrelateImpl(lhs, rhs, joinType) - - /** - * Create a [RelDistinct] instance. - * - * @param input - * @return - */ - public fun relDistinct(input: Rel): RelDistinct = RelDistinctImpl(input) - - /** - * Create a [RelExcept] instance for the default EXCEPT. - * - * @param lhs - * @param rhs - * @return - */ - public fun relExcept(lhs: Rel, rhs: Rel): RelExcept = relExcept(lhs, rhs, false) - - /** - * Create a [RelExcept] instance for EXCEPT [ALL|DISTINCT]. - * - * @param lhs - * @param rhs - * @return - */ - public fun relExcept( - lhs: Rel, - rhs: Rel, - isAll: Boolean, - ): RelExcept = RelExceptImpl(lhs, rhs, isAll) - - /** - * Create a [RelExclude] instance. - * - * @param input - * @param exclusions - * @return - */ - public fun relExclude(input: Rel, exclusions: List): RelExclude = RelExcludeImpl(input, exclusions) - - /** - * Create a [RelFilter] instance. - * - * @param input - * @param predicate - * @return - */ - public fun relFilter(input: Rel, predicate: Rex): RelFilter = RelFilterImpl(input, predicate) - - /** - * Create a [RelIntersect] instance for the default INTERSECT. - * - * @param lhs - * @param rhs - * @return - */ - public fun relIntersect( - lhs: Rel, - rhs: Rel, - ): RelIntersect = relIntersect(lhs, rhs, false) - - /** - * Create a [RelIntersect] instance for INTERSECT [ALL|DISTINCT]. - * - * @param lhs - * @param rhs - * @return - */ - public fun relIntersect( - lhs: Rel, - rhs: Rel, - isAll: Boolean, - ): RelIntersect = RelIntersectImpl(lhs, rhs, isAll) - - /** - * Create a [RelIterate] instance. - * - * @param input - * @return - */ - public fun relIterate(input: Rex): RelIterate = RelIterateImpl(input) - - /** - * Create a [RelJoin] instance for a cross join. - * - * - , - * - CROSS JOIN - * - JOIN ON TRUE - * - * @param lhs - * @param rhs - * @return - */ - public fun relJoin(lhs: Rel, rhs: Rel): RelJoin = relJoin(lhs, rhs, condition = null, JoinType.INNER) - - /** - * Create a [RelJoin] instance. - * - * @param lhs - * @param rhs - * @param condition - * @param type - * @return - */ - public fun relJoin( - lhs: Rel, - rhs: Rel, - condition: Rex?, - type: JoinType, - lhsSchema: RelType? = null, - rhsSchema: RelType? = null, - ): RelJoin = RelJoinImpl(lhs, rhs, condition, type, lhsSchema, rhsSchema) - - /** - * Create a [RelLimit] instance. - * - * @param input - * @param limit - * @return - */ - public fun relLimit(input: Rel, limit: Rex): RelLimit = RelLimitImpl(input, limit) - - /** - * Create a [RelLimit] instance. - * - * @param input - * @param offset - * @return - */ - public fun relOffset(input: Rel, offset: Rex): RelOffset = RelOffsetImpl(input, offset) - - /** - * Create a [RelProject] instance. - * - * @param input - * @param projections - * @return - */ - public fun relProject(input: Rel, projections: List): RelProject = RelProjectImpl(input, projections) - - /** - * Create a [RelScan] instance. - * - * @param input - * @return - */ - public fun relScan(input: Rex): RelScan = RelScanImpl(input) - - /** - * Create a [RelSort] instance. - * - * @param input - * @param collations - * @return - */ - public fun relSort(input: Rel, collations: List): RelSort = RelSortImpl(input, collations) - - /** - * Create a [RelUnion] instance for the default UNION. - * - * @param lhs - * @param rhs - * @return - */ - public fun relUnion(lhs: Rel, rhs: Rel): RelUnion = relUnion(lhs, rhs, false) - - /** - * Create a [RelUnion] instance for UNION [ALL|DISTINCT]. - * - * @param lhs - * @param rhs - * @return - */ - public fun relUnion(lhs: Rel, rhs: Rel, isAll: Boolean): RelUnion = RelUnionImpl(lhs, rhs, isAll) - - /** - * Create a [RelUnpivot] instance. - * - * @param input - * @return - */ - public fun relUnpivot(input: Rex): RelUnpivot = RelUnpivotImpl(input) - - // --- REX OPERATORS ------------------------------------------------------------------------------------------------ - - /** - * Create a [RexArray] instance with dynamic array type. - * - * @param values - * @return - */ - public fun rexArray(values: Collection): RexArray = RexArrayImpl(values, RexType(PType.array())) - - /** - * Create a [RexArray] instance with the given array type. - * - * @param values - * @param type - * @return - */ - public fun rexArray(values: Collection, type: RexType): RexArray = RexArrayImpl(values, type) - - /** - * Create a [RexBag] instance with dynamic bag type. - * - * @param values - * @return - */ - public fun rexBag(values: Collection): RexBag = RexBagImpl(values, RexType(PType.bag())) - - /** - * Create a [RexBag] instance with the given array type. - * - * @param values - * @param type - * @return - */ - public fun rexBag(values: Collection, type: RexType): RexBag = RexBagImpl(values, type) - - /** - * Create a [RexCall] instance. - * - * @param function - * @param args - * @return - */ - public fun rexCall(function: Function.Instance, args: List): RexCall = RexCallImpl(function, args) - - /** - * Create a [RexDispatch] instance. - * - * @param name TODO - * @param functions TODO - * @param args TODO - * @return TODO - */ - public fun rexCallDynamic(name: String, functions: List, args: List): RexDispatch = - RexCallDynamicImpl(name, functions, args) - - /** - * Create a [RexCase] instance for a searched case-when with dynamic type. - * - * @param branches - * @param default - * @return - */ - public fun rexCase(branches: List, default: Rex?): RexCase = rexCase(null, branches, default) - - /** - * Create a [RexCase] instance for a searched case-when with the given type. - * - * @param branches - * @param default - * @param type - * @return - */ - 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. - * - * @param match - * @param branches - * @param default - * @return - */ - public fun rexCase(match: Rex?, branches: List, default: Rex?): RexCase = - RexCaseImpl(match, branches, default, RexType.dynamic()) - - /** - * Create a [RexCase] instance for a case-when with the given type. - * - * @param match - * @param branches - * @param default - * @param type - * @return - */ - public fun rexCase(match: Rex?, branches: List, default: Rex?, type: RexType): RexCase = - RexCaseImpl(match, branches, default, type) - - /** - * Create a [RexCast] instance. - * - * @param operand - * @param target - * @return - */ - public fun rexCast(operand: Rex, target: PType): RexCast = RexCastImpl(operand, target) - - /** - * Create a [RexCoalesce] instance with dynamic type. - * - * @param args - * @return - */ - public fun rexCoalesce(args: List): RexCoalesce = RexCoalesceImpl(args, RexType.dynamic()) - - /** - * Create a [RexCoalesce] instance with the given type. - * - * @param args - * @return - */ - public fun rexCoalesce(args: List, type: RexType): RexCoalesce = RexCoalesceImpl(args, type) - - /** - * Create a [RexVar] instance with dynamic type. - * - * @param depth - * @param offset - * @return - */ - public fun rexVar(depth: Int, offset: Int): RexVar = RexVarImpl(depth, offset, RexType.dynamic()) - - /** - * Create a [RexVar] instance with the given type. - * - * @param depth - * @param offset - * @param type - * @return - */ - public fun rexVar(depth: Int, offset: Int, type: RexType): RexVar = RexVarImpl(depth, offset, type) - - /** - * TODO AUDIT ME - * Create a [RexError] instance. - */ - public fun rexError(type: PType): RexError = RexErrorImpl() - - /** - * Create a [RexLit] instance. - * - * @param value - * @return - */ - public fun rexLit(value: Datum): RexLit = RexLitImpl(value) - - /** - * Create a [RexNullIf] instance. - */ - public fun rexNullIf(value: Rex, nullifier: Rex): RexNullIf = RexNullIfImpl(value, nullifier) - - /** - * Create a [RexPathIndex] instance with dynamic type. - * - * @param operand - * @param index - * @return - */ - public fun rexPathIndex(operand: Rex, index: Rex): RexPathIndex = - RexPathIndexImpl(operand, index, RexType.dynamic()) - - /** - * Create a [RexPathIndex] instance with the given type. - * - * @param operand - * @param index - * @param type - * @return - */ - public fun rexPathIndex(operand: Rex, index: Rex, type: RexType): RexPathIndex = - RexPathIndexImpl(operand, index, type) - - /** - * Create a [RexPathKey] instance with dynamic type. - * - * @param operand - * @param key - * @return - */ - public fun rexPathKey(operand: Rex, key: Rex): RexPathKey = RexPathKeyImpl(operand, key, RexType.dynamic()) - - /** - * Create a [RexPathKey] instance with the given type. - * - * @param operand - * @param key - * @param type - * @return - */ - public fun rexPathKey(operand: Rex, key: Rex, type: RexType): RexPathKey = RexPathKeyImpl(operand, key, type) - - /** - * Create a [RexPathSymbol] instance with dynamic type. - * - * @param operand - * @param symbol - * @return - */ - public fun rexPathSymbol(operand: Rex, symbol: String): RexPathSymbol = - RexPathSymbolImpl(operand, symbol, RexType.dynamic()) - - /** - * Create a [RexPathSymbol] instance with the given type. - * - * @param operand - * @param symbol - * @param type - * @return - */ - public fun rexPathSymbol(operand: Rex, symbol: String, type: RexType): RexPathSymbol = - RexPathSymbolImpl(operand, symbol, type) - - /** - * Create a [RexPivot] instance. - * - * @param input - * @param key - * @param value - * @return - */ - public fun rexPivot(input: Rel, key: Rex, value: Rex): RexPivot = RexPivotImpl(input, key, value) - - /** - * Create a [RexSelect] instance. - * - * @param input - * @param constructor - * @return - */ - public fun rexSelect(input: Rel, constructor: Rex): RexSelect = RexSelectImpl(input, constructor) - - /** - * Create a [RexSpread] instance with open struct type. - * - * @param args - * @return - */ - public fun rexSpread(args: List): RexSpread = RexSpreadImpl(args, RexType(PType.struct())) - - /** - * Create a [RexSpread] instance with the given type. - * - * @param args - * @return - */ - public fun rexSpread(args: List, type: RexType): RexSpread = RexSpreadImpl(args, type) - - /** - * Create a [RexStruct] instance with open struct type. - * - * @param fields - * @return - */ - public fun rexStruct(fields: List): RexStruct = RexStructImpl(fields, RexType(PType.struct())) - - /** - * Create a [RexStruct] instance with the given type. - * - * @param fields - * @return - */ - public fun rexStruct(fields: List, type: RexType): RexStruct = RexStructImpl(fields, type) - - /** - * Create a [RexSubquery] instance. - * - * TODO REMOVE constructor AND asScalar – TEMPORARY UNTIL SUBQUERIES ARE FIXED IN THE PLANNER. - * - * @param rel - * @return - */ - public fun rexSubquery(rel: Rel, constructor: Rex, asScalar: Boolean): RexSubquery = - RexSubqueryImpl(rel, constructor, asScalar) - - /** - * Create a [RexSubqueryComp] instance. - * - * @param args - * @param comparison - * @param rel - * @return - */ - public fun rexSubqueryComp( - args: List, - comparison: RexSubqueryComp.Comparison, - rel: Rel, - ): RexSubqueryComp = RexSubqueryCompImpl(args, comparison, null, rel) - - /** - * Create a [RexSubqueryComp] instance. - * - * @param args - * @param comparison - * @param quantifier - * @param rel - * @return - */ - public fun rexSubqueryComp( - args: List, - comparison: RexSubqueryComp.Comparison, - quantifier: RexSubqueryComp.Quantifier?, - rel: Rel, - ): RexSubqueryComp = RexSubqueryCompImpl(args, comparison, quantifier, rel) - - /** - * Create a [RexSubqueryIn] instance for single argument. - * - * @param arg - * @param rel - * @return - */ - public fun rexSubqueryIn(arg: Rex, rel: Rel): RexSubqueryIn = rexSubqueryIn(listOf(arg), rel) - - /** - * Create a [RexSubqueryIn] instance for a list argument. - * - * @param args - * @param rel - * @return - */ - public fun rexSubqueryIn(args: List, rel: Rel): RexSubqueryIn = RexSubqueryInImpl(args, rel) - - /** - * Create a [RexSubqueryTest] instance. - * - * @param test - * @param rel - * @return - */ - public fun rexSubqueryTest(test: RexSubqueryTest.Test, rel: Rel): RexSubqueryTest = RexSubqueryTestImpl(test, rel) - - /** - * Create a [RexTable] instance. - * - * @param table - * @return - */ - public fun rexTable(table: Table): RexTable = RexTableImpl(table) -} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt deleted file mode 100644 index 81afdbc87..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RelBuilder.kt +++ /dev/null @@ -1,240 +0,0 @@ -package org.partiql.plan.builder - -import org.partiql.plan.Collation -import org.partiql.plan.Exclusion -import org.partiql.plan.JoinType -import org.partiql.plan.rel.Rel -import org.partiql.plan.rel.RelAggregate - -/** - * DataFrame style fluent-builder for PartiQL logical plans. - * - * TODO schemas and field names. - */ -@Suppress("LocalVariableName") -public class RelBuilder private constructor(builder: Builder) { - - // DO NOT USE FINAL MEMBERS - private var self: Builder = builder - - /** - * Invoke the builder with the default [PlanFactory] implementation. - */ - public fun build(): Rel = build(PlanFactory.STANDARD) - - /** - * Invoke the builder with the given [PlanFactory] implementation. - */ - public fun build(factory: PlanFactory): Rel = self.build(factory) - - /** - * This object holds named constructors for the [RelBuilder] class. - */ - public companion object { - - /** - * Initialize a logical scan operator builder. - */ - @JvmStatic - public fun scan(input: RexBuilder): RelBuilder = RelBuilder { - val _input = input.build(it) - it.relScan(_input) - } - - /** - * Initialize a logical iterate operator builder. - */ - @JvmStatic - public fun iterate(input: RexBuilder): RelBuilder = RelBuilder { - val _input = input.build(it) - it.relIterate(_input) - } - - /** - * Initialize a logical unpivot operator builder. - */ - @JvmStatic - public fun unpivot(input: RexBuilder): RelBuilder = RelBuilder { - val _input = input.build(it) - it.relUnpivot(_input) - } - } - - /** - * Appends a RelAggregate to the current operator builder. - */ - public fun aggregate( - measures: List, - groups: List, - ): RelBuilder = RelBuilder { - val _input = self.build(it) - val _measures = measures - val _groups = groups.map { group -> group.build(it) } - it.relAggregate(_input, _measures, _groups) - } - - public fun distinct(): RelBuilder = RelBuilder { - val _input = self.build(it) - it.relDistinct(_input) - } - - /** - * Appends a RelExcept to the current operator builder. - */ - public fun except(rhs: Rel): RelBuilder = RelBuilder { - val lhs = self.build(it) - it.relIntersect(lhs, rhs) - } - - /** - * Appends a RelExclude to the current operator builder. - */ - public fun exclude(exclusions: List): RelBuilder = RelBuilder { - val _input = self.build(it) - it.relExclude(_input, exclusions) - } - - /** - * Appends a RelFilter to the current operator builder. - */ - public fun filter(predicate: RexBuilder): RelBuilder = RelBuilder { - val _input = self.build(it) - val _predicate = predicate.build(it) - it.relFilter(_input, _predicate) - } - - /** - * Appends a RelIntersect to the current operator builder. - */ - public fun intersect(rhs: RelBuilder): RelBuilder = RelBuilder { - val _lhs = self.build(it) - val _rhs = rhs.build(it) - it.relIntersect(_lhs, _rhs) - } - - /** - * Appends a RelJoin to the current operator builder for LATERAL CROSS JOIN. - */ - public fun join(rhs: RelBuilder): RelBuilder = join(rhs, null, JoinType.INNER()) - - /** - * Appends a RelJoin to the current operator builder for INNER JOIN ON . - * - * @param rhs - * @param condition - * @return - */ - public fun join( - rhs: RelBuilder, - condition: RexBuilder, - ): RelBuilder = join(rhs, condition, JoinType.INNER()) - - /** - * Appends a RelJoin to the current operator builder for [LEFT|RIGHT|INNER|FULL] JOIN. - * - * @param rhs - * @param type - * @return - */ - public fun join(rhs: RelBuilder, type: JoinType): RelBuilder = join(rhs, null, type) - - /** - * Appends a RelJoin to the current operator builder for [LEFT|RIGHT|INNER|FULL] JOIN ON . - * - * @param rhs - * @param condition - * @param type - * @return - */ - public fun join( - rhs: RelBuilder, - condition: RexBuilder?, - type: JoinType, - ): RelBuilder = RelBuilder { - val _lhs = self.build(it) - val _rhs = rhs.build(it) - val _condition = condition?.build(it) - it.relJoin(_lhs, _rhs, _condition, type) - } - - /** - * Appends a RelLimit to the current operator builder. - * - * @param limit - * @return - */ - public fun limit(limit: RexBuilder): RelBuilder = RelBuilder { - val _input = self.build(it) - val _limit = limit.build(it) - it.relLimit(_input, _limit) - } - - /** - * Appends a RelOffset to the current operator builder. - * - * @param offset - * @return - */ - public fun offset(offset: RexBuilder): RelBuilder = RelBuilder { - val _input = self.build(it) - val _offset = offset.build(it) - it.relOffset(_input, _offset) - } - - /** - * Appends a RelProject to the current operator builder. - * - * @param projections - * @return - */ - public fun project(vararg projections: RexBuilder): RelBuilder = project(projections.toList()) - - /** - * Appends a RelProject to the current operator builder. - * - * @param projections - * @return - */ - public fun project(projections: List): RelBuilder = RelBuilder { - val _input = self.build(it) - val _projections = projections.map { rex -> rex.build(it) } - it.relProject(_input, _projections) - } - - /** - * Appends a RelSort to the current operator builder. - * - * @param collations - * @return - */ - public fun sort(collations: List): RelBuilder = RelBuilder { - val _input = self.build(it) - it.relSort(_input, collations) - } - - /** - * Appends a RelUnion to the current operator builder. - */ - public fun union(rhs: Rel): RelBuilder = RelBuilder { - val lhs = self.build(it) - it.relUnion(lhs, rhs) - } - - /** - * Appends a RexPivot to the current relational operator – this is a rel->rex projection. - */ - public fun pivot( - key: RexBuilder, - value: RexBuilder, - ): RexBuilder = RexBuilder.pivot(this, key, value) - - /** - * Appends a RexSelect to the current relation operator – this is a rel->rex projection. - */ - public fun select(constructor: RexBuilder): RexBuilder = RexBuilder.select(this, constructor) - - // PRIVATE FUNCTIONAL INTERFACE COMPILES DOWN TO PRIVATE STATIC METHODS. - private fun interface Builder { - fun build(factory: PlanFactory): Rel - } -} diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RexBuilder.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RexBuilder.kt deleted file mode 100644 index be30e7897..000000000 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/RexBuilder.kt +++ /dev/null @@ -1,203 +0,0 @@ -package org.partiql.plan.builder - -import org.partiql.plan.rel.Rel -import org.partiql.plan.rex.Rex -import org.partiql.plan.rex.RexStruct -import org.partiql.plan.rex.RexSubqueryTest -import org.partiql.spi.catalog.Table -import org.partiql.spi.value.Datum -import org.partiql.types.PType - -/** - * DataFrame style fluent-builder for PartiQL logical plans. - */ -@Suppress("LocalVariableName") -public class RexBuilder private constructor(rex: Builder) { - - // DO NOT USE FINAL MEMBERS - private var self: Builder = rex - - /** - * Invoke the builder with the default [PlanFactory] implementation. - */ - public fun build(): Rex = build(PlanFactory.STANDARD) - - /** - * Invoke the builder with the given [PlanFactory] implementation. - */ - public fun build(factory: PlanFactory): Rex = self.build(factory) - - /** - * This object holds named constructors for the [RexBuilder] class. - */ - public companion object { - - @JvmStatic - public fun variable(offset: Int): RexBuilder = RexBuilder { - it.rexVar(0, offset) - } - - @JvmStatic - public fun variable(depth: Int, offset: Int): RexBuilder = RexBuilder { - it.rexVar(depth, offset) - } - - @JvmStatic - public fun table(table: Table): RexBuilder = RexBuilder { - it.rexTable(table) - } - - @JvmStatic - public fun lit(value: Boolean): RexBuilder = lit(Datum.bool(value)) - - @JvmStatic - public fun lit(value: Int): RexBuilder = lit(Datum.integer(value)) - - @JvmStatic - public fun lit(value: Long): RexBuilder = lit(Datum.bigint(value)) - - @JvmStatic - public fun lit(value: String): RexBuilder = lit(Datum.string(value)) - - @JvmStatic - public fun lit(value: Datum): RexBuilder = RexBuilder { it.rexLit(value) } - - @JvmStatic - public fun array(values: Collection): RexBuilder = RexBuilder { it.rexArray(values) } - - @JvmStatic - public fun bag(values: Collection): RexBuilder = RexBuilder { it.rexBag(values) } - - @JvmStatic - public fun coalesce(args: List): RexBuilder = RexBuilder { - it.rexCoalesce(args) - } - - /** - * TODO add some vararg and vararg pair overloads. - */ - @JvmStatic - public fun struct(fields: List): RexBuilder = RexBuilder { - it.rexStruct(fields) - } - - /** - * Spread because it's similar to the struct/dict spread of other languages. { x..., y... } - */ - @JvmStatic - public fun spread(args: List): RexBuilder = RexBuilder { - it.rexSpread(args) - } - - /** - * Scalar subquery coercion. - */ - @JvmStatic - public fun subquery(rel: RelBuilder): RexBuilder = RexBuilder { - throw UnsupportedOperationException("subquery builders are removed until supported in partiql-planner") - } - - /** - * Subquery EXISTS. - */ - @JvmStatic - public fun exists(rel: RelBuilder): RexBuilder = RexBuilder { - val _rel = rel.build(it) - it.rexSubqueryTest(RexSubqueryTest.Test.EXISTS, _rel) - } - - /** - * Subquery UNIQUE. - */ - @JvmStatic - public fun unique(rel: RelBuilder): RexBuilder = RexBuilder { - val _rel = rel.build(it) - it.rexSubqueryTest(RexSubqueryTest.Test.UNIQUE, _rel) - } - - /** - * Creates a RexPivot operator. - */ - @JvmStatic - public fun pivot(input: RelBuilder, key: RexBuilder, value: RexBuilder): RexBuilder = RexBuilder { - val _input = input.build(it) - val _key = key.build(it) - val _value = value.build(it) - it.rexPivot(_input, _key, _value) - } - - /** - * Creates a RexSelect operator. - * - * @param input - * @param constructor - * @return - */ - @JvmStatic - public fun select(input: RelBuilder, constructor: RexBuilder): RexBuilder = RexBuilder { - val _input = input.build(it) - val _constructor = constructor.build(it) - it.rexSelect(_input, _constructor) - } - } - - /** - * Appends a RexCast to the current rex builder. - */ - public fun cast(target: PType): RexBuilder = RexBuilder { - val _operand = self.build(it) - it.rexCast(_operand, target) - } - - /** - * Appends a RexPathKey (or RexPathSymbol) to the current rex builder. - * - * @param key - * @return - */ - public fun path(key: String, caseInsensitive: Boolean = false): RexBuilder = RexBuilder { - val _key = it.rexLit(Datum.string(key)) - val _operand = self.build(it) - if (caseInsensitive) { - it.rexPathSymbol(_operand, key) - } else { - it.rexPathKey(_operand, _key) - } - } - - /** - * Appends a RexPathIndex to the current rex builder. - * - * @param index - * @return - */ - public fun path(index: Int): RexBuilder = RexBuilder { - val _index = it.rexLit(Datum.integer(index)) - val _operand = self.build(it) - it.rexPathIndex(_operand, _index) - } - - /** - * Transform the [Rex] operator into a RelScan operator - this a rex->rel projection. - */ - public fun scan(): RelBuilder = RelBuilder.scan(this) - - /** - * Transform the [Rel] operator into a RelIterate operator – this is rex->rel projection. - * - * @return - */ - public fun iterate(): RelBuilder = RelBuilder.iterate(this) - - /** - * The UNPIVOT expression-to-relation projection. - */ - public fun unpivot(): RelBuilder = RelBuilder.unpivot(this) - - /** - * PRIVATE FUNCTIONAL INTERFACE COMPILES DOWN TO PRIVATE STATIC METHODS. - */ - private fun interface Builder { - fun build(factory: PlanFactory): Rex - } -} diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt index b0de20d8e..076480f90 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt @@ -3,7 +3,7 @@ package org.partiql.planner.internal import org.partiql.ast.Statement import org.partiql.plan.Operation import org.partiql.plan.Plan -import org.partiql.plan.builder.PlanFactory +import org.partiql.plan.builder.Operators import org.partiql.plan.rex.Rex import org.partiql.planner.PartiQLPlanner import org.partiql.planner.PartiQLPlannerPass @@ -63,7 +63,7 @@ internal class SqlPlanner( override fun getOperation(): Operation { return object : Operation.Query { override fun getRex(): Rex { - return PlanFactory.STANDARD.rexError(PType.dynamic()) + return Operators.STANDARD.rexError(PType.dynamic()) } } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index e52aea3c9..df13d5a05 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -58,7 +58,7 @@ internal class PlanTransform(private val flags: Set) { private val signal: Boolean, ) : PlanBaseVisitor() { - private val factory = org.partiql.plan.builder.PlanFactory.STANDARD + private val factory = org.partiql.plan.builder.Operators.STANDARD override fun defaultReturn(node: INode, ctx: PType): Any { TODO("Translation not supported for ${node::class.simpleName}") diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index 191ccf921..933c10d61 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.params.provider.ArgumentsSource import org.partiql.parser.PartiQLParser import org.partiql.plan.Exclusion import org.partiql.plan.Operation -import org.partiql.plan.builder.PlanFactory +import org.partiql.plan.builder.Operators import org.partiql.plan.rel.RelExclude import org.partiql.plan.rel.RelProject import org.partiql.plan.rex.RexSelect @@ -59,7 +59,7 @@ class SubsumptionTest { return parameters.map { Arguments.of(it) }.stream() } - private val factory = PlanFactory.STANDARD + private val factory = Operators.STANDARD private fun rexOpVar(depth: Int, offset: Int): RexVar = factory.rexVar(depth, offset) From e0c1fbfd92c74137dcb550dc82a66018691ae526 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 2 Dec 2024 09:51:59 -0800 Subject: [PATCH 07/19] Operators factory to plan root level --- .../main/kotlin/org/partiql/plan/{builder => }/Operators.kt | 5 +---- partiql-plan/src/main/kotlin/org/partiql/plan/builder/.keep | 0 .../main/kotlin/org/partiql/planner/internal/SqlPlanner.kt | 2 +- .../org/partiql/planner/internal/transforms/PlanTransform.kt | 3 ++- .../org/partiql/planner/internal/exclude/SubsumptionTest.kt | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) rename partiql-plan/src/main/kotlin/org/partiql/plan/{builder => }/Operators.kt (98%) create mode 100644 partiql-plan/src/main/kotlin/org/partiql/plan/builder/.keep diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt similarity index 98% rename from partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt rename to partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt index 8ec09e96f..f5920e404 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/Operators.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt @@ -1,8 +1,5 @@ -package org.partiql.plan.builder +package org.partiql.plan -import org.partiql.plan.Collation -import org.partiql.plan.Exclusion -import org.partiql.plan.JoinType import org.partiql.plan.rel.Rel import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelAggregate.Measure diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/builder/.keep b/partiql-plan/src/main/kotlin/org/partiql/plan/builder/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt index 076480f90..e8d3b8d91 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt @@ -3,7 +3,7 @@ package org.partiql.planner.internal import org.partiql.ast.Statement import org.partiql.plan.Operation import org.partiql.plan.Plan -import org.partiql.plan.builder.Operators +import org.partiql.plan.Operators import org.partiql.plan.rex.Rex import org.partiql.planner.PartiQLPlanner import org.partiql.planner.PartiQLPlannerPass diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index df13d5a05..a4e8d77f8 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -4,6 +4,7 @@ import org.partiql.plan.AggregateCall import org.partiql.plan.Collation import org.partiql.plan.Exclusion import org.partiql.plan.JoinType +import org.partiql.plan.Operators import org.partiql.plan.Plan import org.partiql.plan.rel.RelType import org.partiql.plan.rex.Rex @@ -58,7 +59,7 @@ internal class PlanTransform(private val flags: Set) { private val signal: Boolean, ) : PlanBaseVisitor() { - private val factory = org.partiql.plan.builder.Operators.STANDARD + private val factory = Operators.STANDARD override fun defaultReturn(node: INode, ctx: PType): Any { TODO("Translation not supported for ${node::class.simpleName}") diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index 933c10d61..e2689d30e 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.params.provider.ArgumentsSource import org.partiql.parser.PartiQLParser import org.partiql.plan.Exclusion import org.partiql.plan.Operation -import org.partiql.plan.builder.Operators +import org.partiql.plan.Operators import org.partiql.plan.rel.RelExclude import org.partiql.plan.rel.RelProject import org.partiql.plan.rex.RexSelect From 949ed9cd66ce10368a2fec55c9e39de5e1500b04 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 2 Dec 2024 15:08:28 -0800 Subject: [PATCH 08/19] Cleanup operands and add rel rewriter --- .../internal/compiler/StandardCompiler.kt | 9 +- partiql-plan/README.md | 26 +- .../main/java/org/partiql/plan/Operator.java | 6 +- .../org/partiql/plan/OperatorTransform.java | 482 ++++++++++++++++++ .../{Visitor.java => OperatorVisitor.java} | 53 +- .../org/partiql/plan/rel/RelAggregate.java | 58 ++- .../java/org/partiql/plan/rel/RelBase.java | 18 +- .../org/partiql/plan/rel/RelCorrelate.java | 30 +- .../org/partiql/plan/rel/RelDistinct.java | 25 +- .../java/org/partiql/plan/rel/RelExcept.java | 42 +- .../java/org/partiql/plan/rel/RelExclude.java | 31 +- .../java/org/partiql/plan/rel/RelFilter.java | 30 +- .../org/partiql/plan/rel/RelIntersect.java | 30 +- .../java/org/partiql/plan/rel/RelIterate.java | 19 +- .../java/org/partiql/plan/rel/RelJoin.java | 44 +- .../java/org/partiql/plan/rel/RelLimit.java | 30 +- .../java/org/partiql/plan/rel/RelOffset.java | 30 +- .../java/org/partiql/plan/rel/RelProject.java | 30 +- .../java/org/partiql/plan/rel/RelScan.java | 19 +- .../java/org/partiql/plan/rel/RelSort.java | 26 +- .../java/org/partiql/plan/rel/RelUnion.java | 30 +- .../java/org/partiql/plan/rel/RelUnpivot.java | 19 +- .../java/org/partiql/plan/rex/RexArray.java | 8 +- .../java/org/partiql/plan/rex/RexBag.java | 8 +- .../java/org/partiql/plan/rex/RexBase.java | 18 +- .../java/org/partiql/plan/rex/RexCall.java | 6 +- .../java/org/partiql/plan/rex/RexCase.java | 12 +- .../java/org/partiql/plan/rex/RexCast.java | 8 +- .../org/partiql/plan/rex/RexCoalesce.java | 8 +- .../org/partiql/plan/rex/RexDispatch.java | 6 +- .../java/org/partiql/plan/rex/RexError.java | 6 +- .../java/org/partiql/plan/rex/RexLit.java | 6 +- .../java/org/partiql/plan/rex/RexNullIf.java | 10 +- .../org/partiql/plan/rex/RexPathIndex.java | 10 +- .../java/org/partiql/plan/rex/RexPathKey.java | 10 +- .../org/partiql/plan/rex/RexPathSymbol.java | 8 +- .../java/org/partiql/plan/rex/RexPivot.java | 12 +- .../java/org/partiql/plan/rex/RexSelect.java | 10 +- .../java/org/partiql/plan/rex/RexSpread.java | 8 +- .../java/org/partiql/plan/rex/RexStruct.java | 8 +- .../org/partiql/plan/rex/RexSubquery.java | 8 +- .../org/partiql/plan/rex/RexSubqueryComp.java | 10 +- .../org/partiql/plan/rex/RexSubqueryIn.java | 10 +- .../org/partiql/plan/rex/RexSubqueryTest.java | 8 +- .../java/org/partiql/plan/rex/RexTable.java | 6 +- .../java/org/partiql/plan/rex/RexVar.java | 6 +- .../main/kotlin/org/partiql/plan/Operators.kt | 41 +- .../internal/transforms/PlanTransform.kt | 32 +- ...r.kt => PlanEquivalenceOperatorVisitor.kt} | 4 +- .../kotlin/org/partiql/planner/PlanTest.kt | 2 +- 50 files changed, 1100 insertions(+), 276 deletions(-) create mode 100644 partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java rename partiql-plan/src/main/java/org/partiql/plan/{Visitor.java => OperatorVisitor.java} (74%) rename partiql-planner/src/test/kotlin/org/partiql/planner/{PlanEquivalenceVisitor.kt => PlanEquivalenceOperatorVisitor.kt} (98%) 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 42822943b..8b78ae114 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 @@ -64,7 +64,7 @@ import org.partiql.plan.JoinType import org.partiql.plan.Operation import org.partiql.plan.Operator import org.partiql.plan.Plan -import org.partiql.plan.Visitor +import org.partiql.plan.OperatorVisitor import org.partiql.plan.rel.Rel import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelDistinct @@ -123,7 +123,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun prepare(plan: Plan, mode: Mode, ctx: Context): Statement { try { - val visitor = _Visitor(mode) + val visitor = _Operator_Visitor(mode) val operation = plan.getOperation() val statement: Statement = when { operation is Operation.Query -> visitor.compile(operation) @@ -143,7 +143,8 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { * Transforms plan relation operators into the internal physical operators. */ @Suppress("ClassName") - private inner class _Visitor(mode: Mode) : Visitor { + private inner class _Operator_Visitor(mode: Mode) : + OperatorVisitor { private val mode = mode.code() @@ -173,7 +174,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { // first match if (strategy.getPattern().matches(operator)) { // compile children - val children = operator.getChildren().map { compileWithStrategies(it, ctx) } + val children = operator.getOperands().map { compileWithStrategies(it, ctx) } val match = Match(operator, children) return strategy.apply(match) } diff --git a/partiql-plan/README.md b/partiql-plan/README.md index f746a8bcd..55771e76b 100644 --- a/partiql-plan/README.md +++ b/partiql-plan/README.md @@ -3,30 +3,38 @@ ## Classes * Operator -* Rel -* Rex +* Rel & RelBase +* Rex & RexBase ## Visitors -* Visitor -* Rewriter +* OperatorVisitor +* OperatorRewriter ## Design -For the rule and strategy patterns to work, we need to model classes whose children have a stable ordering; -so we have defined an abstract base class for all operators which holds children and controls the access to them. -We use base implementations for state management and enforcing children ordering; however we use interfaces for the +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. +What are operands? + +* 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" + Why interfaces for top-level domain entities and not abstract base classes? -* We don’t want to force materialization of children (consider wrapping a serde class) +* We don’t want to force materialization of operands (consider wrapping a serde class) * We don’t want to force holding state (aka having to call super constructors) * The operator/rel/rex should be flexible for extension and the interface is the most open-ended / non-prescriptive. Why abstract base classes for individual operators and not interfaces? -* Enforce children ordering is the primary reason; also can memoize children. +* Enforce operands ordering is the primary reason; also can memoize operands. * Hold state such as mutable tags and computed types. * We want the standard operators to be prescriptive but not limiting. 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 0afafe439..f54f16c09 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Operator.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Operator.java @@ -30,7 +30,7 @@ public interface Operator { * @param Visitor context type (scoped args). * @return R */ - public abstract R accept(Visitor visitor, C ctx); + public abstract R accept(OperatorVisitor visitor, C ctx); /** * Get i-th child (input) operator. @@ -39,11 +39,11 @@ public interface Operator { * @return child operator */ @NotNull - public abstract Operator getChild(int index); + public abstract Operator getOperand(int index); /** * @return all child (input) operators. */ @NotNull - public abstract List getChildren(); + public abstract List getOperands(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java new file mode 100644 index 000000000..790457e36 --- /dev/null +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java @@ -0,0 +1,482 @@ +package org.partiql.plan; + +import org.jetbrains.annotations.NotNull; +import org.partiql.plan.rel.*; +import org.partiql.plan.rel.RelAggregate.Measure; +import org.partiql.plan.rex.*; + +import java.util.ArrayList; +import java.util.List; + +/** + * Operator transform is an abstract base visitor which recursively rewrites an operator tree. + *
+ * Developer Note + * - + * - use the visitAll for rewriting collections as it's more efficient and won't trigger rewrites. + */ +public abstract class OperatorTransform implements OperatorVisitor { + + /** + * Operator factory to use for rewrites. + */ + private final Operators operators; + + /** + * Base operator transform with standard operators factory. + */ + public OperatorTransform() { + this.operators = Operators.STANDARD; + } + + /** + * Base operator transform with custom operators factory. + */ + public OperatorTransform(Operators operators) { + this.operators = operators; + } + + @NotNull + @Override + public Operator defaultReturn(@NotNull Operator operator, C ctx) { + return operator; + } + + @NotNull + @Override + public Operator defaultVisit(Operator operator, C ctx) { + return operator; + } + + @NotNull + @Override + public Operator visitAggregate(@NotNull RelAggregate rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite measures + List measures = rel.getMeasures(); + List measures_new = visitAll(measures, ctx, this::visitAggregateMeasure); + // rewrite groups + List groups = rel.getGroups(); + List groups_new = visitAll(groups, ctx, this::visitAggregateGroup); + // rewrite aggregate + if (input != input_new || measures != measures_new || groups != groups_new) { + return operators.aggregate(input_new, measures_new, groups_new); + } + return rel; + } + + @NotNull + public Measure visitAggregateMeasure(@NotNull Measure measure, C ctx) { + // rewrite args + List args = measure.getArgs(); + List args_new = visitAll(args, ctx, this::visitAggregateGroup); + // rewrite aggregate measure + if (args != args_new) { + return measure.copy(args_new); + } + return measure; + } + + @NotNull + public Rex visitAggregateGroup(@NotNull Rex rex, C ctx) { + // rewrite aggregate group + return visit(rex, ctx, Rex.class); + } + + @Override + public Operator visitCorrelate(@NotNull RelCorrelate rel, C ctx) { + // rewrite left + Rel left = rel.getLeft(); + Rel left_new = visit(left, ctx, Rel.class); + // rewrite right + Rel right = rel.getRight(); + Rel right_new = visit(right, ctx, Rel.class); + // rewrite correlate + if (left != left_new || right != right_new) { + return operators.correlate(left_new, right_new, rel.getJoinType()); + } + return rel; + } + + @NotNull + @Override + public Operator visitDistinct(@NotNull RelDistinct rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite distinct + if (input != input_new) { + return operators.distinct(input_new); + } + return rel; + } + + @NotNull + @Override + public Operator visitExcept(@NotNull RelExcept rel, C ctx) { + // rewrite left + Rel left = rel.getLeft(); + Rel left_new = visit(left, ctx, Rel.class); + // rewrite right + Rel right = rel.getRight(); + Rel right_new = visit(right, ctx, Rel.class); + // rewrite except + if (left != left_new || right != right_new) { + return operators.except(left_new, right_new, rel.isAll()); + } + return rel; + } + + @NotNull + @Override + public Operator visitExclude(@NotNull RelExclude rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite exclusions + List exclusions = rel.getExclusions(); + List exclusions_new = visitAll(exclusions, ctx, this::visitExclusions); + // rewrite exclude + if (input != input_new) { + return operators.exclude(input_new, exclusions_new); + } + return rel; + } + + @NotNull + public Exclusion visitExclusions(@NotNull Exclusion exclusion, C ctx) { + // rewrite exclusion + return exclusion; + } + + @Override + public Operator visitFilter(@NotNull RelFilter rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite predicate + Rex predicate = rel.getPredicate(); + Rex predicate_new = visit(predicate, ctx, Rex.class); + // rewrite filter + if (input != input_new || predicate != predicate_new) { + return operators.filter(input_new, predicate_new); + } + return rel; + } + + @Override + public Operator visitIntersect(@NotNull RelIntersect rel, C ctx) { + // rewrite left + Rel left = rel.getLeft(); + Rel left_new = visit(left, ctx, Rel.class); + // rewrite right + Rel right = rel.getRight(); + Rel right_new = visit(right, ctx, Rel.class); + // rewrite intersect + if (left != left_new || right != right_new) { + return operators.intersect(left_new, right_new, rel.isAll()); + } + return rel; + } + + @Override + public Operator visitIterate(@NotNull RelIterate rel, C ctx) { + // rewrite rex + Rex rex = rel.getRex(); + Rex rex_new = visit(rex, ctx, Rex.class); + // rewrite iterate + if (rex != rex_new) { + return operators.iterate(rex_new); + } + return rel; + } + + @Override + public Operator visitJoin(@NotNull RelJoin rel, C ctx) { + // rewrite left + Rel left = rel.getLeft(); + Rel left_new = visit(left, ctx, Rel.class); + // rewrite right + Rel right = rel.getRight(); + Rel right_new = visit(right, ctx, Rel.class); + // rewrite condition + Rex condition = rel.getCondition(); + Rex condition_new = visit(condition, ctx, Rex.class); + // rewrite join + if (left != left_new || right != right_new || condition != condition_new) { + return operators.join(left_new, right_new, condition_new, rel.getJoinType()); + } + return rel; + } + + @Override + public Operator visitLimit(@NotNull RelLimit rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite limit + Rex limit = rel.getLimit(); + Rex limit_new = visit(limit, ctx, Rex.class); + // rewrite limit + if (input != input_new || limit != limit_new) { + return operators.limit(input_new, limit_new); + } + return rel; + } + + @Override + public Operator visitOffset(@NotNull RelOffset rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite offset + Rex offset = rel.getOffset(); + Rex offset_new = visit(offset, ctx, Rex.class); + // rewrite offset + if (input != input_new || offset != offset_new) { + return operators.offset(input_new, offset_new); + } + return rel; + } + + @Override + public Operator visitProject(@NotNull RelProject rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite projections + List projections = rel.getProjections(); + List projects_new = visitAll(projections, ctx, this::visitProjection); + // rewrite projection + if (input != input_new || projections != projects_new) { + return operators.project(input_new, projects_new); + } + return rel; + } + + @NotNull + public Rex visitProjection(@NotNull Rex rex, C ctx) { + // rewrite projection + return visit(rex, ctx, Rex.class); + } + + @Override + public Operator visitScan(@NotNull RelScan rel, C ctx) { + // rewrite rex + Rex rex = rel.getRex(); + Rex rex_new = visit(rex, ctx, Rex.class); + // rewrite scan + if (rex != rex_new) { + return operators.scan(rex_new); + } + return rel; + } + + @Override + public Operator visitSort(@NotNull RelSort rel, C ctx) { + // rewrite input + Rel input = rel.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite collations + List collations = rel.getCollations(); + List collations_new = visitAll(collations, ctx, this::visitCollation); + // rewrite sort + if (input != input_new || collations != collations_new) { + return operators.sort(input_new, collations_new); + } + return rel; + } + + @NotNull + public Collation visitCollation(@NotNull Collation collation, C ctx) { + // rewrite collation + return collation; + } + + @Override + public Operator visitUnion(@NotNull RelUnion rel, C ctx) { + // rewrite left + Rel left = rel.getLeft(); + Rel left_new = visit(left, ctx, Rel.class); + // rewrite right + Rel right = rel.getRight(); + Rel right_new = visit(right, ctx, Rel.class); + // rewrite union + if (left != left_new || right != right_new) { + return operators.union(left_new, right_new, rel.isAll()); + } + return rel; + } + + @Override + public Operator visitUnpivot(@NotNull RelUnpivot rel, C ctx) { + Rex rex = rel.getRex(); + Rex rex_new = visit(rex, ctx, Rex.class); + if (rex != rex_new) { + return operators.unpivot(rex); + } + return rel; + } + + @Override + public Operator visitArray(@NotNull RexArray rex, C ctx) { + return OperatorVisitor.super.visitArray(rex, ctx); + } + + @Override + public Operator visitBag(@NotNull RexBag rex, C ctx) { + return OperatorVisitor.super.visitBag(rex, ctx); + } + + @Override + public Operator visitCall(@NotNull RexCall rex, C ctx) { + return OperatorVisitor.super.visitCall(rex, ctx); + } + + @Override + public Operator visitCallDynamic(@NotNull RexDispatch rex, C ctx) { + return OperatorVisitor.super.visitCallDynamic(rex, ctx); + } + + @Override + public Operator visitCase(@NotNull RexCase rex, C ctx) { + return OperatorVisitor.super.visitCase(rex, ctx); + } + + @Override + public Operator visitCast(@NotNull RexCast rex, C ctx) { + return OperatorVisitor.super.visitCast(rex, ctx); + } + + @Override + public Operator visitCoalesce(@NotNull RexCoalesce rex, C ctx) { + return OperatorVisitor.super.visitCoalesce(rex, ctx); + } + + @Override + public Operator visitError(@NotNull RexError rex, C ctx) { + return OperatorVisitor.super.visitError(rex, ctx); + } + + @Override + public Operator visitLit(@NotNull RexLit rex, C ctx) { + return OperatorVisitor.super.visitLit(rex, ctx); + } + + @Override + public Operator visitNullIf(@NotNull RexNullIf rex, C ctx) { + return OperatorVisitor.super.visitNullIf(rex, ctx); + } + + @Override + public Operator visitPathIndex(@NotNull RexPathIndex rex, C ctx) { + return OperatorVisitor.super.visitPathIndex(rex, ctx); + } + + @Override + public Operator visitPathKey(@NotNull RexPathKey rex, C ctx) { + return OperatorVisitor.super.visitPathKey(rex, ctx); + } + + @Override + public Operator visitPathSymbol(@NotNull RexPathSymbol rex, C ctx) { + return OperatorVisitor.super.visitPathSymbol(rex, ctx); + } + + @Override + public Operator visitPivot(@NotNull RexPivot rex, C ctx) { + return OperatorVisitor.super.visitPivot(rex, ctx); + } + + @Override + public Operator visitSelect(@NotNull RexSelect rex, C ctx) { + return OperatorVisitor.super.visitSelect(rex, ctx); + } + + @Override + public Operator visitStruct(@NotNull RexStruct rex, C ctx) { + return OperatorVisitor.super.visitStruct(rex, ctx); + } + + @Override + public Operator visitSubquery(@NotNull RexSubquery rex, C ctx) { + return OperatorVisitor.super.visitSubquery(rex, ctx); + } + + @Override + public Operator visitSubqueryComp(@NotNull RexSubqueryComp rex, C ctx) { + return OperatorVisitor.super.visitSubqueryComp(rex, ctx); + } + + @Override + public Operator visitSubqueryIn(@NotNull RexSubqueryIn rex, C ctx) { + return OperatorVisitor.super.visitSubqueryIn(rex, ctx); + } + + @Override + public Operator visitSubqueryTest(@NotNull RexSubqueryTest rex, C ctx) { + return OperatorVisitor.super.visitSubqueryTest(rex, ctx); + } + + @Override + public Operator visitSpread(@NotNull RexSpread rex, C ctx) { + return OperatorVisitor.super.visitSpread(rex, ctx); + } + + @Override + public Operator visitTable(@NotNull RexTable rex, C ctx) { + return OperatorVisitor.super.visitTable(rex, ctx); + } + + @Override + public Operator visitVar(@NotNull RexVar rex, C ctx) { + return OperatorVisitor.super.visitVar(rex, ctx); + } + + /** + * Helper method to visit an operator and cast to the expected type. + */ + public final T visit(@NotNull Operator operator, C ctx, Class clazz) { + Operator o = visit(operator, ctx); + if (clazz.isInstance(o)) { + return clazz.cast(o); + } + return onError(o, clazz); + } + + /** + * Helper method to visit a list of operators and return a new list if any operator was rewritten. + * Using this will drastically reduce rebuilds since a new list is created ONLY IF necessary. + * Doing .stream().map().collect() will always create a new list, even if no operators were rewritten. + */ + public final List visitAll(List objects, C ctx, Mapper mapper) { + if (objects.isEmpty()) { + return objects; + } + boolean diff = false; + List mapped = new ArrayList<>(objects.size()); + for (T o : objects) { + T t = mapper.apply(o, ctx); + mapped.add(t); + diff |= o != t; + } + return diff ? mapped : objects; + } + + /** + * Default error handling throws a ClassCastException. + */ + public T onError(Operator o, Class clazz) { + throw new ClassCastException("OperatorTransform expected " + clazz.getName() + ", found: " + o.getClass().getName()); + } + + /** + * @param + * @param + */ + public interface Mapper { + T apply(T op, C ctx); + } +} diff --git a/partiql-plan/src/main/java/org/partiql/plan/Visitor.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java similarity index 74% rename from partiql-plan/src/main/java/org/partiql/plan/Visitor.java rename to partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java index 7796d2bae..6f17e27f2 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Visitor.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java @@ -1,8 +1,45 @@ package org.partiql.plan; import org.jetbrains.annotations.NotNull; -import org.partiql.plan.rel.*; -import org.partiql.plan.rex.*; +import org.partiql.plan.rel.RelAggregate; +import org.partiql.plan.rel.RelCorrelate; +import org.partiql.plan.rel.RelDistinct; +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.RexCase; +import org.partiql.plan.rex.RexCast; +import org.partiql.plan.rex.RexCoalesce; +import org.partiql.plan.rex.RexDispatch; +import org.partiql.plan.rex.RexError; +import org.partiql.plan.rex.RexLit; +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. @@ -10,10 +47,10 @@ * @param Visit return type * @param Context parameter type */ -public interface Visitor { +public interface OperatorVisitor { default R defaultVisit(Operator operator, C ctx) { - for (Operator child : operator.getChildren()) { + for (Operator child : operator.getOperands()) { child.accept(this, ctx); } return defaultReturn(operator, ctx); @@ -31,6 +68,10 @@ default R visitAggregate(@NotNull RelAggregate rel, C ctx) { return defaultVisit(rel, ctx); } + default R visitCorrelate(@NotNull RelCorrelate rel, C ctx) { + return defaultVisit(rel, ctx); + } + default R visitDistinct(@NotNull RelDistinct rel, C ctx) { return defaultVisit(rel, ctx); } @@ -59,10 +100,6 @@ default R visitJoin(@NotNull RelJoin rel, C ctx) { return defaultVisit(rel, ctx); } - default R visitCorrelate(@NotNull RelCorrelate rel, C ctx) { - return defaultVisit(rel, ctx); - } - default R visitLimit(@NotNull RelLimit rel, C ctx) { return defaultVisit(rel, 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 0f51a0188..05585d61f 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import org.partiql.spi.function.Aggregation; @@ -24,14 +24,28 @@ public static RelAggregate create(@NotNull Rel input, @NotNull List mea } /** - * @return the input (child 0) + * @return new {@link Measure} instance + */ + @NotNull + public static Measure measure(@NotNull Aggregation agg, @NotNull List args, @NotNull Boolean distinct) { + return new Measure(agg, args, distinct); + } + + /** + * @return the input (operand 0) */ @NotNull public abstract Rel getInput(); + /** + * @return the measures (arg) + */ @NotNull public abstract List getMeasures(); + /** + * @return the groups (arg) + */ @NotNull public abstract List getGroups(); @@ -43,16 +57,28 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitAggregate(this, ctx); } + /** + * @return copy with new input. + */ + @NotNull + public abstract RelAggregate copy(@NotNull Rel input); + + /** + * @return copy with new input and args. + */ + @NotNull + public abstract RelAggregate copy(@NotNull Rel input, @NotNull List measures, @NotNull List groups); + /** * An aggregation function along with its arguments and any additional filters (e.g. DISTINCT). *
@@ -64,7 +90,7 @@ public static class Measure { private final List args; private final Boolean distinct; - public Measure(Aggregation agg, List args, Boolean distinct) { + private Measure(Aggregation agg, List args, Boolean distinct) { this.agg = agg; this.args = args; this.distinct = distinct; @@ -84,6 +110,11 @@ public List getArgs() { public Boolean isDistinct() { return distinct; } + + @NotNull + public Measure copy(@NotNull List args) { + return new Measure(agg, args, distinct); + } } private static class Impl extends RelAggregate { @@ -92,7 +123,7 @@ private static class Impl extends RelAggregate { private final List measures; private final List groups; - public Impl(Rel input, List measures, List groups) { + private Impl(Rel input, List measures, List groups) { this.input = input; this.measures = measures; this.groups = groups; @@ -115,5 +146,20 @@ public List getMeasures() { public List getGroups() { return groups; } + + @NotNull + @Override + public RelAggregate copy(@NotNull Rel input) { + return new Impl(input, measures, groups); + } + + /** + * @return copy with new input and args (non-final). + */ + @NotNull + @Override + public RelAggregate copy(@NotNull Rel input, @NotNull List measures, @NotNull List groups) { + return new Impl(input, measures, groups); + } } } 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 8c325e09c..85c592c9c 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 @@ -12,7 +12,7 @@ public abstract class RelBase implements Rel { private int tag = 0; private RelType type; - private List children; + private List operands; @Override public int getTag() { @@ -35,17 +35,17 @@ public final RelType getType() { @NotNull @Override - public final Operator getChild(int index) { - return children.get(index); + public final Operator getOperand(int index) { + return operands.get(index); } @NotNull @Override - public final List getChildren() { - if (children == null) { - children = children(); + public final List getOperands() { + if (operands == null) { + operands = operands(); } - return children; + return operands; } /** @@ -58,7 +58,7 @@ public final List getChildren() { /** * PROTECTED (could also be package private atm). * - * @return computed children. + * @return computed operands. */ - protected abstract List children(); + 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 e529a4f56..549e0e258 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 @@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.JoinType; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -24,13 +24,13 @@ public static RelCorrelate create(@NotNull Rel left, @NotNull Rel right, @NotNul } /** - * @return the left input (child 0) + * @return the left input (operand 0) */ @NotNull public abstract Rel getLeft(); /** - * @return the right input (child 1) + * @return the right input (operand 1) */ @NotNull public abstract Rel getRight(); @@ -46,24 +46,30 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getLeft(); Rel c1 = getRight(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitCorrelate(this, ctx); } + @NotNull + public abstract RelCorrelate copy(@NotNull Rel left, @NotNull Rel right); + + @NotNull + public abstract RelCorrelate copy(@NotNull Rel left, @NotNull Rel right, @NotNull JoinType joinType); + private static class Impl extends RelCorrelate { private final Rel left; private final Rel right; private final JoinType joinType; - public Impl(Rel left, Rel right, JoinType joinType) { + private Impl(Rel left, Rel right, JoinType joinType) { this.left = left; this.right = right; this.joinType = joinType; @@ -86,5 +92,17 @@ public Rel getRight() { public JoinType getJoinType() { return joinType; } + + @NotNull + @Override + public RelCorrelate copy(@NotNull Rel left, @NotNull Rel right) { + return new Impl(left, right, joinType); + } + + @NotNull + @Override + public RelCorrelate copy(@NotNull Rel left, @NotNull Rel right, @NotNull JoinType joinType) { + return new Impl(left, right, joinType); + } } } 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 14be950c4..eaa1d29cd 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,7 +20,7 @@ public static RelDistinct create(@NotNull Rel input) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); @@ -33,21 +33,27 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitDistinct(this, ctx); } + /** + * @return copy with new input. + */ + @NotNull + public abstract RelDistinct copy(@NotNull Rel input); + private static class Impl extends RelDistinct { private final Rel input; - public Impl(Rel input) { + private Impl(Rel input) { this.input = input; } @@ -56,5 +62,14 @@ public Impl(Rel input) { public Rel getInput() { return input; } + + /** + * @return copy with new input (non-final). + */ + @NotNull + @Override + public RelDistinct copy(@NotNull Rel input) { + return create(input); + } } } 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 8c3a8096a..0767756d7 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,13 +20,13 @@ public static RelExcept create(@NotNull Rel left, @NotNull Rel right, boolean al } /** - * @return left input (child 0) + * @return left input (operand 0) */ @NotNull public abstract Rel getLeft(); /** - * @return right input (child 1) + * @return right input (operand 1) */ @NotNull public abstract Rel getRight(); @@ -44,24 +44,36 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getLeft(); Rel c1 = getRight(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitExcept(this, ctx); } + /** + * @return copy with new inputs (non-final). + */ + @NotNull + public abstract RelExcept copy(@NotNull Rel left, @NotNull Rel right); + + /** + * @return copy with new inputs and args (non-final). + */ + @NotNull + public abstract RelExcept copy(@NotNull Rel left, @NotNull Rel right, boolean all); + private static class Impl extends RelExcept { private final Rel left; private final Rel right; private final boolean all; - public Impl(Rel left, Rel right, boolean all) { + private Impl(Rel left, Rel right, boolean all) { this.left = left; this.right = right; this.all = all; @@ -83,5 +95,23 @@ public Rel getRight() { public boolean isAll() { return all; } + + /** + * @return copy with new inputs (non-final). + */ + @NotNull + @Override + public RelExcept copy(@NotNull Rel left, @NotNull Rel right) { + return new Impl(left, right, all); + } + + /** + * @return copy with new inputs and args (non-final). + */ + @NotNull + @Override + public RelExcept copy(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } } } 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 a489a249b..c8d436f44 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 @@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Exclusion; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -21,13 +21,13 @@ public static RelExclude create(@NotNull Rel input, @NotNull List exc } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return exclusions (not an operator child). + * @return exclusions (not an operator operand). */ @NotNull public abstract List getExclusions(); @@ -40,22 +40,28 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitExclude(this, ctx); } + @NotNull + public abstract RelExclude copy(@NotNull Rel input); + + @NotNull + public abstract RelExclude copy(@NotNull Rel input, @NotNull List exclusions); + private static class Impl extends RelExclude { private final Rel input; private final List exclusions; - public Impl(Rel input, List exclusions) { + private Impl(Rel input, List exclusions) { this.input = input; this.exclusions = exclusions; } @@ -71,6 +77,17 @@ public Rel getInput() { public List getExclusions() { return exclusions; } - } + @NotNull + @Override + public RelExclude copy(@NotNull Rel input) { + return new Impl(input, exclusions); + } + + @NotNull + @Override + public RelExclude copy(@NotNull Rel input, @NotNull List exclusions) { + return new Impl(input, exclusions); + } + } } 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 9834958c6..fa073ec68 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,13 +21,13 @@ public static RelFilter create(@NotNull Rel input, @NotNull Rex predicate) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return predicate rex (child 1) + * @return predicate rex (operand 1) */ @NotNull public abstract Rex getPredicate(); @@ -40,23 +40,29 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); Rex c1 = getPredicate(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitFilter(this, ctx); } + @NotNull + public abstract RelFilter copy(@NotNull Rel input); + + @NotNull + public abstract RelFilter copy(@NotNull Rel input, @NotNull Rex predicate); + private static class Impl extends RelFilter { private final Rel input; private final Rex predicate; - public Impl(Rel input, Rex predicate) { + private Impl(Rel input, Rex predicate) { this.input = input; this.predicate = predicate; } @@ -72,5 +78,17 @@ public Rel getInput() { public Rex getPredicate() { return predicate; } + + @NotNull + @Override + public RelFilter copy(@NotNull Rel input) { + return new Impl(input, predicate); + } + + @NotNull + @Override + public RelFilter copy(@NotNull Rel input, @NotNull Rex predicate) { + return new Impl(input, predicate); + } } } 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 47e26bd57..cad60fec6 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,13 +20,13 @@ public static RelIntersect create(@NotNull Rel left, @NotNull Rel right, boolean } /** - * @return left rel (child 0) + * @return left rel (operand 0) */ @NotNull public abstract Rel getLeft(); /** - * @return right rel (child 1) + * @return right rel (operand 1) */ @NotNull public abstract Rel getRight(); @@ -44,24 +44,30 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getLeft(); Rel c1 = getRight(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitIntersect(this, ctx); } + @NotNull + public abstract RelIntersect copy(@NotNull Rel left, @NotNull Rel right); + + @NotNull + public abstract RelIntersect copy(@NotNull Rel left, @NotNull Rel right, boolean all); + private static class Impl extends RelIntersect { private final Rel left; private final Rel right; private final boolean all; - public Impl(Rel left, Rel right, boolean all) { + private Impl(Rel left, Rel right, boolean all) { this.left = left; this.right = right; this.all = all; @@ -83,5 +89,17 @@ public Rel getRight() { public boolean isAll() { return all; } + + @NotNull + @Override + public RelIntersect copy(@NotNull Rel left, @NotNull Rel right) { + return new Impl(left, right, all); + } + + @NotNull + @Override + public RelIntersect copy(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } } } 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 7c85bafdd..00eb12654 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,7 +21,7 @@ public static RelIterate create(@NotNull Rex rex) { } /** - * @return input rex (child 0) + * @return input rex (operand 0) */ @NotNull public abstract Rex getRex(); @@ -34,21 +34,24 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rex c0 = getRex(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitIterate(this, ctx); } + @NotNull + public abstract RelIterate copy(@NotNull Rex rex); + private static class Impl extends RelIterate { private final Rex rex; - public Impl(Rex rex) { + private Impl(Rex rex) { this.rex = rex; } @@ -57,5 +60,11 @@ public Impl(Rex rex) { public Rex getRex() { return rex; } + + @NotNull + @Override + public RelIterate copy(@NotNull Rex rex) { + return new Impl(rex); + } } } 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 857475ed3..01136b54b 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 @@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.JoinType; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -17,18 +17,18 @@ public abstract class RelJoin extends RelBase { * @return new {@link RelJoin} instance */ @NotNull - public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull JoinType joinType, @NotNull Rex condition) { - return new Impl(left, right, joinType, condition); + public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull Rex condition, @NotNull JoinType joinType) { + return new Impl(left, right, condition, joinType); } /** - * @return left input (child 0) + * @return left input (operand 0) */ @NotNull public abstract Rel getLeft(); /** - * @return right input (child 1) + * @return right input (operand 1) */ @NotNull public abstract Rel getRight(); @@ -40,7 +40,7 @@ public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull Joi public abstract JoinType getJoinType(); /** - * @return the join condition (child 2), or null if there is no condition. + * @return the join condition (operand 2), or null if there is no condition. */ @NotNull public abstract Rex getCondition(); @@ -52,7 +52,7 @@ protected RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getLeft(); Rel c1 = getRight(); Rex c2 = getCondition(); // can be null! @@ -60,22 +60,28 @@ protected final List children() { } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitJoin(this, ctx); } + @NotNull + public abstract RelJoin copy(@NotNull Rel left, @NotNull Rel right); + + @NotNull + public abstract RelJoin copy(@NotNull Rel left, @NotNull Rel right, @NotNull Rex condition, @NotNull JoinType joinType); + private static class Impl extends RelJoin { private final Rel left; private final Rel right; - private final JoinType joinType; private final Rex condition; + private final JoinType joinType; - public Impl(Rel left, Rel right, JoinType joinType, Rex condition) { + private Impl(Rel left, Rel right, Rex condition, JoinType joinType) { this.left = left; this.right = right; - this.joinType = joinType; this.condition = condition; + this.joinType = joinType; } @NotNull @@ -90,6 +96,12 @@ public Rel getRight() { return right; } + @NotNull + @Override + public Rex getCondition() { + return condition; + } + @NotNull @Override public JoinType getJoinType() { @@ -98,8 +110,14 @@ public JoinType getJoinType() { @NotNull @Override - public Rex getCondition() { - return condition; + public RelJoin copy(@NotNull Rel left, @NotNull Rel right) { + return new Impl(left, right, condition, joinType); + } + + @NotNull + @Override + public RelJoin copy(@NotNull Rel left, @NotNull Rel right, @NotNull Rex condition, @NotNull JoinType joinType) { + return new Impl(left, right, condition, joinType); } } } 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 22475108f..2f70b6b83 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,13 +21,13 @@ public static RelLimit create(@NotNull Rel input, @NotNull Rex limit) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return limit rex (child 1) + * @return limit rex (operand 1) */ @NotNull public abstract Rex getLimit(); @@ -40,23 +40,29 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); Rex c1 = getLimit(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitLimit(this, ctx); } + @NotNull + public abstract RelLimit copy(@NotNull Rel input); + + @NotNull + public abstract RelLimit copy(@NotNull Rel input, @NotNull Rex limit); + private static class Impl extends RelLimit { private final Rel input; private final Rex limit; - public Impl(Rel input, Rex limit) { + private Impl(Rel input, Rex limit) { this.input = input; this.limit = limit; } @@ -72,5 +78,17 @@ public Rel getInput() { public Rex getLimit() { return limit; } + + @NotNull + @Override + public RelLimit copy(@NotNull Rel input) { + return new Impl(input, limit); + } + + @NotNull + @Override + public RelLimit copy(@NotNull Rel input, @NotNull Rex limit) { + return new Impl(input, limit); + } } } 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 5cad94486..f3043b5e5 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,13 +21,13 @@ public static RelOffset create(@NotNull Rel input, @NotNull Rex offset) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return offset rex (child 1) + * @return offset rex (operand 1) */ @NotNull public abstract Rex getOffset(); @@ -40,23 +40,29 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); Rex c1 = getOffset(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitOffset(this, ctx); } + @NotNull + public abstract RelOffset copy(@NotNull Rel input); + + @NotNull + public abstract RelOffset copy(@NotNull Rel input, @NotNull Rex offset); + private static class Impl extends RelOffset { private final Rel input; private final Rex offset; - public Impl(Rel input, Rex offset) { + private Impl(Rel input, Rex offset) { this.input = input; this.offset = offset; } @@ -72,5 +78,17 @@ public Rel getInput() { public Rex getOffset() { return offset; } + + @NotNull + @Override + public RelOffset copy(@NotNull Rel input) { + return new Impl(input, offset); + } + + @NotNull + @Override + public RelOffset copy(@NotNull Rel input, @NotNull Rex offset) { + return new Impl(input, offset); + } } } 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 591e56677..4223039a8 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,13 +21,13 @@ public static RelProject create(Rel input, List projections) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return projection (not a child, it's a list not an operator). + * @return projection (not a operand, it's a list not an operator). */ @NotNull public abstract List getProjections(); @@ -40,22 +40,28 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitProject(this, ctx); } + @NotNull + public abstract RelProject copy(@NotNull Rel input); + + @NotNull + public abstract RelProject copy(@NotNull Rel input, @NotNull List projections); + private static class Impl extends RelProject { private final Rel input; private final List projections; - public Impl(Rel input, List projections) { + private Impl(Rel input, List projections) { this.input = input; this.projections = projections; } @@ -71,5 +77,17 @@ public Rel getInput() { public List getProjections() { return projections; } + + @NotNull + @Override + public RelProject copy(@NotNull Rel input) { + return new Impl(input, projections); + } + + @NotNull + @Override + public RelProject copy(@NotNull Rel input, @NotNull List projections) { + return new Impl(input, projections); + } } } 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 6be7c2b16..c9e1df5ca 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,7 +21,7 @@ public static RelScan create(@NotNull Rex rex) { } /** - * @return input rex (child 0) + * @return input rex (operand 0) */ @NotNull public abstract Rex getRex(); @@ -34,21 +34,24 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rex c0 = getRex(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitScan(this, ctx); } + @NotNull + public abstract RelScan copy(@NotNull Rex rex); + private static class Impl extends RelScan { private final Rex rex; - public Impl(Rex rex) { + private Impl(Rex rex) { this.rex = rex; } @@ -57,5 +60,11 @@ public Impl(Rex rex) { public Rex getRex() { return rex; } + + @NotNull + @Override + public RelScan copy(@NotNull Rex rex) { + return new Impl(rex); + } } } 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 f10eb8a5e..b901a974d 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 @@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Collation; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -34,22 +34,28 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitSort(this, ctx); } + @NotNull + public abstract RelSort copy(@NotNull Rel input); + + @NotNull + public abstract RelSort copy(@NotNull Rel input, @NotNull List collations); + private static class Impl extends RelSort { private final Rel input; private final List collations; - public Impl(Rel input, List collations) { + private Impl(Rel input, List collations) { this.input = input; this.collations = collations; } @@ -65,5 +71,17 @@ public Rel getInput() { public List getCollations() { return collations; } + + @NotNull + @Override + public RelSort copy(@NotNull Rel input) { + return new Impl(input, collations); + } + + @NotNull + @Override + public RelSort copy(@NotNull Rel input, @NotNull List collations) { + return new Impl(input, collations); + } } } 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 e60ac4215..711d4fca2 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -25,13 +25,13 @@ public static RelUnion create(@NotNull Rel left, @NotNull Rel right, boolean all public abstract boolean isAll(); /** - * @return left rel (child 0) + * @return left rel (operand 0) */ @NotNull public abstract Rel getLeft(); /** - * @return right rel (child 1) + * @return right rel (operand 1) */ @NotNull public abstract Rel getRight(); @@ -44,24 +44,30 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getLeft(); Rel c1 = getRight(); return List.of(c0, c1); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitUnion(this, ctx); } + @NotNull + public abstract RelUnion copy(@NotNull Rel left, @NotNull Rel right); + + @NotNull + public abstract RelUnion copy(@NotNull Rel left, @NotNull Rel right, boolean all); + private static class Impl extends RelUnion { private final Rel left; private final Rel right; private final boolean all; - public Impl(Rel left, Rel right, boolean all) { + private Impl(Rel left, Rel right, boolean all) { this.left = left; this.right = right; this.all = all; @@ -83,5 +89,17 @@ public Rel getLeft() { public Rel getRight() { return right; } + + @NotNull + @Override + public RelUnion copy(@NotNull Rel left, @NotNull Rel right) { + return new Impl(left, right, all); + } + + @NotNull + @Override + public RelUnion copy(@NotNull Rel left, @NotNull Rel right, boolean all) { + return new Impl(left, right, all); + } } } 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 45d12c452..53b49acb3 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rex.Rex; import java.util.List; @@ -21,7 +21,7 @@ public static RelUnpivot create(@NotNull Rex rex) { } /** - * @return input rex (child 0) + * @return input rex (operand 0) */ @NotNull public abstract Rex getRex(); @@ -34,21 +34,24 @@ protected final RelType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rex c0 = getRex(); return List.of(c0); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitUnpivot(this, ctx); } + @NotNull + public abstract RelUnpivot copy(@NotNull Rex rex); + private static class Impl extends RelUnpivot { private final Rex rex; - public Impl(Rex rex) { + private Impl(Rex rex) { this.rex = rex; } @@ -57,5 +60,11 @@ public Impl(Rex rex) { public Rex getRex() { return rex; } + + @NotNull + @Override + public RelUnpivot copy(@NotNull Rex rex) { + return new Impl(rex); + } } } 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 1baf206f8..c78531535 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -21,7 +21,7 @@ public static RexArray create(@NotNull List values) { } /** - * @return the values of the array, also the children. + * @return the values of the array, also the operands. */ @NotNull public abstract List getValues(); @@ -34,13 +34,13 @@ protected final RexType type() { @NotNull @Override - protected final List children() { + protected final List operands() { List varargs = getValues(); return List.copyOf(varargs); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitArray(this, ctx); } 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 4600545e0..a07fa2601 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.Collection; @@ -22,7 +22,7 @@ public static RexBag create(@NotNull Collection values) { } /** - * @return the values of the bag, also the children (unordered). + * @return the values of the bag, also the operands (unordered). */ @NotNull public abstract Collection getValues(); @@ -35,13 +35,13 @@ protected final RexType type() { @NotNull @Override - protected final List children() { + protected final List operands() { List varargs = getValues().stream().toList(); return List.copyOf(varargs); } @Override - public R accept(@NotNull Visitor visitor, C ctx) { + public R accept(@NotNull OperatorVisitor visitor, C ctx) { return visitor.visitBag(this, ctx); } 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 da5701465..879f88ef2 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 @@ -11,7 +11,7 @@ public abstract class RexBase implements Rex { private int tag = 0; - private List children; + private List operands; private RexType type; @Override @@ -35,17 +35,17 @@ public final RexType getType() { @NotNull @Override - public final Operator getChild(int index) { - return children.get(index); + public final Operator getOperand(int index) { + return operands.get(index); } @NotNull @Override - public final List getChildren() { - if (children == null) { - children = children(); + public final List getOperands() { + if (operands == null) { + operands = operands(); } - return children; + return operands; } /** @@ -58,7 +58,7 @@ public final List getChildren() { /** * PROTECTED (could also be package private atm). * - * @return computed children. + * @return computed operands. */ - protected abstract List children(); + 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 ce1eb0e44..106662081 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.spi.function.Function; import java.util.List; @@ -35,13 +35,13 @@ protected RexType type() { } @Override - protected List children() { + protected List operands() { List varargs = getArgs(); return List.copyOf(varargs); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitCall(this, ctx); } 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 2258a0ce6..c4d358f5f 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 @@ -3,7 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -18,19 +18,19 @@ public static RexCase create(@Nullable Rex match, @NotNull List branches } /** - * @return the match expression, or {@code null} if none (child 0) + * @return the match expression, or {@code null} if none (operand 0) */ @Nullable public abstract Rex getMatch(); /** - * @return the list of branches (not children). + * @return the list of branches (not operands). */ @NotNull public abstract List getBranches(); /** - * @return the default expression, or {@code null} if none (child 1) + * @return the default expression, or {@code null} if none (operand 1) */ @Nullable public abstract Rex getDefault(); @@ -42,14 +42,14 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { Rex c0 = getMatch(); Rex c1 = getDefault(); return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitCase(this, ctx); } 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 c775ea870..f146c09cd 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -21,7 +21,7 @@ public static RexCast create(@NotNull Rex operand, @NotNull PType target) { } /** - * @return operand rex (child 0) + * @return operand rex (operand 0) */ @NotNull public abstract Rex getOperand(); @@ -38,12 +38,12 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitCast(this, ctx); } 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 dc91dcc65..b38415e99 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,7 +20,7 @@ public static RexCoalesce create(List args) { } /** - * @return the list of arguments (also the children). + * @return the list of arguments (also the operands). */ @NotNull public abstract List getArgs(); @@ -31,13 +31,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { List varargs = getArgs(); return List.copyOf(varargs); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitCoalesce(this, ctx); } 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 c83be1a5f..64e39f15d 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.spi.function.Function; import java.util.List; @@ -42,13 +42,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { List varargs = getArgs(); return List.copyOf(varargs); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitCallDynamic(this, ctx); } 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 9d000eeca..c52d3975d 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -27,12 +27,12 @@ protected RexType type() { } @Override - protected List children() { + protected List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitError(this, ctx); } 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 011faac30..2009dc309 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.spi.value.Datum; import java.util.List; @@ -30,12 +30,12 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitLit(this, ctx); } 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 5356c7391..b7d883af5 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,13 +20,13 @@ public static RexNullIf create(@NotNull Rex v1, @NotNull Rex v2) { } /** - * @return v1 rex (child 0) + * @return v1 rex (operand 0) */ @NotNull public abstract Rex getV1(); /** - * @return v2 rex (child 1) + * @return v2 rex (operand 1) */ @NotNull public abstract Rex getV2(); @@ -38,14 +38,14 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rex c0 = getV1(); Rex c1 = getV2(); return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitNullIf(this, ctx); } 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 24af36e1e..a669c17f0 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,13 +20,13 @@ public static RexPathIndex create(@NotNull Rex operand, @NotNull Rex index) { } /** - * @return operand rex (child 0) + * @return operand rex (operand 0) */ @NotNull public abstract Rex getOperand(); /** - * @return index rex (child 1) + * @return index rex (operand 1) */ public abstract Rex getIndex(); @@ -37,14 +37,14 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rex c0 = getOperand(); Rex c1 = getIndex(); return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitPathIndex(this, ctx); } 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 ec1ff61dc..8822d33af 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,13 +20,13 @@ public static RexPathKey create(@NotNull Rex operand, @NotNull Rex key) { } /** - * @return operand rex (child 0) + * @return operand rex (operand 0) */ @NotNull public abstract Rex getOperand(); /** - * @return key rex (child 1) + * @return key rex (operand 1) */ @NotNull public abstract Rex getKey(); @@ -38,14 +38,14 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { Rex c0 = getOperand(); Rex c1 = getKey(); return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitPathKey(this, ctx); } 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 89a48f713..e39d588d3 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import java.util.List; @@ -20,7 +20,7 @@ public static RexPathSymbol create(@NotNull Rex operand, @NotNull String symbol) } /** - * @return operand rex (child 0) + * @return operand rex (operand 0) */ @NotNull public abstract Rex getOperand(); @@ -38,13 +38,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rex c0 = getOperand(); return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitPathSymbol(this, ctx); } 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 97806a21e..69c4e1879 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -22,19 +22,19 @@ public static RexPivot create(@NotNull Rel input, @NotNull Rex key, @NotNull Rex } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return key rex (child 1) + * @return key rex (operand 1) */ @NotNull public abstract Rex getKey(); /** - * @return value rex (child 2) + * @return value rex (operand 2) */ @NotNull public abstract Rex getValue(); @@ -46,7 +46,7 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); Rex c1 = getKey(); Rex c2 = getValue(); @@ -54,7 +54,7 @@ protected final List children() { } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitPivot(this, ctx); } 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 52636adfb..c82519884 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -22,13 +22,13 @@ public static RexSelect create(@NotNull Rel input, @NotNull Rex constructor) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return constructor rex (child 1) + * @return constructor rex (operand 1) */ public abstract Rex getConstructor(); @@ -40,14 +40,14 @@ protected final RexType type() { @NotNull @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); Rex c1 = getConstructor(); return List.of(c0, c1); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSelect(this, ctx); } 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 57ca437ef..ecce82f38 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -21,7 +21,7 @@ public static RexSpread create(@NotNull List args) { } /** - * @return list of spread arguments (the children) + * @return list of spread arguments (the operands) */ public abstract List getArgs(); @@ -33,12 +33,12 @@ protected final RexType type() { @NotNull @Override - protected final List children() { + protected final List operands() { List varargs = getArgs().stream().toList(); return List.copyOf(varargs); } - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSpread(this, 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 d70696ec2..0f8aeee57 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -29,7 +29,7 @@ public static Field field(Rex key, Rex value) { } /** - * @return list of struct fields (NOT children) + * @return list of struct fields (NOT operands) */ @NotNull public abstract List getFields(); @@ -41,12 +41,12 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitStruct(this, ctx); } 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 a6e349f31..4a807ef47 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import java.util.List; @@ -21,7 +21,7 @@ public static RexSubquery create(@NotNull Rel input, @NotNull Rex constructor, b } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); @@ -40,13 +40,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSubquery(this, ctx); } 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 3cfcef706..7586ea2f8 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.spi.Enum; import org.partiql.types.PType; @@ -30,13 +30,13 @@ public static RexSubqueryComp create( } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return collection comparison arguments (not children). + * @return collection comparison arguments (not operands). */ @NotNull public abstract List getArgs(); @@ -60,13 +60,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSubqueryComp(this, ctx); } 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 d4cbf67ac..c460b2524 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.types.PType; @@ -22,13 +22,13 @@ public static RexSubqueryIn create(@NotNull Rel input, @NotNull List args) } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); /** - * @return collection comparison arguments (not children). + * @return collection comparison arguments (not operands). */ @NotNull public abstract List getArgs(); @@ -39,13 +39,13 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSubqueryIn(this, ctx); } 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 a25259347..af734c360 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.plan.rel.Rel; import org.partiql.spi.Enum; import org.partiql.types.PType; @@ -28,7 +28,7 @@ public static RexSubqueryTest create(@NotNull Rel input, @NotNull Test test) { } /** - * @return input rel (child 0) + * @return input rel (operand 0) */ @NotNull public abstract Rel getInput(); @@ -46,13 +46,13 @@ protected final RexType type() { } @Override - protected List children() { + protected List operands() { Rel c0 = getInput(); return List.of(c0); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitSubqueryTest(this, ctx); } 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 0c25ffbaf..a6085c80c 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.spi.catalog.Table; import java.util.List; @@ -32,12 +32,12 @@ protected final RexType type() { } @Override - protected final List children() { + protected final List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitTable(this, ctx); } 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 dd0f172a9..e36276686 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 @@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.plan.Operator; -import org.partiql.plan.Visitor; +import org.partiql.plan.OperatorVisitor; import org.partiql.types.PType; import java.util.List; @@ -31,12 +31,12 @@ public static RexVar create(int depth, int offset, PType type) { public abstract int getOffset(); @Override - protected final List children() { + protected final List operands() { return List.of(); } @Override - public R accept(Visitor visitor, C ctx) { + public R accept(OperatorVisitor visitor, C ctx) { return visitor.visitVar(this, ctx); } diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt index f5920e404..90882a9d5 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt @@ -54,13 +54,12 @@ import org.partiql.types.PType */ public interface Operators { - // ALL MEMBERS SHOULD BE @JvmStatic public companion object { /** * A singleton of the [Operators] with all the standard implementations. */ - @JvmStatic + @JvmField public val STANDARD: Operators = object : Operators {} } @@ -75,7 +74,7 @@ public interface Operators { * * @param input */ - public fun relAggregate( + public fun aggregate( input: Rel, measures: List, groups: List, @@ -89,7 +88,7 @@ public interface Operators { * @param joinType * @return */ - public fun relCorrelate( + public fun correlate( lhs: Rel, rhs: Rel, joinType: JoinType, @@ -101,7 +100,7 @@ public interface Operators { * @param input * @return */ - public fun relDistinct(input: Rel): RelDistinct = RelDistinct.create(input) + public fun distinct(input: Rel): RelDistinct = RelDistinct.create(input) /** * Create a [RelExcept] instance for EXCEPT [ALL|DISTINCT]. @@ -110,7 +109,7 @@ public interface Operators { * @param rhs * @return */ - public fun relExcept( + public fun except( lhs: Rel, rhs: Rel, all: Boolean, @@ -123,7 +122,7 @@ public interface Operators { * @param exclusions * @return */ - public fun relExclude(input: Rel, exclusions: List): RelExclude = RelExclude.create(input, exclusions) + public fun exclude(input: Rel, exclusions: List): RelExclude = RelExclude.create(input, exclusions) /** * Create a [RelFilter] instance. @@ -132,7 +131,7 @@ public interface Operators { * @param predicate * @return */ - public fun relFilter(input: Rel, predicate: Rex): RelFilter = RelFilter.create(input, predicate) + public fun filter(input: Rel, predicate: Rex): RelFilter = RelFilter.create(input, predicate) /** * Create a [RelIntersect] instance for INTERSECT [ALL|DISTINCT]. @@ -142,7 +141,7 @@ public interface Operators { * @param all * @return */ - public fun relIntersect( + public fun intersect( lhs: Rel, rhs: Rel, all: Boolean, @@ -154,7 +153,7 @@ public interface Operators { * @param rex * @return */ - public fun relIterate(rex: Rex): RelIterate = RelIterate.create(rex) + public fun iterate(rex: Rex): RelIterate = RelIterate.create(rex) /** * Create a [RelJoin] instance. @@ -165,12 +164,12 @@ public interface Operators { * @param type * @return */ - public fun relJoin( + public fun join( lhs: Rel, rhs: Rel, - type: JoinType, condition: Rex, - ): RelJoin = RelJoin.create(lhs, rhs, type, condition) + type: JoinType, + ): RelJoin = RelJoin.create(lhs, rhs, condition, type) /** * Create a [RelLimit] instance. @@ -179,7 +178,7 @@ public interface Operators { * @param limit * @return */ - public fun relLimit(input: Rel, limit: Rex): RelLimit = RelLimit.create(input, limit) + public fun limit(input: Rel, limit: Rex): RelLimit = RelLimit.create(input, limit) /** * Create a [RelLimit] instance. @@ -188,7 +187,7 @@ public interface Operators { * @param offset * @return */ - public fun relOffset(input: Rel, offset: Rex): RelOffset = RelOffset.create(input, offset) + public fun offset(input: Rel, offset: Rex): RelOffset = RelOffset.create(input, offset) /** * Create a [RelProject] instance. @@ -197,7 +196,7 @@ public interface Operators { * @param projections * @return */ - public fun relProject(input: Rel, projections: List): RelProject = RelProject.create(input, projections) + public fun project(input: Rel, projections: List): RelProject = RelProject.create(input, projections) /** * Create a [RelScan] instance. @@ -205,7 +204,7 @@ public interface Operators { * @param rex * @return */ - public fun relScan(rex: Rex): RelScan = RelScan.create(rex) + public fun scan(rex: Rex): RelScan = RelScan.create(rex) /** * Create a [RelSort] instance. @@ -214,7 +213,7 @@ public interface Operators { * @param collations * @return */ - public fun relSort(input: Rel, collations: List): RelSort = RelSort.create(input, collations) + public fun sort(input: Rel, collations: List): RelSort = RelSort.create(input, collations) /** * Create a [RelUnion] instance for UNION [ALL|DISTINCT]. @@ -223,15 +222,15 @@ public interface Operators { * @param rhs * @return */ - public fun relUnion(lhs: Rel, rhs: Rel, all: Boolean): RelUnion = RelUnion.create(lhs, rhs, all) + public fun union(lhs: Rel, rhs: Rel, all: Boolean): RelUnion = RelUnion.create(lhs, rhs, all) /** * Create a [RelUnpivot] instance. * - * @param input + * @param rex * @return */ - public fun relUnpivot(input: Rex): RelUnpivot = RelUnpivot.create(input) + public fun unpivot(rex: Rex): RelUnpivot = RelUnpivot.create(rex) // --- REX OPERATORS ----------------------------------------------------------------------------------------------- diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index a4e8d77f8..263b2696b 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -86,7 +86,7 @@ internal class PlanTransform(private val flags: Set) { override fun visitRelOpErr(node: org.partiql.planner.internal.ir.Rel.Op.Err, ctx: PType): Any { // Listener should have already received the error. This node is a dud. Registered error listeners should // have failed compilation already. - return factory.relScan(factory.rexError(ctx)) + return factory.scan(factory.rexError(ctx)) } // EXPRESSIONS @@ -252,7 +252,7 @@ internal class PlanTransform(private val flags: Set) { val input = visitRel(node.input, ctx) val calls = node.calls.map { visitRelOpAggregateCall(it, ctx) as AggregateCall } val groups = node.groups.map { visitRex(it, ctx) } - return factory.relAggregate(input, calls, groups) + return factory.aggregate(input, calls, groups) } override fun visitRelOpAggregateCallUnresolved(node: IRel.Op.Aggregate.Call.Unresolved, ctx: PType): Any { @@ -281,13 +281,13 @@ internal class PlanTransform(private val flags: Set) { IRel.Op.Join.Type.RIGHT -> JoinType.RIGHT IRel.Op.Join.Type.FULL -> JoinType.FULL } - return factory.relJoin(lhs, rhs, condition, type, lhsType, rhsType) + return factory.join(lhs, rhs, condition, type, lhsType, rhsType) } override fun visitRelOpExclude(node: IRel.Op.Exclude, ctx: PType): Any { val input = visitRel(node.input, ctx) val paths = node.paths.mapNotNull { visitRelOpExcludePath(it, ctx) } - return factory.relExclude(input, paths) + return factory.exclude(input, paths) } override fun visitRelOpExcludePath(node: IRel.Op.Exclude.Path, ctx: PType): Exclusion? { @@ -310,72 +310,72 @@ internal class PlanTransform(private val flags: Set) { override fun visitRelOpProject(node: IRel.Op.Project, ctx: PType): Any { val input = visitRel(node.input, ctx) val projections = node.projections.map { visitRex(it, ctx) } - return factory.relProject(input, projections) + return factory.project(input, projections) } override fun visitRelOpOffset(node: IRel.Op.Offset, ctx: PType): Any { val input = visitRel(node.input, ctx) val offset = visitRex(node.offset, ctx) - return factory.relOffset(input, offset) + return factory.offset(input, offset) } override fun visitRelOpLimit(node: IRel.Op.Limit, ctx: PType): Any { val input = visitRel(node.input, ctx) val limit = visitRex(node.limit, ctx) - return factory.relLimit(input, limit) + return factory.limit(input, limit) } override fun visitRelOpIntersect(node: IRel.Op.Intersect, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.relIntersect(lhs, rhs, isAll) + return factory.intersect(lhs, rhs, isAll) } override fun visitRelOpUnion(node: IRel.Op.Union, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.relUnion(lhs, rhs, isAll) + return factory.union(lhs, rhs, isAll) } override fun visitRelOpExcept(node: IRel.Op.Except, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.relExcept(lhs, rhs, isAll) + return factory.except(lhs, rhs, isAll) } override fun visitRelOpSort(node: IRel.Op.Sort, ctx: PType): Any { val input = visitRel(node.input, ctx) val collations = node.specs.map { collation(it) } - return factory.relSort(input, collations) + return factory.sort(input, collations) } override fun visitRelOpFilter(node: IRel.Op.Filter, ctx: PType): Any { val input = visitRel(node.input, ctx) val condition = visitRex(node.predicate, ctx) - return factory.relFilter(input, condition) + return factory.filter(input, condition) } override fun visitRelOpDistinct(node: IRel.Op.Distinct, ctx: PType): Any { val input = visitRel(node.input, ctx) - return factory.relDistinct(input) + return factory.distinct(input) } override fun visitRelOpUnpivot(node: IRel.Op.Unpivot, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.relUnpivot(input) + return factory.unpivot(input) } override fun visitRelOpScanIndexed(node: IRel.Op.ScanIndexed, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.relIterate(input) + return factory.iterate(input) } override fun visitRelOpScan(node: IRel.Op.Scan, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.relScan(input) + return factory.scan(input) } // HELPERS diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt similarity index 98% rename from partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt rename to partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt index 24419814c..3d8da9371 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt @@ -5,7 +5,7 @@ package org.partiql.planner import org.partiql.plan.Operation import org.partiql.plan.Operator import org.partiql.plan.Plan -import org.partiql.plan.Visitor +import org.partiql.plan.OperatorVisitor import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelCorrelate import org.partiql.plan.rel.RelDistinct @@ -51,7 +51,7 @@ import org.partiql.plan.rex.RexVar * * 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 : Visitor { +object PlanEquivalenceOperatorVisitor : OperatorVisitor { @JvmStatic public fun equals(p1: Plan, p2: Plan): Boolean = visitPlan(p1, p2) diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanTest.kt index edf5f02d1..91f4b8045 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanTest.kt @@ -128,7 +128,7 @@ class PlanTest { } private fun assertPlanEqual(actual: Plan, expected: Plan) { - assert(PlanEquivalenceVisitor.equals(actual, expected)) { + assert(PlanEquivalenceOperatorVisitor.equals(actual, expected)) { buildString { appendLine("plans were not equivalent") // TODO print diff From 7ad3549ae527e18550d5f9440e42857e308988bf Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 2 Dec 2024 15:57:36 -0800 Subject: [PATCH 09/19] Completes OperatorTransform and fix partiql-plan build --- .../internal/compiler/StandardCompiler.kt | 2 +- partiql-plan/api/partiql-plan.api | 1449 +++++++---------- partiql-plan/build.gradle.kts | 4 + .../org/partiql/plan/OperatorTransform.java | 277 +++- .../org/partiql/plan/OperatorVisitor.java | 8 +- .../main/java/org/partiql/plan/rel/Rel.java | 2 +- .../org/partiql/plan/rex/RexDispatch.java | 2 +- .../main/kotlin/org/partiql/plan/Operators.kt | 48 +- .../partiql/planner/internal/SqlPlanner.kt | 2 +- .../internal/transforms/PlanTransform.kt | 40 +- .../planner/PlanEquivalenceOperatorVisitor.kt | 4 +- .../internal/exclude/SubsumptionTest.kt | 2 +- 12 files changed, 926 insertions(+), 914 deletions(-) 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 8b78ae114..9eabf7129 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 @@ -339,7 +339,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { return ExprBag(values) } - override fun visitCallDynamic(rex: RexDispatch, ctx: Unit): ExprValue { + override fun visitDispatch(rex: RexDispatch, ctx: Unit): ExprValue { // Check candidate arity for uniformity var arity: Int = -1 val name = rex.getName() diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index 78f758078..78d1206d0 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -1,31 +1,25 @@ -public abstract interface class org/partiql/plan/AggregateCall { - public abstract fun getAgg ()Lorg/partiql/spi/function/Aggregation; - public abstract fun getArgs ()Ljava/util/List; - public abstract fun isDistinct ()Z -} - public abstract interface class org/partiql/plan/Collation { + public abstract fun getColumn ()Lorg/partiql/plan/rex/Rex; public abstract fun getNulls ()Lorg/partiql/plan/Collation$Nulls; public abstract fun getOrder ()Lorg/partiql/plan/Collation$Order; - public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; } -public final class org/partiql/plan/Collation$Nulls : java/lang/Enum { - public static final field FIRST Lorg/partiql/plan/Collation$Nulls; - public static final field LAST Lorg/partiql/plan/Collation$Nulls; - public static final field OTHER Lorg/partiql/plan/Collation$Nulls; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/Collation$Nulls; - public static fun values ()[Lorg/partiql/plan/Collation$Nulls; +public final class org/partiql/plan/Collation$Nulls : org/partiql/spi/Enum { + public static final field FIRST I + public static final field LAST I + public static final field UNKNOWN I + public static fun FIRST ()Lorg/partiql/plan/Collation$Order; + public static fun LAST ()Lorg/partiql/plan/Collation$Order; + public fun toString ()Ljava/lang/String; } -public final class org/partiql/plan/Collation$Order : java/lang/Enum { - public static final field ASC Lorg/partiql/plan/Collation$Order; - public static final field DESC Lorg/partiql/plan/Collation$Order; - public static final field OTHER Lorg/partiql/plan/Collation$Order; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/Collation$Order; - public static fun values ()[Lorg/partiql/plan/Collation$Order; +public final class org/partiql/plan/Collation$Order : org/partiql/spi/Enum { + public static final field ASC I + public static final field DESC I + public static final field UNKNOWN I + public static fun ASC ()Lorg/partiql/plan/Collation$Order; + public static fun DESC ()Lorg/partiql/plan/Collation$Order; + public fun toString ()Ljava/lang/String; } public final class org/partiql/plan/Exclusion { @@ -111,14 +105,16 @@ public final class org/partiql/plan/Exclusion$StructWildcard : org/partiql/plan/ public fun toString ()Ljava/lang/String; } -public final class org/partiql/plan/JoinType : java/lang/Enum { - public static final field FULL Lorg/partiql/plan/JoinType; - public static final field INNER Lorg/partiql/plan/JoinType; - public static final field LEFT Lorg/partiql/plan/JoinType; - public static final field RIGHT Lorg/partiql/plan/JoinType; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/JoinType; - public static fun values ()[Lorg/partiql/plan/JoinType; +public class org/partiql/plan/JoinType : org/partiql/spi/Enum { + public static final field FULL I + public static final field INNER I + public static final field LEFT I + public static final field RIGHT I + public static final field UNKNOWN I + public static fun FULL ()Lorg/partiql/plan/JoinType; + public static fun INNER ()Lorg/partiql/plan/JoinType; + public static fun LEFT ()Lorg/partiql/plan/JoinType; + public static fun RIGHT ()Lorg/partiql/plan/JoinType; } public abstract interface class org/partiql/plan/Operation { @@ -126,977 +122,776 @@ public abstract interface class org/partiql/plan/Operation { public abstract interface class org/partiql/plan/Operation$Query : org/partiql/plan/Operation { public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; - public abstract fun getType ()Lorg/partiql/plan/rex/RexType; -} - -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 getChild (I)V - public abstract fun getChildren ()Ljava/util/Collection; -} - -public final class org/partiql/plan/Operator$DefaultImpls { - public static fun getChild (Lorg/partiql/plan/Operator;I)V + 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 getOperands ()Ljava/util/List; + public abstract fun getTag ()I + public abstract fun setTag (I)V +} + +public abstract class org/partiql/plan/OperatorTransform : org/partiql/plan/OperatorVisitor { + public fun ()V + public fun (Lorg/partiql/plan/Operators;)V + public synthetic fun defaultReturn (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public fun defaultReturn (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun defaultVisit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public fun defaultVisit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun onError (Lorg/partiql/plan/Operator;Ljava/lang/Class;)Lorg/partiql/plan/Operator; + public final fun visit (Lorg/partiql/plan/Operator;Ljava/lang/Object;Ljava/lang/Class;)Lorg/partiql/plan/Operator; + public synthetic fun visitAggregate (Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitAggregate (Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitAggregateGroup (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Lorg/partiql/plan/rex/Rex; + public fun visitAggregateMeasure (Lorg/partiql/plan/rel/RelAggregate$Measure;Ljava/lang/Object;)Lorg/partiql/plan/rel/RelAggregate$Measure; + public final fun visitAll (Ljava/util/List;Ljava/lang/Object;Lorg/partiql/plan/OperatorTransform$Mapper;)Ljava/util/List; + public synthetic fun visitArray (Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitArray (Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitBag (Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitBag (Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitCall (Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCall (Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitCase (Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCase (Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitCaseBranch (Lorg/partiql/plan/rex/RexCase$Branch;Ljava/lang/Object;)Lorg/partiql/plan/rex/RexCase$Branch; + public synthetic fun visitCast (Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCast (Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitCoalesce (Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCoalesce (Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitCollation (Lorg/partiql/plan/Collation;Ljava/lang/Object;)Lorg/partiql/plan/Collation; + public synthetic fun visitCorrelate (Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCorrelate (Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitDispatch (Lorg/partiql/plan/rex/RexDispatch;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDispatch (Lorg/partiql/plan/rex/RexDispatch;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitDistinct (Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDistinct (Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitError (Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitError (Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitExcept (Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcept (Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitExclude (Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExclude (Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitExclusions (Lorg/partiql/plan/Exclusion;Ljava/lang/Object;)Lorg/partiql/plan/Exclusion; + public synthetic fun visitFilter (Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitFilter (Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitIntersect (Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIntersect (Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitIterate (Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIterate (Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitJoin (Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitJoin (Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitLimit (Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLimit (Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitLit (Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLit (Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitNullIf (Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitNullIf (Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitOffset (Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitOffset (Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitPathIndex (Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathIndex (Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitPathKey (Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathKey (Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitPathSymbol (Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathSymbol (Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitPivot (Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPivot (Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitProject (Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitProject (Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitProjection (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Lorg/partiql/plan/rex/Rex; + public final fun visitRel (Lorg/partiql/plan/rel/Rel;Ljava/lang/Object;)Lorg/partiql/plan/rel/Rel; + public final fun visitRex (Lorg/partiql/plan/rex/Rex;Ljava/lang/Object;)Lorg/partiql/plan/rex/Rex; + public synthetic fun visitScan (Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitScan (Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSelect (Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelect (Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSort (Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSort (Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSpread (Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSpread (Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitStruct (Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitStruct (Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public fun visitStructField (Lorg/partiql/plan/rex/RexStruct$Field;Ljava/lang/Object;)Lorg/partiql/plan/rex/RexStruct$Field; + public synthetic fun visitSubquery (Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubquery (Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSubqueryComp (Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryComp (Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSubqueryIn (Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryIn (Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitTable (Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitTable (Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitUnion (Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitUnion (Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitUnpivot (Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitUnpivot (Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Lorg/partiql/plan/Operator; + public synthetic fun visitVar (Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitVar (Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Lorg/partiql/plan/Operator; +} + +public abstract interface class org/partiql/plan/OperatorTransform$Mapper { + public abstract fun apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class org/partiql/plan/OperatorVisitor { + public abstract fun defaultReturn (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public fun defaultVisit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public fun visit (Lorg/partiql/plan/Operator;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitAggregate (Lorg/partiql/plan/rel/RelAggregate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitArray (Lorg/partiql/plan/rex/RexArray;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitBag (Lorg/partiql/plan/rex/RexBag;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCall (Lorg/partiql/plan/rex/RexCall;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCase (Lorg/partiql/plan/rex/RexCase;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCast (Lorg/partiql/plan/rex/RexCast;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCoalesce (Lorg/partiql/plan/rex/RexCoalesce;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitCorrelate (Lorg/partiql/plan/rel/RelCorrelate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDispatch (Lorg/partiql/plan/rex/RexDispatch;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitDistinct (Lorg/partiql/plan/rel/RelDistinct;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitError (Lorg/partiql/plan/rex/RexError;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExcept (Lorg/partiql/plan/rel/RelExcept;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitExclude (Lorg/partiql/plan/rel/RelExclude;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitFilter (Lorg/partiql/plan/rel/RelFilter;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIntersect (Lorg/partiql/plan/rel/RelIntersect;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitIterate (Lorg/partiql/plan/rel/RelIterate;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitJoin (Lorg/partiql/plan/rel/RelJoin;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLimit (Lorg/partiql/plan/rel/RelLimit;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitLit (Lorg/partiql/plan/rex/RexLit;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitNullIf (Lorg/partiql/plan/rex/RexNullIf;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitOffset (Lorg/partiql/plan/rel/RelOffset;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathIndex (Lorg/partiql/plan/rex/RexPathIndex;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathKey (Lorg/partiql/plan/rex/RexPathKey;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPathSymbol (Lorg/partiql/plan/rex/RexPathSymbol;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitPivot (Lorg/partiql/plan/rex/RexPivot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitProject (Lorg/partiql/plan/rel/RelProject;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitScan (Lorg/partiql/plan/rel/RelScan;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSelect (Lorg/partiql/plan/rex/RexSelect;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSort (Lorg/partiql/plan/rel/RelSort;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSpread (Lorg/partiql/plan/rex/RexSpread;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitStruct (Lorg/partiql/plan/rex/RexStruct;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubquery (Lorg/partiql/plan/rex/RexSubquery;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryComp (Lorg/partiql/plan/rex/RexSubqueryComp;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryIn (Lorg/partiql/plan/rex/RexSubqueryIn;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitTable (Lorg/partiql/plan/rex/RexTable;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitUnion (Lorg/partiql/plan/rel/RelUnion;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitUnpivot (Lorg/partiql/plan/rel/RelUnpivot;Ljava/lang/Object;)Ljava/lang/Object; + public fun visitVar (Lorg/partiql/plan/rex/RexVar;Ljava/lang/Object;)Ljava/lang/Object; +} + +public abstract interface class org/partiql/plan/Operators { + public static final field Companion Lorg/partiql/plan/Operators$Companion; + public static final field STANDARD Lorg/partiql/plan/Operators; + public abstract fun aggregate (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; + public abstract fun array (Ljava/util/List;)Lorg/partiql/plan/rex/RexArray; + public abstract fun bag (Ljava/util/Collection;)Lorg/partiql/plan/rex/RexBag; + public abstract fun call (Lorg/partiql/spi/function/Function$Instance;Ljava/util/List;)Lorg/partiql/plan/rex/RexCall; + public abstract fun caseWhen (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; + public abstract fun cast (Lorg/partiql/plan/rex/Rex;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexCast; + public abstract fun coalesce (Ljava/util/List;)Lorg/partiql/plan/rex/RexCoalesce; + public abstract fun correlate (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; + public abstract fun dispatch (Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rex/RexDispatch; + public abstract fun distinct (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; + public abstract fun error (Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexError; + public abstract fun except (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; + public abstract fun exclude (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; + public abstract fun filter (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; + public abstract fun intersect (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; + public abstract fun iterate (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; + public abstract fun join (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelJoin; + public abstract fun limit (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; + public abstract fun lit (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/rex/RexLit; + public abstract fun nullIf (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexNullIf; + public abstract fun offset (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; + public abstract fun pathIndex (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathIndex; + public abstract fun pathKey (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathKey; + public abstract fun pathSymbol (Lorg/partiql/plan/rex/Rex;Ljava/lang/String;)Lorg/partiql/plan/rex/RexPathSymbol; + public abstract fun pivot (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPivot; + public abstract fun project (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; + public abstract fun scan (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; + public abstract fun select (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexSelect; + public abstract fun sort (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; + public abstract fun spread (Ljava/util/List;)Lorg/partiql/plan/rex/RexSpread; + public abstract fun struct (Ljava/util/List;)Lorg/partiql/plan/rex/RexStruct; + public abstract fun subquery (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Z)Lorg/partiql/plan/rex/RexSubquery; + public abstract fun subqueryComp (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comparison;Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier;)Lorg/partiql/plan/rex/RexSubqueryComp; + public abstract fun subqueryIn (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rex/RexSubqueryIn; + public abstract fun subqueryTest (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/RexSubqueryTest$Test;)Lorg/partiql/plan/rex/RexSubqueryTest; + public abstract fun table (Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/rex/RexTable; + public abstract fun union (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; + public abstract fun unpivot (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; + public abstract fun variable (IILorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexVar; +} + +public final class org/partiql/plan/Operators$Companion { +} + +public final class org/partiql/plan/Operators$DefaultImpls { + public static fun aggregate (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; + public static fun array (Lorg/partiql/plan/Operators;Ljava/util/List;)Lorg/partiql/plan/rex/RexArray; + public static fun bag (Lorg/partiql/plan/Operators;Ljava/util/Collection;)Lorg/partiql/plan/rex/RexBag; + public static fun call (Lorg/partiql/plan/Operators;Lorg/partiql/spi/function/Function$Instance;Ljava/util/List;)Lorg/partiql/plan/rex/RexCall; + public static fun caseWhen (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; + public static fun cast (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexCast; + public static fun coalesce (Lorg/partiql/plan/Operators;Ljava/util/List;)Lorg/partiql/plan/rex/RexCoalesce; + public static fun correlate (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; + public static fun dispatch (Lorg/partiql/plan/Operators;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rex/RexDispatch; + public static fun distinct (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; + public static fun error (Lorg/partiql/plan/Operators;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexError; + public static fun except (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; + public static fun exclude (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; + public static fun filter (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; + public static fun intersect (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; + public static fun iterate (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; + public static fun join (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelJoin; + public static fun limit (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; + public static fun lit (Lorg/partiql/plan/Operators;Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/rex/RexLit; + public static fun nullIf (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexNullIf; + public static fun offset (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; + public static fun pathIndex (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathIndex; + public static fun pathKey (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathKey; + public static fun pathSymbol (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;Ljava/lang/String;)Lorg/partiql/plan/rex/RexPathSymbol; + public static fun pivot (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPivot; + public static fun project (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; + public static fun scan (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; + public static fun select (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexSelect; + public static fun sort (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; + public static fun spread (Lorg/partiql/plan/Operators;Ljava/util/List;)Lorg/partiql/plan/rex/RexSpread; + public static fun struct (Lorg/partiql/plan/Operators;Ljava/util/List;)Lorg/partiql/plan/rex/RexStruct; + public static fun subquery (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Z)Lorg/partiql/plan/rex/RexSubquery; + public static fun subqueryComp (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comparison;Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier;)Lorg/partiql/plan/rex/RexSubqueryComp; + public static fun subqueryIn (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rex/RexSubqueryIn; + public static fun subqueryTest (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/RexSubqueryTest$Test;)Lorg/partiql/plan/rex/RexSubqueryTest; + public static fun table (Lorg/partiql/plan/Operators;Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/rex/RexTable; + public static fun union (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; + public static fun unpivot (Lorg/partiql/plan/Operators;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; + public static fun variable (Lorg/partiql/plan/Operators;IILorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexVar; } public abstract interface class org/partiql/plan/Plan { - public abstract fun getOperation ()Lorg/partiql/plan/Operation; + public abstract fun getOperations ()Ljava/util/List; public abstract fun getVersion ()Lorg/partiql/plan/Version; } -public final class org/partiql/plan/Plan$DefaultImpls { - public static fun getVersion (Lorg/partiql/plan/Plan;)Lorg/partiql/plan/Version; -} - 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/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 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/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 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; - public abstract fun relAggregate (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; - public abstract fun relAggregateCall (Lorg/partiql/spi/function/Aggregation;Ljava/util/List;Z)Lorg/partiql/plan/AggregateCall; - public abstract fun relCorrelate (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelCorrelate; - public abstract fun relCorrelate (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; - public abstract fun relDistinct (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; - public abstract fun relExcept (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelExcept; - public abstract fun relExcept (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; - public abstract fun relExclude (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; - public abstract fun relFilter (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; - public abstract fun relIntersect (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelIntersect; - public abstract fun relIntersect (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; - public abstract fun relIterate (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; - public abstract fun relJoin (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelJoin; - public abstract fun relJoin (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;Lorg/partiql/plan/rel/RelType;Lorg/partiql/plan/rel/RelType;)Lorg/partiql/plan/rel/RelJoin; - public abstract fun relLimit (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; - public abstract fun relOffset (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; - public abstract fun relProject (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; - public abstract fun relScan (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; - public abstract fun relSort (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; - public abstract fun relUnion (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelUnion; - public abstract fun relUnion (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; - public abstract fun relUnpivot (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; - public abstract fun rexArray (Ljava/util/Collection;)Lorg/partiql/plan/rex/RexArray; - public abstract fun rexArray (Ljava/util/Collection;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexArray; - public abstract fun rexBag (Ljava/util/Collection;)Lorg/partiql/plan/rex/RexBag; - public abstract fun rexBag (Ljava/util/Collection;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexBag; - public abstract fun rexCall (Lorg/partiql/spi/function/Function$Instance;Ljava/util/List;)Lorg/partiql/plan/rex/RexCall; - public abstract fun rexCallDynamic (Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rex/RexCallDynamic; - public abstract fun rexCase (Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; - public abstract fun rexCase (Ljava/util/List;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCase; - public abstract fun rexCase (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; - public abstract fun rexCase (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCase; - public abstract fun rexCast (Lorg/partiql/plan/rex/Rex;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexCast; - public abstract fun rexCoalesce (Ljava/util/List;)Lorg/partiql/plan/rex/RexCoalesce; - public abstract fun rexCoalesce (Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCoalesce; - public abstract fun rexError (Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexError; - public abstract fun rexLit (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/rex/RexLit; - public abstract fun rexNullIf (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexNullIf; - public abstract fun rexPathIndex (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathIndex; - public abstract fun rexPathIndex (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathIndex; - public abstract fun rexPathKey (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathKey; - public abstract fun rexPathKey (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathKey; - public abstract fun rexPathSymbol (Lorg/partiql/plan/rex/Rex;Ljava/lang/String;)Lorg/partiql/plan/rex/RexPathSymbol; - public abstract fun rexPathSymbol (Lorg/partiql/plan/rex/Rex;Ljava/lang/String;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathSymbol; - public abstract fun rexPivot (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPivot; - public abstract fun rexSelect (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexSelect; - public abstract fun rexSpread (Ljava/util/List;)Lorg/partiql/plan/rex/RexSpread; - public abstract fun rexSpread (Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexSpread; - public abstract fun rexStruct (Ljava/util/List;)Lorg/partiql/plan/rex/RexStruct; - public abstract fun rexStruct (Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexStruct; - public abstract fun rexSubquery (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Z)Lorg/partiql/plan/rex/RexSubquery; - public abstract fun rexSubqueryComp (Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comp;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryComp; - public abstract fun rexSubqueryComp (Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comp;Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryComp; - public abstract fun rexSubqueryIn (Ljava/util/List;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryIn; - public abstract fun rexSubqueryIn (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryIn; - public abstract fun rexSubqueryTest (Lorg/partiql/plan/rex/RexSubqueryTest$Test;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryTest; - public abstract fun rexTable (Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/rex/RexTable; - public abstract fun rexVar (II)Lorg/partiql/plan/rex/RexVar; - public abstract fun rexVar (IILorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexVar; -} - -public final class org/partiql/plan/builder/PlanFactory$Companion { - public final fun getSTANDARD ()Lorg/partiql/plan/builder/PlanFactory; -} - -public final class org/partiql/plan/builder/PlanFactory$DefaultImpls { - public static fun relAggregate (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; - public static fun relAggregateCall (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/spi/function/Aggregation;Ljava/util/List;Z)Lorg/partiql/plan/AggregateCall; - public static synthetic fun relAggregateCall$default (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/spi/function/Aggregation;Ljava/util/List;ZILjava/lang/Object;)Lorg/partiql/plan/AggregateCall; - public static fun relCorrelate (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelCorrelate; - public static fun relCorrelate (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; - public static fun relDistinct (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; - public static fun relExcept (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelExcept; - public static fun relExcept (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; - public static fun relExclude (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; - public static fun relFilter (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; - public static fun relIntersect (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelIntersect; - public static fun relIntersect (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; - public static fun relIterate (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; - public static fun relJoin (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelJoin; - public static fun relJoin (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;Lorg/partiql/plan/rel/RelType;Lorg/partiql/plan/rel/RelType;)Lorg/partiql/plan/rel/RelJoin; - public static synthetic fun relJoin$default (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;Lorg/partiql/plan/rel/RelType;Lorg/partiql/plan/rel/RelType;ILjava/lang/Object;)Lorg/partiql/plan/rel/RelJoin; - public static fun relLimit (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; - public static fun relOffset (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; - public static fun relProject (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; - public static fun relScan (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; - public static fun relSort (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; - public static fun relUnion (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelUnion; - public static fun relUnion (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; - public static fun relUnpivot (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; - public static fun rexArray (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/Collection;)Lorg/partiql/plan/rex/RexArray; - public static fun rexArray (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/Collection;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexArray; - public static fun rexBag (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/Collection;)Lorg/partiql/plan/rex/RexBag; - public static fun rexBag (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/Collection;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexBag; - public static fun rexCall (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/spi/function/Function$Instance;Ljava/util/List;)Lorg/partiql/plan/rex/RexCall; - public static fun rexCallDynamic (Lorg/partiql/plan/builder/PlanFactory;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rex/RexCallDynamic; - public static fun rexCase (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; - public static fun rexCase (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCase; - public static fun rexCase (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; - public static fun rexCase (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCase; - public static fun rexCast (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexCast; - public static fun rexCoalesce (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;)Lorg/partiql/plan/rex/RexCoalesce; - public static fun rexCoalesce (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexCoalesce; - public static fun rexError (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexError; - public static fun rexLit (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/rex/RexLit; - public static fun rexNullIf (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexNullIf; - public static fun rexPathIndex (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathIndex; - public static fun rexPathIndex (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathIndex; - public static fun rexPathKey (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathKey; - public static fun rexPathKey (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathKey; - public static fun rexPathSymbol (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Ljava/lang/String;)Lorg/partiql/plan/rex/RexPathSymbol; - public static fun rexPathSymbol (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Ljava/lang/String;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexPathSymbol; - public static fun rexPivot (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPivot; - public static fun rexSelect (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexSelect; - public static fun rexSpread (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;)Lorg/partiql/plan/rex/RexSpread; - public static fun rexSpread (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexSpread; - public static fun rexStruct (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;)Lorg/partiql/plan/rex/RexStruct; - public static fun rexStruct (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexStruct; - public static fun rexSubquery (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Z)Lorg/partiql/plan/rex/RexSubquery; - public static fun rexSubqueryComp (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comp;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryComp; - public static fun rexSubqueryComp (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comp;Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryComp; - public static fun rexSubqueryIn (Lorg/partiql/plan/builder/PlanFactory;Ljava/util/List;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryIn; - public static fun rexSubqueryIn (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryIn; - public static fun rexSubqueryTest (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/plan/rex/RexSubqueryTest$Test;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rex/RexSubqueryTest; - public static fun rexTable (Lorg/partiql/plan/builder/PlanFactory;Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/rex/RexTable; - public static fun rexVar (Lorg/partiql/plan/builder/PlanFactory;II)Lorg/partiql/plan/rex/RexVar; - public static fun rexVar (Lorg/partiql/plan/builder/PlanFactory;IILorg/partiql/plan/rex/RexType;)Lorg/partiql/plan/rex/RexVar; -} - -public final class org/partiql/plan/builder/RelBuilder { - public static final field Companion Lorg/partiql/plan/builder/RelBuilder$Companion; - public synthetic fun (Lorg/partiql/plan/builder/RelBuilder$Builder;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun aggregate (Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/builder/RelBuilder; - public final fun build ()Lorg/partiql/plan/rel/Rel; - public final fun build (Lorg/partiql/plan/builder/PlanFactory;)Lorg/partiql/plan/rel/Rel; - public final fun distinct ()Lorg/partiql/plan/builder/RelBuilder; - public final fun except (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/builder/RelBuilder; - public final fun exclude (Ljava/util/List;)Lorg/partiql/plan/builder/RelBuilder; - public final fun filter (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun intersect (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public static final fun iterate (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun join (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun join (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/builder/RelBuilder; - public final fun join (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun join (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/builder/RelBuilder; - public final fun limit (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun offset (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun pivot (Lorg/partiql/plan/builder/RexBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun project (Ljava/util/List;)Lorg/partiql/plan/builder/RelBuilder; - public final fun project ([Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public static final fun scan (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun select (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun sort (Ljava/util/List;)Lorg/partiql/plan/builder/RelBuilder; - public final fun union (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/builder/RelBuilder; - public static final fun unpivot (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; -} - -public final class org/partiql/plan/builder/RelBuilder$Companion { - public final fun iterate (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun scan (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; - public final fun unpivot (Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RelBuilder; -} - -public final class org/partiql/plan/builder/RexBuilder { - public static final field Companion Lorg/partiql/plan/builder/RexBuilder$Companion; - public synthetic fun (Lorg/partiql/plan/builder/RexBuilder$Builder;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public static final fun array (Ljava/util/Collection;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun bag (Ljava/util/Collection;)Lorg/partiql/plan/builder/RexBuilder; - public final fun build ()Lorg/partiql/plan/rex/Rex; - public final fun build (Lorg/partiql/plan/builder/PlanFactory;)Lorg/partiql/plan/rex/Rex; - public final fun cast (Lorg/partiql/types/PType;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun coalesce (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun exists (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun iterate ()Lorg/partiql/plan/builder/RelBuilder; - public static final fun lit (I)Lorg/partiql/plan/builder/RexBuilder; - public static final fun lit (J)Lorg/partiql/plan/builder/RexBuilder; - public static final fun lit (Ljava/lang/String;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun lit (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun lit (Z)Lorg/partiql/plan/builder/RexBuilder; - public final fun path (I)Lorg/partiql/plan/builder/RexBuilder; - public final fun path (Ljava/lang/String;Z)Lorg/partiql/plan/builder/RexBuilder; - public static synthetic fun path$default (Lorg/partiql/plan/builder/RexBuilder;Ljava/lang/String;ZILjava/lang/Object;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun pivot (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun scan ()Lorg/partiql/plan/builder/RelBuilder; - public static final fun select (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun spread (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun struct (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun subquery (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun table (Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/builder/RexBuilder; - public static final fun unique (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun unpivot ()Lorg/partiql/plan/builder/RelBuilder; - public static final fun variable (I)Lorg/partiql/plan/builder/RexBuilder; - public static final fun variable (II)Lorg/partiql/plan/builder/RexBuilder; -} - -public final class org/partiql/plan/builder/RexBuilder$Companion { - public final fun array (Ljava/util/Collection;)Lorg/partiql/plan/builder/RexBuilder; - public final fun bag (Ljava/util/Collection;)Lorg/partiql/plan/builder/RexBuilder; - public final fun coalesce (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public final fun exists (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun lit (I)Lorg/partiql/plan/builder/RexBuilder; - public final fun lit (J)Lorg/partiql/plan/builder/RexBuilder; - public final fun lit (Ljava/lang/String;)Lorg/partiql/plan/builder/RexBuilder; - public final fun lit (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/builder/RexBuilder; - public final fun lit (Z)Lorg/partiql/plan/builder/RexBuilder; - public final fun pivot (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun select (Lorg/partiql/plan/builder/RelBuilder;Lorg/partiql/plan/builder/RexBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun spread (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public final fun struct (Ljava/util/List;)Lorg/partiql/plan/builder/RexBuilder; - public final fun subquery (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun table (Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/builder/RexBuilder; - public final fun unique (Lorg/partiql/plan/builder/RelBuilder;)Lorg/partiql/plan/builder/RexBuilder; - public final fun variable (I)Lorg/partiql/plan/builder/RexBuilder; - public final fun variable (II)Lorg/partiql/plan/builder/RexBuilder; -} - 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 final class org/partiql/plan/rel/Rel$DefaultImpls { - public static fun getChild (Lorg/partiql/plan/rel/Rel;I)V } -public abstract interface class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/Rel { - 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 class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelAggregate; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate; public abstract fun getGroups ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelAggregate$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelAggregate;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelAggregate;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; + public abstract fun getMeasures ()Ljava/util/List; + public static fun measure (Lorg/partiql/spi/function/Aggregation;Ljava/util/List;Ljava/lang/Boolean;)Lorg/partiql/plan/rel/RelAggregate$Measure; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; +} + +public class org/partiql/plan/rel/RelAggregate$Measure { + public fun copy (Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate$Measure; + public fun getAgg ()Lorg/partiql/spi/function/Aggregation; + public fun getArgs ()Ljava/util/List; + public fun isDistinct ()Ljava/lang/Boolean; +} + +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 getOperands ()Ljava/util/List; + public fun getTag ()I + public final fun getType ()Lorg/partiql/plan/rel/RelType; + protected abstract fun operands ()Ljava/util/List; + public fun setTag (I)V + protected abstract fun type ()Lorg/partiql/plan/rel/RelType; +} + +public abstract class org/partiql/plan/rel/RelCorrelate : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelCorrelate; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelCorrelate; public abstract fun getJoinType ()Lorg/partiql/plan/JoinType; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelCorrelate$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelCorrelate;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelCorrelate;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelCorrelate;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelCorrelate;)Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelDistinct : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelDistinct : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; + public static fun create (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelDistinct; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; - public abstract fun getType ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public final class org/partiql/plan/rel/RelDistinct$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelDistinct;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelDistinct;I)V - 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 -} - -public abstract interface class org/partiql/plan/rel/RelExcept : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelExcept : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelExcept; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelExcept; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; public abstract fun isAll ()Z - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelExcept$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelExcept;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelExcept;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelExcept;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelExcept;)Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelExclude : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelExclude : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelExclude; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelExclude; public abstract fun getExclusions ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelExclude$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelExclude;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelExclude;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelExclude;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelExclude;)Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelFilter : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelFilter : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelFilter; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelFilter; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getPredicate ()Lorg/partiql/plan/rex/Rex; - public abstract fun getType ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelFilter$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelFilter;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelFilter;I)V - 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 + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelIntersect : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelIntersect : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelIntersect; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelIntersect; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; public abstract fun isAll ()Z - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelIntersect$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelIntersect;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelIntersect;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelIntersect;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelIntersect;)Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelIterate : org/partiql/plan/rel/Rel { - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelIterate;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelIterate;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelIterate;)Z +public abstract class org/partiql/plan/rel/RelIterate : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; + public static fun create (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelIterate; + public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelJoin : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelJoin : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelJoin; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelJoin; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/JoinType;)Lorg/partiql/plan/rel/RelJoin; public abstract fun getCondition ()Lorg/partiql/plan/rex/Rex; public abstract fun getJoinType ()Lorg/partiql/plan/JoinType; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; - public abstract fun getLeftSchema ()Lorg/partiql/plan/rel/RelType; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; - public abstract fun getRightSchema ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelJoin$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelJoin;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelJoin;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelJoin;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelJoin;)Z + protected final fun operands ()Ljava/util/List; + protected fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelLimit : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelLimit : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelLimit; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelLimit; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getLimit ()Lorg/partiql/plan/rex/Rex; - public abstract fun getType ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public final class org/partiql/plan/rel/RelLimit$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelLimit;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelLimit;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelOffset : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelOffset; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelOffset; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getOffset ()Lorg/partiql/plan/rex/Rex; - public abstract fun getType ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public final class org/partiql/plan/rel/RelOffset$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelOffset;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelOffset;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelProject : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelProject; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelProject; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getProjections ()Ljava/util/List; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelProject$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelProject;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelProject;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public fun equals (Ljava/lang/Object;)Z - public fun getChild (I)V - public fun getChildren ()Ljava/util/Collection; - public fun getInput ()Lorg/partiql/plan/rel/Rel; - public fun getProjections ()Ljava/util/List; - public fun getType ()Lorg/partiql/plan/rel/RelType; - public fun hashCode ()I - public fun isOrdered ()Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelScan : org/partiql/plan/rel/Rel { - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelScan;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelScan;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelScan;)Z +public abstract class org/partiql/plan/rel/RelScan : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; + public static fun create (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelScan; + public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelSort; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rel/RelSort; public abstract fun getCollations ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; - public abstract fun getType ()Lorg/partiql/plan/rel/RelType; - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelSort$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelSort;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelSort;I)V - 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 + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } public abstract interface class org/partiql/plan/rel/RelType { public abstract fun getField (Ljava/lang/String;)Lorg/partiql/types/Field; - public abstract fun getFields ()Ljava/util/List; - public abstract fun getSize ()I -} - -public final class org/partiql/plan/rel/RelType$DefaultImpls { - public static fun getSize (Lorg/partiql/plan/rel/RelType;)I + public abstract fun getFieldSize ()I + public abstract fun getFields ()[Lorg/partiql/types/Field; + public abstract fun isOrdered ()Z } -public abstract interface class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/Rel { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;)Lorg/partiql/plan/rel/RelUnion; + public abstract fun copy (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rel/Rel;Z)Lorg/partiql/plan/rel/RelUnion; public abstract fun getLeft ()Lorg/partiql/plan/rel/Rel; public abstract fun getRight ()Lorg/partiql/plan/rel/Rel; public abstract fun isAll ()Z - public abstract fun isOrdered ()Z -} - -public final class org/partiql/plan/rel/RelUnion$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelUnion;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelUnion;I)V - 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/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 + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public final class org/partiql/plan/rel/RelUnpivot$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rel/RelUnpivot;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rel/RelUnpivot;I)V - public static fun getChildren (Lorg/partiql/plan/rel/RelUnpivot;)Ljava/util/Collection; - public static fun isOrdered (Lorg/partiql/plan/rel/RelUnpivot;)Z +public abstract class org/partiql/plan/rel/RelUnpivot : org/partiql/plan/rel/RelBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun copy (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; + public static fun create (Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rel/RelUnpivot; + public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rel/RelType; } public abstract interface class org/partiql/plan/rex/Rex : org/partiql/plan/Operator { public abstract fun getType ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/Rex$DefaultImpls { - public static fun getChild (Lorg/partiql/plan/rex/Rex;I)V -} - -public abstract interface class org/partiql/plan/rex/RexArray : org/partiql/plan/rex/Rex { - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexArray;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexArray;)Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexArray : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/util/List;)Lorg/partiql/plan/rex/RexArray; + public abstract fun getValues ()Ljava/util/List; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexBag : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexBag : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/util/Collection;)Lorg/partiql/plan/rex/RexBag; public abstract fun getValues ()Ljava/util/Collection; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexBag$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexBag;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexBag;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexBag;)Ljava/util/Collection; +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 getOperands ()Ljava/util/List; + public fun getTag ()I + public final fun getType ()Lorg/partiql/plan/rex/RexType; + protected abstract fun operands ()Ljava/util/List; + public fun setTag (I)V + protected abstract fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexCall : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexCall : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/spi/function/Function$Instance;Ljava/util/List;)Lorg/partiql/plan/rex/RexCall; public abstract fun getArgs ()Ljava/util/List; - public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getFunction ()Lorg/partiql/spi/function/Function$Instance; + protected fun operands ()Ljava/util/List; + protected fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexCall$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCall;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexCall;I)V - 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/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; - public abstract fun getName ()Ljava/lang/String; -} - -public final class org/partiql/plan/rex/RexCallDynamic$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCallDynamic;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexCallDynamic;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; public abstract fun getBranches ()Ljava/util/List; - public abstract fun getChildren ()Ljava/util/Collection; public abstract fun getDefault ()Lorg/partiql/plan/rex/Rex; public abstract fun getMatch ()Lorg/partiql/plan/rex/Rex; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexCase$Branch { - public abstract fun getCondition ()Lorg/partiql/plan/rex/Rex; - public abstract fun getResult ()Lorg/partiql/plan/rex/Rex; -} - -public final class org/partiql/plan/rex/RexCase$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCase;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexCase;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexCase;)Ljava/util/Collection; +public class org/partiql/plan/rex/RexCase$Branch { + public fun (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)V + public fun getCondition ()Lorg/partiql/plan/rex/Rex; + public fun getResult ()Lorg/partiql/plan/rex/Rex; } -public abstract interface class org/partiql/plan/rex/RexCast : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexCast : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexCast; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; public abstract fun getTarget ()Lorg/partiql/types/PType; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexCast$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexCast;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexCast;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexCoalesce : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/util/List;)Lorg/partiql/plan/rex/RexCoalesce; 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexCoalesce;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexCoalesce;)Ljava/util/Collection; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexError : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; - public abstract fun getType ()Lorg/partiql/plan/rex/RexType; -} - -public final class org/partiql/plan/rex/RexError$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexError;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexError;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexError;)Ljava/util/Collection; - public static fun getType (Lorg/partiql/plan/rex/RexError;)Lorg/partiql/plan/rex/RexType; +public abstract class org/partiql/plan/rex/RexDispatch : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/lang/String;Ljava/util/List;Ljava/util/List;)Lorg/partiql/plan/rex/RexDispatch; + public abstract fun getArgs ()Ljava/util/List; + public abstract fun getFunctions ()Ljava/util/List; + public abstract fun getName ()Ljava/lang/String; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexLit : org/partiql/plan/rex/Rex { - 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 abstract class org/partiql/plan/rex/RexError : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create ()Lorg/partiql/plan/rex/RexError; + protected fun operands ()Ljava/util/List; + protected fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexLit$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexLit;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexLit;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexLit;)Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexLit : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/spi/value/Datum;)Lorg/partiql/plan/rex/RexLit; + public abstract fun getDatum ()Lorg/partiql/spi/value/Datum; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexNullIf : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexNullIf : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexNullIf; public abstract fun getV1 ()Lorg/partiql/plan/rex/Rex; public abstract fun getV2 ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexNullIf$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexNullIf;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexNullIf;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexPathIndex : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathIndex; public abstract fun getIndex ()Lorg/partiql/plan/rex/Rex; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexPathIndex$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathIndex;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexPathIndex;I)V -} - -public abstract interface class org/partiql/plan/rex/RexPathKey : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexPathKey : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPathKey; public abstract fun getKey ()Lorg/partiql/plan/rex/Rex; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexPathKey$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathKey;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexPathKey;I)V -} - -public abstract interface class org/partiql/plan/rex/RexPathSymbol : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexPathSymbol : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rex/Rex;Ljava/lang/String;)Lorg/partiql/plan/rex/RexPathSymbol; public abstract fun getOperand ()Lorg/partiql/plan/rex/Rex; public abstract fun getSymbol ()Ljava/lang/String; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexPathSymbol$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPathSymbol;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexPathSymbol;I)V -} - -public abstract interface class org/partiql/plan/rex/RexPivot : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexPivot : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexPivot; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getKey ()Lorg/partiql/plan/rex/Rex; public abstract fun getValue ()Lorg/partiql/plan/rex/Rex; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexPivot$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexPivot;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexPivot;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexSelect : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexSelect; public abstract fun getConstructor ()Lorg/partiql/plan/rex/Rex; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexSelect$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSelect;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSelect;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexSpread : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/util/List;)Lorg/partiql/plan/rex/RexSpread; public abstract fun getArgs ()Ljava/util/List; - public abstract fun getChildren ()Ljava/util/Collection; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexSpread$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSpread;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSpread;I)V - 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexStruct : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Ljava/util/List;)Lorg/partiql/plan/rex/RexStruct; + public static fun field (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexStruct$Field; public abstract fun getFields ()Ljava/util/List; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexStruct$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexStruct;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexStruct;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexStruct;)Ljava/util/Collection; +public class org/partiql/plan/rex/RexStruct$Field { + public fun getKey ()Lorg/partiql/plan/rex/Rex; + public fun getValue ()Lorg/partiql/plan/rex/Rex; } -public final class org/partiql/plan/rex/RexStruct$Field { - public fun (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)V - public final fun getKey ()Lorg/partiql/plan/rex/Rex; - public final fun getValue ()Lorg/partiql/plan/rex/Rex; -} - -public abstract interface class org/partiql/plan/rex/RexSubquery : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun asScalar ()Z +public abstract class org/partiql/plan/rex/RexSubquery : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/Rex;Z)Lorg/partiql/plan/rex/RexSubquery; 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSubquery;I)V + public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; + public abstract fun isScalar ()Z + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexSubqueryComp : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; +public abstract class org/partiql/plan/rex/RexSubqueryComp : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;Lorg/partiql/plan/rex/RexSubqueryComp$Comparison;Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier;)Lorg/partiql/plan/rex/RexSubqueryComp; public abstract fun getArgs ()Ljava/util/List; - public abstract fun getComp ()Lorg/partiql/plan/rex/RexSubqueryComp$Comp; + public abstract fun getComparison ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getQuantifier ()Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public abstract fun getRel ()Lorg/partiql/plan/rel/Rel; -} - -public final class org/partiql/plan/rex/RexSubqueryComp$Comp : java/lang/Enum { - public static final field EQ Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field GE Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field GT Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field LE Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field LT Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field NE Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static final field OTHER Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/rex/RexSubqueryComp$Comp; - public static fun values ()[Lorg/partiql/plan/rex/RexSubqueryComp$Comp; -} - -public final class org/partiql/plan/rex/RexSubqueryComp$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubqueryComp;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSubqueryComp;I)V -} - -public final class org/partiql/plan/rex/RexSubqueryComp$Quantifier : java/lang/Enum { - public static final field ALL Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public static final field ANY Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public static final field OTHER Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public static final field SOME Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; - public static fun values ()[Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; -} - -public abstract interface class org/partiql/plan/rex/RexSubqueryIn : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; +} + +public class org/partiql/plan/rex/RexSubqueryComp$Comparison : org/partiql/spi/Enum { + public static final field EQ I + public static final field GE I + public static final field GT I + public static final field LE I + public static final field LT I + public static final field NE I + public static final field UNKNOWN I + public static fun EQ ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public static fun GE ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public static fun GT ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public static fun LE ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public static fun LT ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; + public static fun NE ()Lorg/partiql/plan/rex/RexSubqueryComp$Comparison; +} + +public class org/partiql/plan/rex/RexSubqueryComp$Quantifier : org/partiql/spi/Enum { + public static final field ALL I + public static final field ANY I + public static final field SOME I + public static final field UNKNOWN I + public static fun ALL ()Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; + public static fun ANY ()Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; + public static fun SOME ()Lorg/partiql/plan/rex/RexSubqueryComp$Quantifier; +} + +public abstract class org/partiql/plan/rex/RexSubqueryIn : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Ljava/util/List;)Lorg/partiql/plan/rex/RexSubqueryIn; 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSubqueryIn;I)V + public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public abstract interface class org/partiql/plan/rex/RexSubqueryTest : org/partiql/plan/rex/Rex { - 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 class org/partiql/plan/rex/RexSubqueryTest : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/plan/rel/Rel;Lorg/partiql/plan/rex/RexSubqueryTest$Test;)Lorg/partiql/plan/rex/RexSubqueryTest; + public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getTest ()Lorg/partiql/plan/rex/RexSubqueryTest$Test; + protected fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexSubqueryTest$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexSubqueryTest;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexSubqueryTest;I)V -} - -public final class org/partiql/plan/rex/RexSubqueryTest$Test : java/lang/Enum { - public static final field EXISTS Lorg/partiql/plan/rex/RexSubqueryTest$Test; - public static final field OTHER Lorg/partiql/plan/rex/RexSubqueryTest$Test; - public static final field UNIQUE Lorg/partiql/plan/rex/RexSubqueryTest$Test; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public static fun valueOf (Ljava/lang/String;)Lorg/partiql/plan/rex/RexSubqueryTest$Test; - public static fun values ()[Lorg/partiql/plan/rex/RexSubqueryTest$Test; +public class org/partiql/plan/rex/RexSubqueryTest$Test : org/partiql/spi/Enum { + public static final field EXISTS I + public static final field UNIQUE I + public static final field UNKNOWN I + public static fun EXISTS ()Lorg/partiql/plan/rex/RexSubqueryTest$Test; + public static fun UNIQUE ()Lorg/partiql/plan/rex/RexSubqueryTest$Test; } -public abstract interface class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (Lorg/partiql/spi/catalog/Table;)Lorg/partiql/plan/rex/RexTable; public abstract fun getTable ()Lorg/partiql/spi/catalog/Table; + protected final fun operands ()Ljava/util/List; + protected final fun type ()Lorg/partiql/plan/rex/RexType; } -public final class org/partiql/plan/rex/RexTable$DefaultImpls { - public static fun accept (Lorg/partiql/plan/rex/RexTable;Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexTable;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexTable;)Ljava/util/Collection; -} - -public final class org/partiql/plan/rex/RexType { - public static final field Companion Lorg/partiql/plan/rex/RexType$Companion; +public class org/partiql/plan/rex/RexType { public fun (Lorg/partiql/types/PType;)V - public static final fun dynamic ()Lorg/partiql/plan/rex/RexType; + public static fun dynamic ()Lorg/partiql/plan/rex/RexType; public fun equals (Ljava/lang/Object;)Z - public final fun getPType ()Lorg/partiql/types/PType; + public fun getPType ()Lorg/partiql/types/PType; public fun hashCode ()I public fun toString ()Ljava/lang/String; } -public final class org/partiql/plan/rex/RexType$Companion { - public final fun dynamic ()Lorg/partiql/plan/rex/RexType; -} - -public abstract interface class org/partiql/plan/rex/RexVar : org/partiql/plan/rex/Rex { - public abstract fun accept (Lorg/partiql/plan/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getChildren ()Ljava/util/Collection; +public abstract class org/partiql/plan/rex/RexVar : org/partiql/plan/rex/RexBase { + public fun ()V + public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun create (IILorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexVar; 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/Visitor;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getChild (Lorg/partiql/plan/rex/RexVar;I)V - public static fun getChildren (Lorg/partiql/plan/rex/RexVar;)Ljava/util/Collection; + protected final fun operands ()Ljava/util/List; } diff --git a/partiql-plan/build.gradle.kts b/partiql-plan/build.gradle.kts index d0c26e703..f64d7a965 100644 --- a/partiql-plan/build.gradle.kts +++ b/partiql-plan/build.gradle.kts @@ -31,6 +31,10 @@ tasks.shadowJar { configurations = listOf(project.configurations.shadow.get()) } +tasks.javadoc { + enabled = false +} + // Workaround for https://github.com/johnrengelman/shadow/issues/651 components.withType(AdhocComponentWithVariants::class.java).forEach { c -> c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) { diff --git a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java index 790457e36..ec496b717 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java @@ -4,16 +4,14 @@ import org.partiql.plan.rel.*; import org.partiql.plan.rel.RelAggregate.Measure; import org.partiql.plan.rex.*; +import org.partiql.plan.rex.RexCase.Branch; +import org.partiql.plan.rex.RexStruct.Field; import java.util.ArrayList; import java.util.List; /** * Operator transform is an abstract base visitor which recursively rewrites an operator tree. - *
- * Developer Note - * - - * - use the visitAll for rewriting collections as it's more efficient and won't trigger rewrites. */ public abstract class OperatorTransform implements OperatorVisitor { @@ -322,122 +320,335 @@ public Operator visitUnpivot(@NotNull RelUnpivot rel, C ctx) { @Override public Operator visitArray(@NotNull RexArray rex, C ctx) { - return OperatorVisitor.super.visitArray(rex, ctx); + // rewrite values + List values = rex.getValues(); + List values_new = visitAll(values, ctx, this::visitRex); + // rewrite array + if (values != values_new) { + return operators.array(values_new); + } + return rex; } @Override public Operator visitBag(@NotNull RexBag rex, C ctx) { - return OperatorVisitor.super.visitBag(rex, ctx); + // rewrite values (necessarily ascribes order) + List values = rex.getValues().stream().toList(); + List values_new = visitAll(values, ctx, this::visitRex); + // rewrite bag + if (values != values_new) { + return operators.bag(values_new); + } + return rex; } @Override public Operator visitCall(@NotNull RexCall rex, C ctx) { - return OperatorVisitor.super.visitCall(rex, ctx); + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite call + if (args != args_new) { + return operators.call(rex.getFunction(), args_new); + } + return rex; } @Override - public Operator visitCallDynamic(@NotNull RexDispatch rex, C ctx) { - return OperatorVisitor.super.visitCallDynamic(rex, ctx); + public Operator visitCase(@NotNull RexCase rex, C ctx) { + // rewrite match + Rex match = rex.getMatch(); + Rex match_new = (match != null) ? visit(match, ctx, Rex.class) : null; + // rewrite branches + List branches = rex.getBranches(); + List branches_new = visitAll(branches, ctx, this::visitCaseBranch); + // rewrite default + Rex default_ = rex.getDefault(); + Rex default_new = (default_ != null) ? visit(default_, ctx, Rex.class) : null; + // rewrite case + if (match != match_new || branches != branches_new || default_ != default_new) { + return operators.caseWhen(match_new, branches_new, default_new); + } + return rex; } - @Override - public Operator visitCase(@NotNull RexCase rex, C ctx) { - return OperatorVisitor.super.visitCase(rex, ctx); + @NotNull + public Branch visitCaseBranch(@NotNull Branch branch, C ctx) { + // rewrite condition + Rex condition = branch.getCondition(); + Rex condition_new = visit(condition, ctx, Rex.class); + // rewrite result + Rex result = branch.getResult(); + Rex result_new = visit(result, ctx, Rex.class); + // rewrite branch + if (condition != condition_new || result != result_new) { + return new Branch(condition_new, result_new); + } + return branch; } @Override public Operator visitCast(@NotNull RexCast rex, C ctx) { - return OperatorVisitor.super.visitCast(rex, ctx); + // rewrite operand + Rex operand = rex.getOperand(); + Rex operand_new = visit(operand, ctx, Rex.class); + // rewrite cast + if (operand != operand_new) { + return operators.cast(operand_new, rex.getTarget()); + } + return rex; } @Override public Operator visitCoalesce(@NotNull RexCoalesce rex, C ctx) { - return OperatorVisitor.super.visitCoalesce(rex, ctx); + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite coalesce + if (args != args_new) { + return operators.coalesce(args_new); + } + return rex; + } + + @Override + public Operator visitDispatch(@NotNull RexDispatch rex, C ctx) { + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite dispatch + if (args != args_new) { + return operators.dispatch(rex.getName(), rex.getFunctions(), args_new); + } + return rex; } @Override public Operator visitError(@NotNull RexError rex, C ctx) { - return OperatorVisitor.super.visitError(rex, ctx); + return rex; } @Override public Operator visitLit(@NotNull RexLit rex, C ctx) { - return OperatorVisitor.super.visitLit(rex, ctx); + return rex; } @Override public Operator visitNullIf(@NotNull RexNullIf rex, C ctx) { - return OperatorVisitor.super.visitNullIf(rex, ctx); + // rewrite v1 + Rex v1 = rex.getV1(); + Rex v1_new = visit(v1, ctx, Rex.class); + // rewrite v2 + Rex v2 = rex.getV2(); + Rex v2_new = visit(v2, ctx, Rex.class); + // rewrite nullif + if (v1 != v1_new || v2 != v2_new) { + return operators.nullIf(v1_new, v2_new); + } + return rex; } @Override public Operator visitPathIndex(@NotNull RexPathIndex rex, C ctx) { - return OperatorVisitor.super.visitPathIndex(rex, ctx); + // rewrite operand + Rex operand = rex.getOperand(); + Rex operand_new = visit(operand, ctx, Rex.class); + // rewrite index + Rex index = rex.getIndex(); + Rex index_new = visit(index, ctx, Rex.class); + // rewrite path index + if (operand != operand_new || index != index_new) { + return operators.pathIndex(operand_new, index_new); + } + return rex; } @Override public Operator visitPathKey(@NotNull RexPathKey rex, C ctx) { - return OperatorVisitor.super.visitPathKey(rex, ctx); + // rewrite operand + Rex operand = rex.getOperand(); + Rex operand_new = visit(operand, ctx, Rex.class); + // rewrite key + Rex key = rex.getKey(); + Rex key_new = visit(key, ctx, Rex.class); + // rewrite path key + if (operand != operand_new || key != key_new) { + return operators.pathKey(operand_new, key_new); + } + return rex; } @Override public Operator visitPathSymbol(@NotNull RexPathSymbol rex, C ctx) { - return OperatorVisitor.super.visitPathSymbol(rex, ctx); + // rewrite operand + Rex operand = rex.getOperand(); + Rex operand_new = visit(operand, ctx, Rex.class); + // rewrite path symbol + if (operand != operand_new) { + return operators.pathSymbol(operand_new, rex.getSymbol()); + } + return rex; } @Override public Operator visitPivot(@NotNull RexPivot rex, C ctx) { - return OperatorVisitor.super.visitPivot(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite key + Rex key = rex.getKey(); + Rex key_new = visit(key, ctx, Rex.class); + // rewrite value + Rex value = rex.getValue(); + Rex value_new = visit(value, ctx, Rex.class); + // rewrite pivot + if (input != input_new || key != key_new || value != value_new) { + return operators.pivot(input_new, key_new, value_new); + } + return rex; } @Override public Operator visitSelect(@NotNull RexSelect rex, C ctx) { - return OperatorVisitor.super.visitSelect(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite constructor + Rex constructor = rex.getConstructor(); + Rex constructor_new = visit(constructor, ctx, Rex.class); + // rewrite select + if (input != input_new || constructor != constructor_new) { + return operators.select(input_new, constructor_new); + } + return rex; } @Override public Operator visitStruct(@NotNull RexStruct rex, C ctx) { - return OperatorVisitor.super.visitStruct(rex, ctx); + // rewrite fields + List fields = rex.getFields(); + List fields_new = visitAll(fields, ctx, this::visitStructField); + // rewrite struct + if (fields != fields_new) { + return operators.struct(fields_new); + } + return rex; + } + + @NotNull + public Field visitStructField(@NotNull Field field, C ctx) { + // rewrite key + Rex key = field.getKey(); + Rex key_new = visit(key, ctx, Rex.class); + // rewrite value + Rex value = field.getValue(); + Rex value_new = visit(value, ctx, Rex.class); + // rewrite field + if (key != key_new || value != value_new) { + return RexStruct.field(key_new, value_new); + } + return field; } @Override public Operator visitSubquery(@NotNull RexSubquery rex, C ctx) { - return OperatorVisitor.super.visitSubquery(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite constructor + Rex constructor = rex.getConstructor(); + Rex constructor_new = visit(constructor, ctx, Rex.class); + // rewrite subquery + if (input != input_new || constructor != constructor_new) { + return operators.subquery(input_new, constructor_new, rex.isScalar()); + } + return rex; } @Override public Operator visitSubqueryComp(@NotNull RexSubqueryComp rex, C ctx) { - return OperatorVisitor.super.visitSubqueryComp(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite subquery comp + if (input != input_new) { + return operators.subqueryComp(input_new, args_new, rex.getComparison(), rex.getQuantifier()); + } + return rex; } @Override public Operator visitSubqueryIn(@NotNull RexSubqueryIn rex, C ctx) { - return OperatorVisitor.super.visitSubqueryIn(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite subquery in + if (input != input_new) { + return operators.subqueryIn(input_new, args_new); + } + return rex; } @Override public Operator visitSubqueryTest(@NotNull RexSubqueryTest rex, C ctx) { - return OperatorVisitor.super.visitSubqueryTest(rex, ctx); + // rewrite input + Rel input = rex.getInput(); + Rel input_new = visit(input, ctx, Rel.class); + // rewrite subquery test + if (input != input_new) { + return operators.subqueryTest(input_new, rex.getTest()); + } + return rex; } @Override public Operator visitSpread(@NotNull RexSpread rex, C ctx) { - return OperatorVisitor.super.visitSpread(rex, ctx); + // rewrite args + List args = rex.getArgs(); + List args_new = visitAll(args, ctx, this::visitRex); + // rewrite spread + if (args != args_new) { + return operators.spread(args_new); + } + return rex; } @Override public Operator visitTable(@NotNull RexTable rex, C ctx) { - return OperatorVisitor.super.visitTable(rex, ctx); + return rex; } @Override public Operator visitVar(@NotNull RexVar rex, C ctx) { - return OperatorVisitor.super.visitVar(rex, ctx); + return rex; + } + + /** + * Helper method to visit a rel and cast as rel. + */ + @NotNull + public final Rel visitRel(@NotNull Rel rel, C ctx) { + return visit(rel, ctx, Rel.class); + } + + /** + * Helper method to visit a rex and cast as rex. + */ + @NotNull + public final Rex visitRex(@NotNull Rex rex, C ctx) { + return visit(rex, ctx, Rex.class); } /** * Helper method to visit an operator and cast to the expected type. */ + @NotNull public final T visit(@NotNull Operator operator, C ctx, Class clazz) { Operator o = visit(operator, ctx); if (clazz.isInstance(o)) { @@ -451,7 +662,8 @@ public final T visit(@NotNull Operator operator, C ctx, Cla * Using this will drastically reduce rebuilds since a new list is created ONLY IF necessary. * Doing .stream().map().collect() will always create a new list, even if no operators were rewritten. */ - public final List visitAll(List objects, C ctx, Mapper mapper) { + @NotNull + public final List visitAll(@NotNull List objects, C ctx, @NotNull Mapper mapper) { if (objects.isEmpty()) { return objects; } @@ -468,7 +680,8 @@ public final List visitAll(List objects, C ctx, Mapper mapper) { /** * Default error handling throws a ClassCastException. */ - public T onError(Operator o, Class clazz) { + @NotNull + public T onError(@NotNull Operator o, @NotNull Class clazz) { throw new ClassCastException("OperatorTransform expected " + clazz.getName() + ", found: " + o.getClass().getName()); } 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 6f17e27f2..40368dc82 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorVisitor.java @@ -141,10 +141,6 @@ default R visitCall(@NotNull RexCall rex, C ctx) { return defaultVisit(rex, ctx); } - default R visitCallDynamic(@NotNull RexDispatch rex, C ctx) { - return defaultVisit(rex, ctx); - } - default R visitCase(@NotNull RexCase rex, C ctx) { return defaultVisit(rex, ctx); } @@ -157,6 +153,10 @@ default R visitCoalesce(@NotNull RexCoalesce rex, C ctx) { return defaultVisit(rex, ctx); } + default R visitDispatch(@NotNull RexDispatch rex, C ctx) { + return defaultVisit(rex, ctx); + } + default R visitError(@NotNull RexError rex, C ctx) { return defaultVisit(rex, ctx); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java index f4c152f0d..2d7608b1f 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java @@ -4,7 +4,7 @@ import org.partiql.plan.Operator; /** - * A Rel is an {@link Operator that produces a collection of tuples. + * A Rel is an {@link Operator} that produces a collection of tuples. */ public interface Rel extends Operator { 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 64e39f15d..b4e93b0e2 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 @@ -49,7 +49,7 @@ protected final List operands() { @Override public R accept(OperatorVisitor visitor, C ctx) { - return visitor.visitCallDynamic(this, ctx); + return visitor.visitDispatch(this, ctx); } private static class Impl extends RexDispatch { diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt index 90882a9d5..b52160861 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt @@ -240,7 +240,7 @@ public interface Operators { * @param values * @return */ - public fun rexArray(values: List): RexArray = RexArray.create(values) + public fun array(values: List): RexArray = RexArray.create(values) /** * Create a [RexBag] instance. @@ -248,7 +248,7 @@ public interface Operators { * @param values * @return */ - public fun rexBag(values: Collection): RexBag = RexBag.create(values) + public fun bag(values: Collection): RexBag = RexBag.create(values) /** * Create a [RexCall] instance. @@ -257,17 +257,17 @@ public interface Operators { * @param args * @return */ - public fun rexCall(function: Function.Instance, args: List): RexCall = RexCall.create(function, args) + public fun call(function: Function.Instance, args: List): RexCall = RexCall.create(function, args) /** - * Create a [RexCase] instance for a case-when with dynamic type. + * Create a [RexCase] instance for a case-when with dynamic type (case is a reserved word in Java). * * @param match * @param branches * @param default * @return */ - public fun rexCase(match: Rex?, branches: List, default: Rex?): RexCase = + public fun caseWhen(match: Rex?, branches: List, default: Rex?): RexCase = RexCase.create(match, branches, default) /** @@ -277,7 +277,7 @@ public interface Operators { * @param target * @return */ - public fun rexCast(operand: Rex, target: PType): RexCast = RexCast.create(operand, target) + public fun cast(operand: Rex, target: PType): RexCast = RexCast.create(operand, target) /** * Create a [RexCoalesce] instance. @@ -285,7 +285,7 @@ public interface Operators { * @param args * @return */ - public fun rexCoalesce(args: List): RexCoalesce = RexCoalesce.create(args) + public fun coalesce(args: List): RexCoalesce = RexCoalesce.create(args) /** * Create a [RexDispatch] instance. @@ -295,13 +295,13 @@ public interface Operators { * @param args * @return */ - public fun rexDispatch(name: String, functions: List, args: List): RexDispatch = + public fun dispatch(name: String, functions: List, args: List): RexDispatch = RexDispatch.create(name, functions, args) /** * Create a [RexError] instance. */ - public fun rexError(type: PType): RexError = RexError.create() + public fun error(type: PType): RexError = RexError.create() /** * Create a [RexLit] instance. @@ -309,12 +309,12 @@ public interface Operators { * @param value * @return */ - public fun rexLit(value: Datum): RexLit = RexLit.create(value) + public fun lit(value: Datum): RexLit = RexLit.create(value) /** * Create a [RexNullIf] instance. */ - public fun rexNullIf(v1: Rex, v2: Rex): RexNullIf = RexNullIf.create(v1, v2) + public fun nullIf(v1: Rex, v2: Rex): RexNullIf = RexNullIf.create(v1, v2) /** * Create a [RexPathIndex] instance. @@ -323,7 +323,7 @@ public interface Operators { * @param index * @return */ - public fun rexPathIndex(operand: Rex, index: Rex): RexPathIndex = RexPathIndex.create(operand, index) + public fun pathIndex(operand: Rex, index: Rex): RexPathIndex = RexPathIndex.create(operand, index) /** * Create a [RexPathKey] instance. @@ -332,7 +332,7 @@ public interface Operators { * @param key * @return */ - public fun rexPathKey(operand: Rex, key: Rex): RexPathKey = RexPathKey.create(operand, key) + public fun pathKey(operand: Rex, key: Rex): RexPathKey = RexPathKey.create(operand, key) /** * Create a [RexPathSymbol] instance. @@ -341,7 +341,7 @@ public interface Operators { * @param symbol * @return */ - public fun rexPathSymbol(operand: Rex, symbol: String): RexPathSymbol = RexPathSymbol.create(operand, symbol) + public fun pathSymbol(operand: Rex, symbol: String): RexPathSymbol = RexPathSymbol.create(operand, symbol) /** * Create a [RexPivot] instance. @@ -351,7 +351,7 @@ public interface Operators { * @param value * @return */ - public fun rexPivot(input: Rel, key: Rex, value: Rex): RexPivot = RexPivot.create(input, key, value) + public fun pivot(input: Rel, key: Rex, value: Rex): RexPivot = RexPivot.create(input, key, value) /** * Create a [RexSelect] instance. @@ -360,7 +360,7 @@ public interface Operators { * @param constructor * @return */ - public fun rexSelect(input: Rel, constructor: Rex): RexSelect = RexSelect.create(input, constructor) + public fun select(input: Rel, constructor: Rex): RexSelect = RexSelect.create(input, constructor) /** * Create a [RexSpread] instance with open struct type. @@ -368,7 +368,7 @@ public interface Operators { * @param args * @return */ - public fun rexSpread(args: List): RexSpread = RexSpread.create(args) + public fun spread(args: List): RexSpread = RexSpread.create(args) /** * Create a [RexStruct] instance. @@ -376,7 +376,7 @@ public interface Operators { * @param fields * @return */ - public fun rexStruct(fields: List): RexStruct = RexStruct.create(fields) + public fun struct(fields: List): RexStruct = RexStruct.create(fields) /** * Create a [RexSubquery] instance. @@ -386,7 +386,7 @@ public interface Operators { * @param input * @return */ - public fun rexSubquery(input: Rel, constructor: Rex, scalar: Boolean): RexSubquery = + public fun subquery(input: Rel, constructor: Rex, scalar: Boolean): RexSubquery = RexSubquery.create(input, constructor, scalar) /** @@ -398,7 +398,7 @@ public interface Operators { * @param quantifier * @return */ - public fun rexSubqueryComp( + public fun subqueryComp( input: Rel, args: List, comparison: RexSubqueryComp.Comparison, @@ -412,7 +412,7 @@ public interface Operators { * @param args * @return */ - public fun rexSubqueryIn(input: Rel, args: List): RexSubqueryIn = RexSubqueryIn.create(input, args) + public fun subqueryIn(input: Rel, args: List): RexSubqueryIn = RexSubqueryIn.create(input, args) /** * Create a [RexSubqueryTest] instance. @@ -421,7 +421,7 @@ public interface Operators { * @param test * @return */ - public fun rexSubqueryTest(input: Rel, test: RexSubqueryTest.Test): RexSubqueryTest = + public fun subqueryTest(input: Rel, test: RexSubqueryTest.Test): RexSubqueryTest = RexSubqueryTest.create(input, test) /** @@ -430,7 +430,7 @@ public interface Operators { * @param table * @return */ - public fun rexTable(table: Table): RexTable = RexTable.create(table) + public fun table(table: Table): RexTable = RexTable.create(table) /** * Create a [RexVar] instance (requires a type). @@ -440,5 +440,5 @@ public interface Operators { * @param type * @return */ - public fun rexVar(depth: Int, offset: Int, type: PType): RexVar = RexVar.create(depth, offset, type) + public fun variable(depth: Int, offset: Int, type: PType): RexVar = RexVar.create(depth, offset, type) } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt index e8d3b8d91..3cea887a4 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt @@ -63,7 +63,7 @@ internal class SqlPlanner( override fun getOperation(): Operation { return object : Operation.Query { override fun getRex(): Rex { - return Operators.STANDARD.rexError(PType.dynamic()) + return Operators.STANDARD.error(PType.dynamic()) } } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 263b2696b..0476573f3 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -80,13 +80,13 @@ internal class PlanTransform(private val flags: Set) { */ override fun visitRexOpErr(node: IRex.Op.Err, ctx: PType): Any { // Listener should have already received the error/warning. The listener should have already failed compilation. - return factory.rexError(ctx) + return factory.error(ctx) } override fun visitRelOpErr(node: org.partiql.planner.internal.ir.Rel.Op.Err, ctx: PType): Any { // Listener should have already received the error. This node is a dud. Registered error listeners should // have failed compilation already. - return factory.scan(factory.rexError(ctx)) + return factory.scan(factory.error(ctx)) } // EXPRESSIONS @@ -98,13 +98,13 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } val type = RexType(ctx) - return factory.rexSpread(args, type) + return factory.spread(args, type) } override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType): Any { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) - return factory.rexSelect(input, constructor) + return factory.select(input, constructor) } /** @@ -118,20 +118,20 @@ internal class PlanTransform(private val flags: Set) { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) val isScalar = node.coercion == IRex.Op.Subquery.Coercion.SCALAR - return factory.rexSubquery(input, constructor, isScalar) + return factory.subquery(input, constructor, isScalar) } override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType): Any { val input = visitRel(node.rel, ctx) val key = visitRex(node.key, ctx) val value = visitRex(node.value, ctx) - return factory.rexPivot(input, key, value) + return factory.pivot(input, key, value) } override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType): Any { val fields = node.fields.map { field(it) } val type = RexType(ctx) - return factory.rexStruct(fields, type) + return factory.struct(fields, type) } override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType): Any { @@ -147,20 +147,20 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } val type = RexType(ctx) - return factory.rexCoalesce(args, type) + return factory.coalesce(args, type) } override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType): Any { val value = visitRex(node.value, ctx) val nullifier = visitRex(node.nullifier, ctx) - return factory.rexNullIf(value, nullifier) + return factory.nullIf(value, nullifier) } override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType): Any { val branches = node.branches.map { branch(it) } val default = visitRex(node.default, ctx) val type = RexType(ctx) - return factory.rexCase(branches, default, type) + return factory.caseWhen(branches, default, type) } override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType): Any { @@ -174,7 +174,7 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType): Any { val fn = node.fn val args = node.args.map { visitRex(it, ctx) } - return factory.rexCall(fn, args) + return factory.call(fn, args) } override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType): Any { @@ -188,32 +188,32 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType): Any { val operand = visitRex(node.arg, ctx) val target = node.cast.target - return factory.rexCast(operand, target) + return factory.cast(operand, target) } override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType): Any { val operand = visitRex(node.root, ctx) val symbol = node.key val type = RexType(ctx) - return factory.rexPathSymbol(operand, symbol, type) + return factory.pathSymbol(operand, symbol, type) } override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType): Any { val operand = visitRex(node.root, ctx) val key = visitRex(node.key, ctx) val type = RexType(ctx) - return factory.rexPathKey(operand, key, type) + return factory.pathKey(operand, key, type) } override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType): Any { val operand = visitRex(node.root, ctx) val index = visitRex(node.key, ctx) val type = RexType(ctx) - return factory.rexPathIndex(operand, index, type) + return factory.pathIndex(operand, index, type) } override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType): Any { - return factory.rexTable(node.ref.table) + return factory.table(node.ref.table) } override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType): Any { @@ -221,7 +221,7 @@ internal class PlanTransform(private val flags: Set) { } override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType): Any { - return factory.rexVar( + return factory.variable( depth = node.depth, offset = node.ref, type = RexType(ctx), @@ -235,11 +235,11 @@ internal class PlanTransform(private val flags: Set) { // PartiQLValue. if (value is DecimalValue && ctx.code() == PType.DECIMAL) { return when (val dec = value.value) { - null -> factory.rexLit(Datum.nullValue(ctx)) - else -> factory.rexLit(Datum.decimal(dec, ctx.precision, ctx.scale)) + null -> factory.lit(Datum.nullValue(ctx)) + else -> factory.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) } } - return factory.rexLit(Datum.of(node.value)) + return factory.lit(Datum.of(node.value)) } // RELATION OPERATORS diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt index 3d8da9371..0cce6682b 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt @@ -155,8 +155,8 @@ object PlanEquivalenceOperatorVisitor : OperatorVisitor { return super.visitCall(rex, other) } - override fun visitCallDynamic(rex: RexDispatch, other: Any): Boolean { - return super.visitCallDynamic(rex, other) + override fun visitDispatch(rex: RexDispatch, other: Any): Boolean { + return super.visitDispatch(rex, other) } override fun visitCase(rex: RexCase, other: Any): Boolean { diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index e2689d30e..4c3b9488c 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -61,7 +61,7 @@ class SubsumptionTest { private val factory = Operators.STANDARD - private fun rexOpVar(depth: Int, offset: Int): RexVar = factory.rexVar(depth, offset) + private fun rexOpVar(depth: Int, offset: Int): RexVar = factory.variable(depth, offset) private val parameters = listOf( SubsumptionTC( From ae048a24551dbe6476c3ea2810aa0c27e8ffb4f3 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 2 Dec 2024 16:47:41 -0800 Subject: [PATCH 10/19] Fix planner assemble --- CHANGELOG.md | 2 +- docs/wiki/design/Architecture Design.md | 4 +- docs/wiki/documentation/Exceptions.md | 2 +- docs/wiki/documentation/Functions.md | 6 +- ...meric Data Type & Arithmetic Operations.md | 18 +-- docs/wiki/documentation/Window Functions.md | 2 +- .../Rewriter to Visitor Transform Guide.md | 2 +- partiql-ast/README.adoc | 2 +- .../internal/compiler/StandardCompiler.kt | 8 +- .../plan/{Operation.java => Action.java} | 6 +- .../main/java/org/partiql/plan/Collation.java | 8 +- .../org/partiql/plan/OperatorTransform.java | 2 +- .../src/main/java/org/partiql/plan/Plan.java | 8 +- .../main/java/org/partiql/plan/Version.java | 28 +++- .../java/org/partiql/plan/rex/RexCase.java | 7 +- .../partiql/planner/internal/SqlPlanner.kt | 48 ++++--- .../internal/transforms/PlanTransform.kt | 134 ++++++++---------- .../planner/PlanEquivalenceOperatorVisitor.kt | 12 +- .../planner/PlannerPErrorReportingTests.kt | 6 +- .../internal/exclude/SubsumptionTest.kt | 6 +- .../internal/typer/PartiQLTyperTestBase.kt | 6 +- .../internal/typer/PlanTyperTestsPorted.kt | 5 +- .../partiql/runner/executor/EvalExecutor.kt | 2 +- 23 files changed, 167 insertions(+), 157 deletions(-) rename partiql-plan/src/main/java/org/partiql/plan/{Operation.java => Action.java} (73%) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7072584..21dc6d8d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -821,7 +821,7 @@ breaking changes if migrating from v0.9.2. The breaking changes accidentally int `PlannerPipe.Builder.plannerEventCallback` for details. - Adds the following optimization passes, none of which are enabled by default: - `FilterScanToKeyLookupPass` which performs a simple optimization common to most databases: it converts a filter - predicate covering a table's complete primary key into a single get-by-key operation, thereby avoiding a full table + predicate covering a table's complete primary key into a single get-by-key action, thereby avoiding a full table scan. This may pass leave behind some useless `and` expressions if more `and` operands exist in the filter predicate other than primary key field equality expressions. - `RemoveUselessAndsPass`, which removes any useless `and` expressions introduced by the previous pass or by the diff --git a/docs/wiki/design/Architecture Design.md b/docs/wiki/design/Architecture Design.md index fa4bb01c8..b7f3ec467 100644 --- a/docs/wiki/design/Architecture Design.md +++ b/docs/wiki/design/Architecture Design.md @@ -17,7 +17,7 @@ We can illustrate this technique with a simple integer evaluator. Consider the ```java interface Operation { - /** Evaluates the operation against the given variables. */ + /** Evaluates the action against the given variables. */ int eval(Map env); } ``` @@ -73,7 +73,7 @@ interface IntValue { } interface Operation { - /** Evaluates the operation against the given variables. */ + /** Evaluates the action against the given variables. */ IntValue eval(Map env); } ``` diff --git a/docs/wiki/documentation/Exceptions.md b/docs/wiki/documentation/Exceptions.md index 981755447..71c026ecd 100644 --- a/docs/wiki/documentation/Exceptions.md +++ b/docs/wiki/documentation/Exceptions.md @@ -26,5 +26,5 @@ This is ​**not** a complete list. Also look at `org.partiql.lang.eval.Evaluati | Expected 1 argument for `functionName` instead of `n of args` | -- | 1 argument function is called with wrong arity | | Internal error, For input string: `string` | NumberFormatException | `CAST` from String is unsuccessful | | / by zero | ArithmeticException | Division by zero | -| `Not enough or Too many` arguments | -- | Wrong operation arity, e.g.: `1+1+` | +| `Not enough or Too many` arguments | -- | Wrong action arity, e.g.: `1+1+` | diff --git a/docs/wiki/documentation/Functions.md b/docs/wiki/documentation/Functions.md index fa9c6da2d..118b3f861 100644 --- a/docs/wiki/documentation/Functions.md +++ b/docs/wiki/documentation/Functions.md @@ -526,7 +526,7 @@ Header Purpose : Given a string, `s`, alter every upper case character in `s` to lower case. Any non-upper cased characters -remain unchanged. This operation does rely on the locale specified by the runtime configuration. +remain unchanged. This action does rely on the locale specified by the runtime configuration. The implementation, currently, relies on Java's [String.toLowerCase()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()) documentation. @@ -889,7 +889,7 @@ TO_STRING(`1969-07-20T20:18+08:00`, 'y-MM-dd''T''H:m:ssXXXXX') -- "1969-07-20T2 ### TO_TIMESTAMP -- since v0.1.0 -Given a string convert it to a timestamp. This is the inverse operation of [`TO_STRING`](#to_string) +Given a string convert it to a timestamp. This is the inverse action of [`TO_STRING`](#to_string) Signature @@ -995,7 +995,7 @@ Header Purpose : Given a string, `str`, alter every upper case character is `str` to lower case. Any non-lower cases characters remain -unchanged. This operation does rely on the locale specified by the runtime configuration. +unchanged. This action does rely on the locale specified by the runtime configuration. The implementation, currently, relies on Java's [String.toLowerCase()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()) documentation. diff --git a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md index eecacb1c4..802d4899e 100644 --- a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md +++ b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md @@ -17,13 +17,13 @@ PartiQL also support `Positive Infinity, Negative Infinity, and NaN` as `FLOAT` Unless otherwise specified, a mathematical operator: 1) takes a field name or expression of a numeric data type as operand -2) For Unary operation, the result type will be the same as the operand -3) For Binary operation, and the two operands are of the same type, the result will be the same as the type of operands. -4) For Binary operation, and the two operands are not of the same type, PartiQL will attempt to automatically coerce the operand. +2) For Unary action, the result type will be the same as the operand +3) For Binary action, and the two operands are of the same type, the result will be the same as the type of operands. +4) For Binary action, and the two operands are not of the same type, PartiQL will attempt to automatically coerce the operand. 5) If one or more operands are MISSING, then the result will be missing. else if one or more operands are null, then the result will be null. ### Overflow -With Type Inferencer and runtime type check enabled, Integer constraint will be honored and we check if the result of the mathematical operation exceeds the range that can be represented with the result type. +With Type Inferencer and runtime type check enabled, Integer constraint will be honored and we check if the result of the mathematical action exceeds the range that can be represented with the result type. Without type inferencer and runtime type check, the default runtime integer representation is `INT8`, and overflow can still happen if the result exceed the range that can be represented with the `INT8` type. @@ -32,16 +32,16 @@ When Permissive mode is enabled, overflowed values will be shown as `MISSING` in ### Conversion Map Operators involving multiple argument data types, such as Integer + Float, the conversion map determines the datatype PartiQL uses. Decimal has the highest numeric precedence, followed by float, and finally by INT. -If either operand has type of Decimal, then PartiQL will attempt to convert the operands implicitly to Decimal before performing the operation. -If none of the operand has Decimal type but any of the operands is Float, then PartiQL will attempt to convert the operands implicitly to Float before performing the operation. +If either operand has type of Decimal, then PartiQL will attempt to convert the operands implicitly to Decimal before performing the action. +If none of the operand has Decimal type but any of the operands is Float, then PartiQL will attempt to convert the operands implicitly to Float before performing the action. ### HonorParameter -If precision and scale matter, i.e. doing operation on monetary value, make sure to turn on the honorTypedOpParameters() option in Compile Option. +If precision and scale matter, i.e. doing action on monetary value, make sure to turn on the honorTypedOpParameters() option in Compile Option. The honorTypedOpParameters() determines how CAST and other typed operations behave. The default CompileOptions uses LEGACY which ignores the additional type arguments. Using the HONOR_PARAMETERS mode will take into account type parameters. ### Unary Plus: -Returns the operand without operation. +Returns the operand without action. Syntax : ` + expression` @@ -209,7 +209,7 @@ Example ``` ### Bitwise And -Performs a bitwise logical AND operation between two integer values. +Performs a bitwise logical AND action between two integer values. Syntax : `expression & expression` diff --git a/docs/wiki/documentation/Window Functions.md b/docs/wiki/documentation/Window Functions.md index f054ac70e..05d5d895d 100644 --- a/docs/wiki/documentation/Window Functions.md +++ b/docs/wiki/documentation/Window Functions.md @@ -186,7 +186,7 @@ LEAD(expr [, offset [, default]]) Purpose: Returns the value from a binding tuple at a given offset *after* the current binding tuple position in the window partition. -Note that `Lag` and `Lead` perform similar operation and have similar semantics, except for the fact that `Lag` looks for `x` rows prior to the current row and `Lead` looks for `x` rows after. +Note that `Lag` and `Lead` perform similar action and have similar semantics, except for the fact that `Lag` looks for `x` rows prior to the current row and `Lead` looks for `x` rows after. Arguments: * expr: diff --git a/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md b/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md index 88fd974d4..db9261adb 100644 --- a/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md +++ b/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md @@ -129,7 +129,7 @@ It's also worth noting that `innerRewriteDataManipulation` and the visitor trans fun transformDataManipulationEvaluationOrder(node: PartiqlAst.Statement.Dml): PartiqlAst.Statement { val from = node.from?.let { transformFromSource(it) } val where = node.where?.let { transformStatementDml_where(node) } - val dmlOperation = transformDmlOp(node.operation) + val dmlOperation = transformDmlOp(node.action) val metas = transformMetas(node.metas) return PartiqlAst.build { diff --git a/partiql-ast/README.adoc b/partiql-ast/README.adoc index 40935b00b..e8599de80 100644 --- a/partiql-ast/README.adoc +++ b/partiql-ast/README.adoc @@ -345,7 +345,7 @@ The Visitor pattern is the most widely misunderstood pattern in all of Design Pa The trouble starts with terminology. The pattern isn’t about “visiting”, and the “accept” method in it doesn’t conjure up any helpful imagery either. Many think the pattern has to do with traversing trees, which isn’t the case at all. We are going to use it on a set of classes that are tree-like, but that’s a coincidence. As you’ll see, the pattern works as well on a single object. -The Visitor pattern is really about approximating the functional style within an OOP language. It lets us add new columns to that table easily. We can define all of the behavior for a new operation on a set of types in one place, without having to touch the types themselves. It does this the same way we solve almost every problem in computer science: by adding a layer of indirection. +The Visitor pattern is really about approximating the functional style within an OOP language. It lets us add new columns to that table easily. We can define all of the behavior for a new action on a set of types in one place, without having to touch the types themselves. It does this the same way we solve almost every problem in computer science: by adding a layer of indirection. -- Robert Nystrom, Crafting Interpreters ____ 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 9eabf7129..b84ec0109 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 @@ -61,7 +61,7 @@ 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.Action import org.partiql.plan.Operator import org.partiql.plan.Plan import org.partiql.plan.OperatorVisitor @@ -126,7 +126,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { val visitor = _Operator_Visitor(mode) val operation = plan.getOperation() val statement: Statement = when { - operation is Operation.Query -> visitor.compile(operation) + operation is Action.Query -> visitor.compile(operation) else -> throw IllegalArgumentException("Only query statements are supported") } return statement @@ -151,10 +151,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { /** * Compile a query operation to a query statement. */ - fun compile(operation: Operation.Query) = object : Statement { + fun compile(action: Action.Query) = object : Statement { // compile the query root - private val root = compile(operation.getRex(), Unit).catch() + private val root = compile(action.getRex(), Unit).catch() // execute with no parameters override fun execute(): Datum = root.eval(Environment()) diff --git a/partiql-plan/src/main/java/org/partiql/plan/Operation.java b/partiql-plan/src/main/java/org/partiql/plan/Action.java similarity index 73% rename from partiql-plan/src/main/java/org/partiql/plan/Operation.java rename to partiql-plan/src/main/java/org/partiql/plan/Action.java index 2cdc8e5e4..4c6cdd2e1 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Operation.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Action.java @@ -4,14 +4,14 @@ import org.partiql.plan.rex.Rex; /** - * TODO DOCUMENTATION + * A PartiQL statement action within a plan. */ -public interface Operation { +public interface Action { /** * PartiQL Query Statement — i.e. SELECT-FROM */ - public interface Query extends Operation { + public interface Query extends Action { /** * Returns the root expression of the query. diff --git a/partiql-plan/src/main/java/org/partiql/plan/Collation.java b/partiql-plan/src/main/java/org/partiql/plan/Collation.java index f1006b62c..f6330897c 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Collation.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Collation.java @@ -79,13 +79,13 @@ private Nulls(int code) { public static final int LAST = 2; @NotNull - public static Order FIRST() { - return new Order(FIRST); + public static Nulls FIRST() { + return new Nulls(FIRST); } @NotNull - public static Order LAST() { - return new Order(LAST); + public static Nulls LAST() { + return new Nulls(LAST); } @Override diff --git a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java index ec496b717..3916442c7 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java @@ -382,7 +382,7 @@ public Branch visitCaseBranch(@NotNull Branch branch, C ctx) { Rex result_new = visit(result, ctx, Rex.class); // rewrite branch if (condition != condition_new || result != result_new) { - return new Branch(condition_new, result_new); + return RexCase.branch(condition_new, result_new); } return branch; } diff --git a/partiql-plan/src/main/java/org/partiql/plan/Plan.java b/partiql-plan/src/main/java/org/partiql/plan/Plan.java index 1ed8d1269..28a6beb3d 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Plan.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Plan.java @@ -13,11 +13,13 @@ public interface Plan { * @return version for serialization and debugging. */ @NotNull - public Version getVersion(); + default public Version getVersion() { + return Version.UNKNOWN(); + } /** - * @return operations to execute. + * @return statement actions to execute. */ @NotNull - public List getOperations(); + public List getActions(); } diff --git a/partiql-plan/src/main/java/org/partiql/plan/Version.java b/partiql-plan/src/main/java/org/partiql/plan/Version.java index 07fbbc77b..e67650672 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Version.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Version.java @@ -1,13 +1,29 @@ package org.partiql.plan; +import org.partiql.spi.Enum; + /** - * Marker interface for some version structure. + * A plan version. */ -public interface Version { +public class Version extends Enum { + + private Version(int code) { + super(code); + } + + public static final int UNKNOWN = 0; + + public static Version UNKNOWN() { + return new Version(UNKNOWN); + } - /** - * The only required method is toString. - */ @Override - public String toString(); + public String toString() { + int code = code(); + switch (code) { + case UNKNOWN: + default: + return "UNKNOWN(" + code + ")"; + } + } } 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 c4d358f5f..d2f97dffa 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 @@ -17,6 +17,11 @@ public static RexCase create(@Nullable Rex match, @NotNull List branches return new Impl(match, branches, def); } + @NotNull + public static Branch branch(@NotNull Rex condition, @NotNull Rex result) { + return new Branch(condition, result); + } + /** * @return the match expression, or {@code null} if none (operand 0) */ @@ -64,7 +69,7 @@ public static class Branch { @NotNull private final Rex result; - public Branch(@NotNull Rex condition, @NotNull Rex result) { + private Branch(@NotNull Rex condition, @NotNull Rex result) { this.condition = condition; this.result = result; } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt index 3cea887a4..a8b116aec 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt @@ -1,11 +1,11 @@ package org.partiql.planner.internal import org.partiql.ast.Statement -import org.partiql.plan.Operation -import org.partiql.plan.Plan +import org.partiql.plan.Action import org.partiql.plan.Operators -import org.partiql.plan.rex.Rex +import org.partiql.plan.Plan import org.partiql.planner.PartiQLPlanner +import org.partiql.planner.PartiQLPlanner.Result import org.partiql.planner.PartiQLPlannerPass import org.partiql.planner.internal.normalize.normalize import org.partiql.planner.internal.transforms.AstToPlan @@ -26,11 +26,10 @@ internal class SqlPlanner( private var flags: Set, ) : PartiQLPlanner { - public override fun plan( - statement: Statement, - session: Session, - ctx: Context, - ): PartiQLPlanner.Result { + /** + * Then default planner logic. + */ + override fun plan(statement: Statement, session: Session, ctx: Context): Result { try { // 0. Initialize the planning environment val env = Env(session) @@ -47,28 +46,33 @@ internal class SqlPlanner( val internal = org.partiql.planner.internal.ir.PartiQLPlan(typed) // 4. Assert plan has been resolved — translating to public API - var plan = PlanTransform(flags).transform(internal, ctx.getErrorListener()) + var plan = PlanTransform(flags).transform(internal, ctx.errorListener) // 5. Apply all passes for (pass in passes) { plan = pass.apply(plan, ctx) } - return PartiQLPlanner.Result(plan) + return Result(plan) } catch (e: PErrorListenerException) { throw e } catch (t: Throwable) { - val error = PError.INTERNAL_ERROR(PErrorKind.SEMANTIC(), null, t) - ctx.errorListener.report(error) - val plan = object : Plan { - override fun getOperation(): Operation { - return object : Operation.Query { - override fun getRex(): Rex { - return Operators.STANDARD.error(PType.dynamic()) - } - } - } - } - return PartiQLPlanner.Result(plan) + return catchAll(ctx, t) + } + } + + /** + * Create a plan with a query action and error node. + * + * @param t + * @return + */ + private fun catchAll(ctx: Context, t: Throwable): Result { + val error = PError.INTERNAL_ERROR(PErrorKind.SEMANTIC(), null, t) + ctx.errorListener.report(error) + val query = Action.Query { Operators.STANDARD.error(PType.dynamic()) } + val plan = object : Plan { + override fun getActions(): MutableList = mutableListOf(query) } + return Result(plan) } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 0476573f3..8331e3774 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -1,12 +1,13 @@ package org.partiql.planner.internal.transforms -import org.partiql.plan.AggregateCall import org.partiql.plan.Collation import org.partiql.plan.Exclusion import org.partiql.plan.JoinType +import org.partiql.plan.Action import org.partiql.plan.Operators import org.partiql.plan.Plan -import org.partiql.plan.rel.RelType +import org.partiql.plan.Version +import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexStruct @@ -17,7 +18,6 @@ import org.partiql.planner.internal.ir.SetQuantifier import org.partiql.planner.internal.ir.visitor.PlanBaseVisitor import org.partiql.spi.errors.PErrorListener import org.partiql.spi.value.Datum -import org.partiql.types.Field import org.partiql.types.PType import org.partiql.value.DecimalValue import org.partiql.value.PartiQLValueExperimental @@ -46,11 +46,10 @@ internal class PlanTransform(private val flags: Set) { val query = (internal.statement as IStatement.Query) val visitor = Visitor(listener, signal) val root = visitor.visitRex(query.root, query.root.type) + val action = Action.Query { root } // TODO replace with standard implementations (or just remove plan transform altogether when possible). return object : Plan { - override fun getOperation(): org.partiql.plan.Operation = object : org.partiql.plan.Operation.Query { - override fun getRex(): Rex = root - } + override fun getActions(): MutableList = mutableListOf(action) } } @@ -59,7 +58,7 @@ internal class PlanTransform(private val flags: Set) { private val signal: Boolean, ) : PlanBaseVisitor() { - private val factory = Operators.STANDARD + private val operators = Operators.STANDARD override fun defaultReturn(node: INode, ctx: PType): Any { TODO("Translation not supported for ${node::class.simpleName}") @@ -80,13 +79,13 @@ internal class PlanTransform(private val flags: Set) { */ override fun visitRexOpErr(node: IRex.Op.Err, ctx: PType): Any { // Listener should have already received the error/warning. The listener should have already failed compilation. - return factory.error(ctx) + return operators.error(ctx) } override fun visitRelOpErr(node: org.partiql.planner.internal.ir.Rel.Op.Err, ctx: PType): Any { // Listener should have already received the error. This node is a dud. Registered error listeners should // have failed compilation already. - return factory.scan(factory.error(ctx)) + return operators.scan(operators.error(ctx)) } // EXPRESSIONS @@ -98,13 +97,13 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } val type = RexType(ctx) - return factory.spread(args, type) + return operators.spread(args) } override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType): Any { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) - return factory.select(input, constructor) + return operators.select(input, constructor) } /** @@ -118,20 +117,20 @@ internal class PlanTransform(private val flags: Set) { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) val isScalar = node.coercion == IRex.Op.Subquery.Coercion.SCALAR - return factory.subquery(input, constructor, isScalar) + return operators.subquery(input, constructor, isScalar) } override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType): Any { val input = visitRel(node.rel, ctx) val key = visitRex(node.key, ctx) val value = visitRex(node.value, ctx) - return factory.pivot(input, key, value) + return operators.pivot(input, key, value) } override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType): Any { val fields = node.fields.map { field(it) } val type = RexType(ctx) - return factory.struct(fields, type) + return operators.struct(fields) } override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType): Any { @@ -147,20 +146,20 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } val type = RexType(ctx) - return factory.coalesce(args, type) + return operators.coalesce(args) } override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType): Any { val value = visitRex(node.value, ctx) val nullifier = visitRex(node.nullifier, ctx) - return factory.nullIf(value, nullifier) + return operators.nullIf(value, nullifier) } override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType): Any { val branches = node.branches.map { branch(it) } val default = visitRex(node.default, ctx) val type = RexType(ctx) - return factory.caseWhen(branches, default, type) + return operators.caseWhen(null, branches, default) } override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType): Any { @@ -174,7 +173,7 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType): Any { val fn = node.fn val args = node.args.map { visitRex(it, ctx) } - return factory.call(fn, args) + return operators.call(fn, args) } override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType): Any { @@ -188,32 +187,32 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType): Any { val operand = visitRex(node.arg, ctx) val target = node.cast.target - return factory.cast(operand, target) + return operators.cast(operand, target) } override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType): Any { val operand = visitRex(node.root, ctx) val symbol = node.key val type = RexType(ctx) - return factory.pathSymbol(operand, symbol, type) + return operators.pathSymbol(operand, symbol) } override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType): Any { val operand = visitRex(node.root, ctx) val key = visitRex(node.key, ctx) val type = RexType(ctx) - return factory.pathKey(operand, key, type) + return operators.pathKey(operand, key) } override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType): Any { val operand = visitRex(node.root, ctx) val index = visitRex(node.key, ctx) val type = RexType(ctx) - return factory.pathIndex(operand, index, type) + return operators.pathIndex(operand, index) } override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType): Any { - return factory.table(node.ref.table) + return operators.table(node.ref.table) } override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType): Any { @@ -221,11 +220,10 @@ internal class PlanTransform(private val flags: Set) { } override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType): Any { - return factory.variable( - depth = node.depth, - offset = node.ref, - type = RexType(ctx), - ) + val depth = node.depth + val offset = node.ref + val type = ctx + return operators.variable(depth, offset, type) } @OptIn(PartiQLValueExperimental::class) @@ -235,11 +233,11 @@ internal class PlanTransform(private val flags: Set) { // PartiQLValue. if (value is DecimalValue && ctx.code() == PType.DECIMAL) { return when (val dec = value.value) { - null -> factory.lit(Datum.nullValue(ctx)) - else -> factory.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) + null -> operators.lit(Datum.nullValue(ctx)) + else -> operators.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) } } - return factory.lit(Datum.of(node.value)) + return operators.lit(Datum.of(node.value)) } // RELATION OPERATORS @@ -250,9 +248,9 @@ internal class PlanTransform(private val flags: Set) { override fun visitRelOpAggregate(node: IRel.Op.Aggregate, ctx: PType): Any { val input = visitRel(node.input, ctx) - val calls = node.calls.map { visitRelOpAggregateCall(it, ctx) as AggregateCall } + val calls = node.calls.map { visitRelOpAggregateCall(it, ctx) as RelAggregate.Measure } val groups = node.groups.map { visitRex(it, ctx) } - return factory.aggregate(input, calls, groups) + return operators.aggregate(input, calls, groups) } override fun visitRelOpAggregateCallUnresolved(node: IRel.Op.Aggregate.Call.Unresolved, ctx: PType): Any { @@ -263,7 +261,7 @@ internal class PlanTransform(private val flags: Set) { val agg = node.agg.signature val args = node.args.map { visitRex(it, ctx) } val isDistinct = node.setq == SetQuantifier.DISTINCT - return factory.relAggregateCall(agg, args, isDistinct) + return RelAggregate.measure(agg, args, isDistinct) } override fun visitRelOpJoin(node: IRel.Op.Join, ctx: PType): Any { @@ -271,23 +269,19 @@ internal class PlanTransform(private val flags: Set) { val rhs = visitRel(node.rhs, ctx) val condition = visitRex(node.rex, ctx) - // TODO CLEANUP JOIN SCHEMA - val lhsType = toSchema(node.lhs.type) - val rhsType = toSchema(node.rhs.type) - - val type = when (node.type) { - IRel.Op.Join.Type.INNER -> JoinType.INNER - IRel.Op.Join.Type.LEFT -> JoinType.LEFT - IRel.Op.Join.Type.RIGHT -> JoinType.RIGHT - IRel.Op.Join.Type.FULL -> JoinType.FULL + val joinType = when (node.type) { + IRel.Op.Join.Type.INNER -> JoinType.INNER() + IRel.Op.Join.Type.LEFT -> JoinType.LEFT() + IRel.Op.Join.Type.RIGHT -> JoinType.RIGHT() + IRel.Op.Join.Type.FULL -> JoinType.FULL() } - return factory.join(lhs, rhs, condition, type, lhsType, rhsType) + return operators.join(lhs, rhs, condition, joinType) } override fun visitRelOpExclude(node: IRel.Op.Exclude, ctx: PType): Any { val input = visitRel(node.input, ctx) val paths = node.paths.mapNotNull { visitRelOpExcludePath(it, ctx) } - return factory.exclude(input, paths) + return operators.exclude(input, paths) } override fun visitRelOpExcludePath(node: IRel.Op.Exclude.Path, ctx: PType): Exclusion? { @@ -310,72 +304,72 @@ internal class PlanTransform(private val flags: Set) { override fun visitRelOpProject(node: IRel.Op.Project, ctx: PType): Any { val input = visitRel(node.input, ctx) val projections = node.projections.map { visitRex(it, ctx) } - return factory.project(input, projections) + return operators.project(input, projections) } override fun visitRelOpOffset(node: IRel.Op.Offset, ctx: PType): Any { val input = visitRel(node.input, ctx) val offset = visitRex(node.offset, ctx) - return factory.offset(input, offset) + return operators.offset(input, offset) } override fun visitRelOpLimit(node: IRel.Op.Limit, ctx: PType): Any { val input = visitRel(node.input, ctx) val limit = visitRex(node.limit, ctx) - return factory.limit(input, limit) + return operators.limit(input, limit) } override fun visitRelOpIntersect(node: IRel.Op.Intersect, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.intersect(lhs, rhs, isAll) + return operators.intersect(lhs, rhs, isAll) } override fun visitRelOpUnion(node: IRel.Op.Union, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.union(lhs, rhs, isAll) + return operators.union(lhs, rhs, isAll) } override fun visitRelOpExcept(node: IRel.Op.Except, ctx: PType): Any { val lhs = visitRel(node.lhs, ctx) val rhs = visitRel(node.rhs, ctx) val isAll = node.setq == SetQuantifier.ALL - return factory.except(lhs, rhs, isAll) + return operators.except(lhs, rhs, isAll) } override fun visitRelOpSort(node: IRel.Op.Sort, ctx: PType): Any { val input = visitRel(node.input, ctx) val collations = node.specs.map { collation(it) } - return factory.sort(input, collations) + return operators.sort(input, collations) } override fun visitRelOpFilter(node: IRel.Op.Filter, ctx: PType): Any { val input = visitRel(node.input, ctx) val condition = visitRex(node.predicate, ctx) - return factory.filter(input, condition) + return operators.filter(input, condition) } override fun visitRelOpDistinct(node: IRel.Op.Distinct, ctx: PType): Any { val input = visitRel(node.input, ctx) - return factory.distinct(input) + return operators.distinct(input) } override fun visitRelOpUnpivot(node: IRel.Op.Unpivot, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.unpivot(input) + return operators.unpivot(input) } override fun visitRelOpScanIndexed(node: IRel.Op.ScanIndexed, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.iterate(input) + return operators.iterate(input) } override fun visitRelOpScan(node: IRel.Op.Scan, ctx: PType): Any { val input = visitRex(node.rex, ctx) - return factory.scan(input) + return operators.scan(input) } // HELPERS @@ -386,13 +380,13 @@ internal class PlanTransform(private val flags: Set) { private fun collation(spec: IRel.Op.Sort.Spec): Collation { val rex = visitRex(spec.rex, spec.rex.type) val (order, nulls) = when (spec.order) { - IRel.Op.Sort.Order.ASC_NULLS_LAST -> Collation.Order.ASC to Collation.Nulls.LAST - IRel.Op.Sort.Order.ASC_NULLS_FIRST -> Collation.Order.ASC to Collation.Nulls.FIRST - IRel.Op.Sort.Order.DESC_NULLS_LAST -> Collation.Order.DESC to Collation.Nulls.LAST - IRel.Op.Sort.Order.DESC_NULLS_FIRST -> Collation.Order.DESC to Collation.Nulls.FIRST + IRel.Op.Sort.Order.ASC_NULLS_LAST -> Collation.Order.ASC() to Collation.Nulls.LAST() + IRel.Op.Sort.Order.ASC_NULLS_FIRST -> Collation.Order.ASC() to Collation.Nulls.FIRST() + IRel.Op.Sort.Order.DESC_NULLS_LAST -> Collation.Order.DESC() to Collation.Nulls.LAST() + IRel.Op.Sort.Order.DESC_NULLS_FIRST -> Collation.Order.DESC() to Collation.Nulls.FIRST() } return object : Collation { - override fun getRex(): Rex = rex + override fun getColumn(): Rex = rex override fun getOrder(): Collation.Order = order override fun getNulls(): Collation.Nulls = nulls } @@ -401,25 +395,13 @@ internal class PlanTransform(private val flags: Set) { private fun field(field: IRex.Op.Struct.Field): RexStruct.Field { val key = visitRex(field.k, field.k.type) val value = visitRex(field.v, field.v.type) - return RexStruct.Field(key, value) + return RexStruct.field(key, value) } private fun branch(branch: IRex.Op.Case.Branch): RexCase.Branch { val condition = visitRex(branch.condition, branch.condition.type) val result = visitRex(branch.rex, branch.rex.type) - return object : RexCase.Branch { - override fun getCondition(): Rex = condition - override fun getResult(): Rex = result - } - } - - /** - * TODO TEMPORARY! - */ - private fun toSchema(type: IRel.Type): RelType = object : RelType { - private val fields = type.schema.map { Field.of(it.name, it.type) } - override fun getFields(): List = fields - override fun getField(name: String): Field = fields.first { it.name == name } + return RexCase.branch(condition, result) } } } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt index 0cce6682b..b237660e2 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt @@ -2,7 +2,7 @@ package org.partiql.planner -import org.partiql.plan.Operation +import org.partiql.plan.Action import org.partiql.plan.Operator import org.partiql.plan.Plan import org.partiql.plan.OperatorVisitor @@ -60,16 +60,16 @@ object PlanEquivalenceOperatorVisitor : OperatorVisitor { if (other !is Plan) { return false } - val op1 = plan.getOperation() - val op2 = other.getOperation() + val op1 = plan.actions[0] + val op2 = other.actions[1] return visitOperation(op1, op2) } - public fun visitOperation(operation: Operation, other: Any): Boolean { - if (other !is Operation) { + public fun visitOperation(action: Action, other: Any): Boolean { + if (other !is Action) { return false } - if (operation is Operation.Query && other is Operation.Query) { + if (action is Action.Query && other is Action.Query) { // TODO return true } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt index b426325d6..75dc8d26e 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt @@ -4,7 +4,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource import org.partiql.ast.Statement import org.partiql.parser.PartiQLParser -import org.partiql.plan.Operation +import org.partiql.plan.Action import org.partiql.planner.internal.typer.CompilerType import org.partiql.planner.internal.typer.PlanTyper.Companion.toCType import org.partiql.planner.util.PErrorAlwaysMissingCollector @@ -404,8 +404,8 @@ internal class PlannerPErrorReportingTests { plan, pc, tc.assertion ) - val statement = plan.getOperation() as Operation.Query - val actualType = statement.getType().getPType() + val statement = plan.actions[0] as Action.Query + val actualType = statement.rex.type.pType assertEquals(tc.expectedType, actualType) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index 4c3b9488c..85efd2065 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsSource import org.partiql.parser.PartiQLParser import org.partiql.plan.Exclusion -import org.partiql.plan.Operation +import org.partiql.plan.Action import org.partiql.plan.Operators import org.partiql.plan.rel.RelExclude import org.partiql.plan.rel.RelProject @@ -30,8 +30,8 @@ class SubsumptionTest { private val catalog = Catalog.builder().name("default").build() } - private fun getExcludeClause(statement: Operation): RelExclude { - val queryExpr = (statement as Operation.Query).getRex() + private fun getExcludeClause(statement: Action): RelExclude { + val queryExpr = (statement as Action.Query).getRex() val relProject = (queryExpr as RexSelect).getInput() as RelProject return (relProject.getInput()) as RelExclude } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt index 42d534ebd..3ecf2714a 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt @@ -3,7 +3,7 @@ package org.partiql.planner.internal.typer import org.junit.jupiter.api.DynamicContainer import org.junit.jupiter.api.DynamicTest import org.partiql.parser.PartiQLParser -import org.partiql.plan.Operation +import org.partiql.plan.Action import org.partiql.planner.PartiQLPlanner import org.partiql.planner.test.PartiQLTest import org.partiql.planner.test.PartiQLTestProvider @@ -111,7 +111,7 @@ abstract class PartiQLTyperTestBase { val pc = PErrorCollector() if (key is TestResult.Success) { val result = testingPipeline(statement, testName, metadata, pc) - val query = result.plan.getOperation() as Operation.Query + val query = result.plan.getOperation() as Action.Query val actualType = query.getType().getPType() // TODO: The tests need parameter checks assert(actualType.code() == key.expectedType.code()) { @@ -142,7 +142,7 @@ abstract class PartiQLTyperTestBase { } } else { val result = testingPipeline(statement, testName, metadata, pc) - val query = result.plan.getOperation() as Operation.Query + val query = result.plan.getOperation() as Action.Query val actualType = query.getType().getPType() assert(actualType.code() == PType.DYNAMIC) { buildString { diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index 13d06bd03..a742ba99f 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -13,6 +13,7 @@ import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsSource import org.junit.jupiter.params.provider.MethodSource import org.partiql.parser.PartiQLParser +import org.partiql.plan.Action import org.partiql.planner.PartiQLPlanner import org.partiql.planner.internal.PErrors import org.partiql.planner.internal.TestCatalog @@ -3840,7 +3841,7 @@ internal class PlanTyperTestsPorted { val collector = PErrorCollector() val plan = infer(input, session, collector) when (val statement = plan.getOperation()) { - is org.partiql.plan.Operation.Query -> { + is Action.Query -> { assert(collector.problems.isEmpty()) { // Throw internal error for debugging collector.problems.firstOrNull { it.code() == PError.INTERNAL_ERROR }?.let { pError -> @@ -3882,7 +3883,7 @@ internal class PlanTyperTestsPorted { val plan = infer(input, session, collector) when (val operation = plan.getOperation()) { - is org.partiql.plan.Operation.Query -> { + is Action.Query -> { assert(collector.problems.isNotEmpty()) { buildString { appendLine("Expected to find problems, but none were found.") 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 f17b322a6..942f35ad7 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 @@ -11,7 +11,7 @@ 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.plan.Action.Query import org.partiql.planner.PartiQLPlanner import org.partiql.runner.CompileType import org.partiql.runner.ION From b8f809298ebbae531620fe82cb7f5aa1615eaa81 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 08:50:57 -0800 Subject: [PATCH 11/19] Fix partiql-eval assemble --- .../internal/compiler/StandardCompiler.kt | 57 ++++++++++--------- .../operator/rel/RelOpJoinOuterFull.kt | 4 +- 2 files changed, 32 insertions(+), 29 deletions(-) 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 b84ec0109..903f7c40d 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 @@ -59,12 +59,12 @@ import org.partiql.eval.internal.operator.rex.ExprSubquery import org.partiql.eval.internal.operator.rex.ExprSubqueryRow import org.partiql.eval.internal.operator.rex.ExprTable 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.Action import org.partiql.plan.Operator -import org.partiql.plan.Plan import org.partiql.plan.OperatorVisitor +import org.partiql.plan.Plan import org.partiql.plan.rel.Rel import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelDistinct @@ -85,10 +85,10 @@ import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexArray import org.partiql.plan.rex.RexBag import org.partiql.plan.rex.RexCall -import org.partiql.plan.rex.RexDispatch import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexCast import org.partiql.plan.rex.RexCoalesce +import org.partiql.plan.rex.RexDispatch import org.partiql.plan.rex.RexError import org.partiql.plan.rex.RexLit import org.partiql.plan.rex.RexNullIf @@ -124,7 +124,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun prepare(plan: Plan, mode: Mode, ctx: Context): Statement { try { val visitor = _Operator_Visitor(mode) - val operation = plan.getOperation() + if (plan.actions.size != 1) { + throw IllegalArgumentException("Only single actions are supported") + } + val operation = plan.actions[0] val statement: Statement = when { operation is Action.Query -> visitor.compile(operation) else -> throw IllegalArgumentException("Only query statements are supported") @@ -143,8 +146,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { * Transforms plan relation operators into the internal physical operators. */ @Suppress("ClassName") - private inner class _Operator_Visitor(mode: Mode) : - OperatorVisitor { + private inner class _Operator_Visitor(mode: Mode) : OperatorVisitor { private val mode = mode.code() @@ -172,7 +174,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { // if strategy matches root, compile children to form a match. for (strategy in strategies) { // first match - if (strategy.getPattern().matches(operator)) { + if (strategy.pattern.matches(operator)) { // compile children val children = operator.getOperands().map { compileWithStrategies(it, ctx) } val match = Match(operator, children) @@ -251,19 +253,20 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } 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)) - - // TODO JOIN SCHEMAS - val lhsType = rel.getLeftSchema() - val rhsType = rel.getRightSchema() - - return when (rel.getJoinType()) { + val lrel = rel.left + val rrel = rel.right + val lhs = compile(lrel, ctx) + val rhs = compile(rrel, ctx) + val condition = compile(rel.getCondition(), ctx) + // use schema for null padding + val lhsType = lrel.type + val rhsType = rrel.type + return when (rel.joinType.code()) { JoinType.INNER -> RelOpJoinInner(lhs, rhs, condition) - JoinType.LEFT -> RelOpJoinOuterLeft(lhs, rhs, condition, rhsType!!) - JoinType.RIGHT -> RelOpJoinOuterRight(lhs, rhs, condition, lhsType!!) - JoinType.FULL -> RelOpJoinOuterFull(lhs, rhs, condition, lhsType!!, rhsType!!) + JoinType.LEFT -> RelOpJoinOuterLeft(lhs, rhs, condition, rhsType) + JoinType.RIGHT -> RelOpJoinOuterRight(lhs, rhs, condition, lhsType) + JoinType.FULL -> RelOpJoinOuterFull(lhs, rhs, condition, lhsType, rhsType) + else -> error("Unsupported join type: ${rel.joinType}") } } @@ -286,7 +289,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitScan(rel: RelScan, ctx: Unit): ExprRelation { - val input = compile(rel.getInput(), ctx) + val input = compile(rel.rex, ctx) return when (mode) { Mode.PERMISSIVE -> RelOpScanPermissive(input) Mode.STRICT -> RelOpScan(input) @@ -297,9 +300,9 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { 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) - val desc = it.getOrder() == Collation.Order.DESC - val last = it.getNulls() == Collation.Nulls.LAST + val expr = compile(it.column, ctx) + val desc = it.order.code() == Collation.Order.DESC + val last = it.order.code() == Collation.Nulls.LAST RelOpSort.Collation(expr, desc, last) } return RelOpSort(input, collations) @@ -315,7 +318,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitUnpivot(rel: RelUnpivot, ctx: Unit): ExprRelation { - val input = compile(rel.getInput(), ctx) + val input = compile(rel.rex, ctx) return when (mode) { Mode.PERMISSIVE -> RelOpUnpivot.Permissive(input) Mode.STRICT -> RelOpUnpivot.Strict(input) @@ -443,14 +446,14 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { 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() + val ordered = rex.getInput().type.isOrdered return ExprSelect(input, constructor, ordered) } 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() + val k = compile(it.key, ctx) + val v = compile(it.value, ctx).catch() ExprStructField(k, v) } return when (mode) { 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 062d18234..0ef786f2a 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 @@ -24,8 +24,8 @@ internal class RelOpJoinOuterFull( ) : RelOpPeeking() { // TODO BETTER MECHANISM FOR NULL PADDING - private val r = rhsType.getFields().toTypedArray() - private val l = lhsType.getFields().toTypedArray() + private val r = rhsType.getFields() + private val l = lhsType.getFields() private val lhsPadded: Row = Row(l.indices.map { Datum.nullValue(l[it].type) }.toTypedArray()) private val rhsPadded: Row = From 641701a3869079f5c893750371b080a9676e1f41 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 09:51:29 -0800 Subject: [PATCH 12/19] Attach ptype to rex --- .../main/java/org/partiql/plan/rex/Rex.java | 8 ++ .../java/org/partiql/plan/rex/RexBase.java | 5 + .../java/org/partiql/plan/rex/RexNullIf.java | 4 + .../internal/transforms/PlanTransform.kt | 100 +++++++++--------- .../planner/PlanEquivalenceOperatorVisitor.kt | 8 +- .../internal/exclude/SubsumptionTest.kt | 5 +- .../internal/typer/PartiQLTyperTestBase.kt | 6 ++ .../internal/typer/PlanTyperTestsPorted.kt | 8 +- 8 files changed, 84 insertions(+), 60 deletions(-) diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java index 211502f1d..8d5fa8171 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java @@ -8,6 +8,14 @@ */ public interface Rex extends Operator { + /** + * @return the type of the value produced by this [Rex]. + */ @NotNull public RexType getType(); + + /** + * @param type the new type of the value produced by this [Rex]. + */ + public void setType(RexType type); } 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 879f88ef2..2a2f54e41 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 @@ -33,6 +33,11 @@ public final RexType getType() { return type; } + @Override + public final void setType(RexType type) { + this.type = type; + } + @NotNull @Override public final Operator getOperand(int index) { 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 b7d883af5..dfbce4efc 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 @@ -31,9 +31,13 @@ public static RexNullIf create(@NotNull Rex v1, @NotNull Rex v2) { @NotNull public abstract Rex getV2(); + /** + * @return minimal common supertype of (NULL, typeof(v1)) + */ @NotNull @Override protected final RexType type() { + return getV1().getType(); } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 8331e3774..1c0946441 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -1,12 +1,11 @@ package org.partiql.planner.internal.transforms +import org.partiql.plan.Action import org.partiql.plan.Collation import org.partiql.plan.Exclusion import org.partiql.plan.JoinType -import org.partiql.plan.Action import org.partiql.plan.Operators import org.partiql.plan.Plan -import org.partiql.plan.Version import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexCase @@ -88,22 +87,30 @@ internal class PlanTransform(private val flags: Set) { return operators.scan(operators.error(ctx)) } + /** + * Attach a PType to a rex. + */ + private fun typed(type: PType, f: () -> Rex): Rex { + val o = f() + o.type = RexType(type) + return o + } + // EXPRESSIONS override fun visitRex(node: IRex, ctx: PType): Rex = super.visitRexOp(node.op, node.type) as Rex override fun visitRexOp(node: IRex.Op, ctx: PType): Rex = super.visitRexOp(node, ctx) as Rex - override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType): Any { + override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType) = typed(ctx) { val args = node.args.map { visitRex(it, ctx) } - val type = RexType(ctx) - return operators.spread(args) + operators.spread(args) } - override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType): Any { + override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType) = typed(ctx) { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) - return operators.select(input, constructor) + operators.select(input, constructor) } /** @@ -113,27 +120,26 @@ internal class PlanTransform(private val flags: Set) { * @param ctx * @return */ - override fun visitRexOpSubquery(node: IRex.Op.Subquery, ctx: PType): Any { + override fun visitRexOpSubquery(node: IRex.Op.Subquery, ctx: PType) = typed(ctx) { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) val isScalar = node.coercion == IRex.Op.Subquery.Coercion.SCALAR - return operators.subquery(input, constructor, isScalar) + operators.subquery(input, constructor, isScalar) } - override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType): Any { + override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType) = typed(ctx) { val input = visitRel(node.rel, ctx) val key = visitRex(node.key, ctx) val value = visitRex(node.value, ctx) - return operators.pivot(input, key, value) + operators.pivot(input, key, value) } - override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType): Any { + override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType) = typed(ctx) { val fields = node.fields.map { field(it) } - val type = RexType(ctx) - return operators.struct(fields) + operators.struct(fields) } - override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType): Any { + override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType) = typed(ctx) { val values = node.values.map { visitRex(it, ctx) } val type = RexType(ctx) return when (ctx.code()) { @@ -143,26 +149,24 @@ internal class PlanTransform(private val flags: Set) { } } - override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType): Any { + override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType) = typed(ctx) { val args = node.args.map { visitRex(it, ctx) } - val type = RexType(ctx) - return operators.coalesce(args) + operators.coalesce(args) } - override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType): Any { + override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType) = typed(ctx) { val value = visitRex(node.value, ctx) val nullifier = visitRex(node.nullifier, ctx) - return operators.nullIf(value, nullifier) + operators.nullIf(value, nullifier) } - override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType): Any { + override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType) = typed(ctx) { val branches = node.branches.map { branch(it) } val default = visitRex(node.default, ctx) - val type = RexType(ctx) - return operators.caseWhen(null, branches, default) + operators.caseWhen(null, branches, default) } - override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType): Any { + override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType) = typed(ctx) { // TODO assert on function name in plan typer .. here is not the place. val args = node.args.map { visitRex(it, ctx) } val fns = node.candidates.map { it.fn.signature } @@ -170,64 +174,60 @@ internal class PlanTransform(private val flags: Set) { return factory.rexCallDynamic(name, fns, args) } - override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType): Any { + override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType) = typed(ctx) { val fn = node.fn val args = node.args.map { visitRex(it, ctx) } - return operators.call(fn, args) + operators.call(fn, args) } - override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType): Any { + override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType) = typed(ctx) { error("The Internal Node Rex.Op.Call.Unresolved should be converted to an Err Node during type resolution if resolution failed") } - override fun visitRexOpCastUnresolved(node: IRex.Op.Cast.Unresolved, ctx: PType): Any { + override fun visitRexOpCastUnresolved(node: IRex.Op.Cast.Unresolved, ctx: PType) = typed(ctx) { error("This should have been converted to an error node.") } - override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType): Any { + override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType) = typed(ctx) { val operand = visitRex(node.arg, ctx) val target = node.cast.target - return operators.cast(operand, target) + operators.cast(operand, target) } - override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType): Any { + override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType) = typed(ctx) { val operand = visitRex(node.root, ctx) val symbol = node.key - val type = RexType(ctx) - return operators.pathSymbol(operand, symbol) + operators.pathSymbol(operand, symbol) } - override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType): Any { + override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType) = typed(ctx) { val operand = visitRex(node.root, ctx) val key = visitRex(node.key, ctx) - val type = RexType(ctx) - return operators.pathKey(operand, key) + operators.pathKey(operand, key) } - override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType): Any { + override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType) = typed(ctx) { val operand = visitRex(node.root, ctx) val index = visitRex(node.key, ctx) - val type = RexType(ctx) - return operators.pathIndex(operand, index) + operators.pathIndex(operand, index) } - override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType): Any { - return operators.table(node.ref.table) + override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType) = typed(ctx) { + operators.table(node.ref.table) } - override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType): Any { + override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType) = typed(ctx) { error("The Internal Plan Node Rex.Op.Var.Unresolved should be converted to an MISSING Node during type resolution if resolution failed") } - override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType): Any { + override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType) = typed(ctx) { val depth = node.depth val offset = node.ref - val type = ctx - return operators.variable(depth, offset, type) + operators.variable(depth, offset, ctx) } @OptIn(PartiQLValueExperimental::class) - override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType): Any { + override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType) = typed(ctx) { val value = node.value // TODO: PartiQLValue doesn't have a finite decimal type, so we need to specially handle this until we remove // PartiQLValue. @@ -237,14 +237,16 @@ internal class PlanTransform(private val flags: Set) { else -> operators.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) } } - return operators.lit(Datum.of(node.value)) + operators.lit(Datum.of(node.value)) } // RELATION OPERATORS - override fun visitRel(node: IRel, ctx: PType): org.partiql.plan.rel.Rel = super.visitRelOp(node.op, ctx) as org.partiql.plan.rel.Rel + override fun visitRel(node: IRel, ctx: PType): org.partiql.plan.rel.Rel = + super.visitRelOp(node.op, ctx) as org.partiql.plan.rel.Rel - override fun visitRelOp(node: IRel.Op, ctx: PType): org.partiql.plan.rel.Rel = super.visitRelOp(node, ctx) as org.partiql.plan.rel.Rel + override fun visitRelOp(node: IRel.Op, ctx: PType): org.partiql.plan.rel.Rel = + super.visitRelOp(node, ctx) as org.partiql.plan.rel.Rel override fun visitRelOpAggregate(node: IRel.Op.Aggregate, ctx: PType): Any { val input = visitRel(node.input, ctx) diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt index b237660e2..c9936443e 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt @@ -1,11 +1,9 @@ -@file:Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") - package org.partiql.planner import org.partiql.plan.Action import org.partiql.plan.Operator -import org.partiql.plan.Plan import org.partiql.plan.OperatorVisitor +import org.partiql.plan.Plan import org.partiql.plan.rel.RelAggregate import org.partiql.plan.rel.RelCorrelate import org.partiql.plan.rel.RelDistinct @@ -25,10 +23,10 @@ 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.RexDispatch import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexCast import org.partiql.plan.rex.RexCoalesce +import org.partiql.plan.rex.RexDispatch import org.partiql.plan.rex.RexError import org.partiql.plan.rex.RexLit import org.partiql.plan.rex.RexNullIf @@ -61,7 +59,7 @@ object PlanEquivalenceOperatorVisitor : OperatorVisitor { return false } val op1 = plan.actions[0] - val op2 = other.actions[1] + val op2 = other.actions[0] return visitOperation(op1, op2) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index 85efd2065..153ce816f 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -18,6 +18,7 @@ import org.partiql.plan.rex.RexVar import org.partiql.planner.PartiQLPlanner import org.partiql.spi.catalog.Catalog import org.partiql.spi.catalog.Session +import org.partiql.types.PType import java.util.stream.Stream import kotlin.test.assertEquals @@ -43,7 +44,7 @@ class SubsumptionTest { val statement = parseResult.statements[0] val session = Session.builder().catalog("default").catalogs(catalog).build() val plan = planner.plan(statement, session).plan - val excludeClause = getExcludeClause(plan.getOperation()).getExclusions() + val excludeClause = getExcludeClause(plan.actions[0]).getExclusions() assertEquals(tc.expectedExcludeExprs, excludeClause) } @@ -61,7 +62,7 @@ class SubsumptionTest { private val factory = Operators.STANDARD - private fun rexOpVar(depth: Int, offset: Int): RexVar = factory.variable(depth, offset) + private fun rexOpVar(depth: Int, offset: Int): RexVar = factory.variable(depth, offset, PType.unknown()) private val parameters = listOf( SubsumptionTC( diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt index 3ecf2714a..194406468 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt @@ -111,10 +111,16 @@ abstract class PartiQLTyperTestBase { val pc = PErrorCollector() if (key is TestResult.Success) { val result = testingPipeline(statement, testName, metadata, pc) +<<<<<<< HEAD val query = result.plan.getOperation() as Action.Query val actualType = query.getType().getPType() // TODO: The tests need parameter checks assert(actualType.code() == key.expectedType.code()) { +======= + val query = result.plan.actions[0] as Action.Query + val actualType = query.rex.type.pType + assert(actualType == key.expectedType) { +>>>>>>> 1b1aad09 (Attach ptype to rex) buildString { this.appendLine("expected Type is : ${key.expectedType}") this.appendLine("actual Type is : $actualType") diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index a742ba99f..c04222597 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -3840,7 +3840,7 @@ internal class PlanTyperTestsPorted { val collector = PErrorCollector() val plan = infer(input, session, collector) - when (val statement = plan.getOperation()) { + when (val statement = plan.actions[0]) { is Action.Query -> { assert(collector.problems.isEmpty()) { // Throw internal error for debugging @@ -3853,7 +3853,7 @@ internal class PlanTyperTestsPorted { PlanPrinter.append(this, plan) } } - val actual = statement.getType().getPType() + val actual = statement.rex.type.pType assert(tc.expected == actual) { buildString { appendLine() @@ -3882,7 +3882,7 @@ internal class PlanTyperTestsPorted { val input = tc.query ?: testProvider[tc.key!!]!!.statement val plan = infer(input, session, collector) - when (val operation = plan.getOperation()) { + when (val operation = plan.actions[0]) { is Action.Query -> { assert(collector.problems.isNotEmpty()) { buildString { @@ -3892,7 +3892,7 @@ internal class PlanTyperTestsPorted { } } if (tc.expected != null) { - val actual = operation.getType().getPType() + val actual = operation.rex.type.pType assert(tc.expected == actual) { buildString { appendLine() From 81f5ecab8da105cb5bbde54ebaed37ba8f33c4ed Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 11:10:10 -0800 Subject: [PATCH 13/19] Fix partiql-planner build --- .../eval/internal/compiler/StandardCompiler.kt | 2 +- partiql-plan/build.gradle.kts | 6 +++++- .../src/main/java/org/partiql/plan/Exclusion.kt | 3 +-- .../main/java/org/partiql/plan/rex/RexError.java | 3 ++- .../main/java/org/partiql/plan/rex/RexVar.java | 16 ++++++++-------- .../planner/internal/transforms/PlanTransform.kt | 14 +++++++------- .../internal/typer/PartiQLTyperTestBase.kt | 14 ++++---------- .../internal/typer/PlanTyperTestsPorted.kt | 4 ++-- 8 files changed, 30 insertions(+), 32 deletions(-) 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 903f7c40d..1743bbde2 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 @@ -494,7 +494,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitVar(rex: RexVar, ctx: Unit): ExprValue { - val depth = rex.getDepth() + val depth = rex.getScope() val offset = rex.getOffset() return ExprVar(depth, offset) } diff --git a/partiql-plan/build.gradle.kts b/partiql-plan/build.gradle.kts index f64d7a965..2a22e3bd9 100644 --- a/partiql-plan/build.gradle.kts +++ b/partiql-plan/build.gradle.kts @@ -31,10 +31,14 @@ tasks.shadowJar { configurations = listOf(project.configurations.shadow.get()) } -tasks.javadoc { +tasks.withType { enabled = false } +tasks.withType { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} + // Workaround for https://github.com/johnrengelman/shadow/issues/651 components.withType(AdhocComponentWithVariants::class.java).forEach { c -> c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) { diff --git a/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt b/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt index 454c94527..b40d06af0 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt @@ -38,8 +38,7 @@ public class Exclusion(variable: RexVar, items: List) { override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Exclusion) return false - - if (_variable != other._variable) return false + if (_variable.scope != other._variable.scope || _variable.offset != other._variable.offset) return false if (_items != other._items) return false return true 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 c52d3975d..3902f5e7d 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 @@ -23,7 +23,8 @@ public static RexError create() { @Override protected RexType type() { - return new RexType(PType.unknown()); + // TODO SHOULD BE UNKNOWN + return new RexType(PType.dynamic()); } @Override 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 e36276686..0430fcd50 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 @@ -16,14 +16,14 @@ public abstract class RexVar extends RexBase { * @return new variable reference expression. */ @NotNull - public static RexVar create(int depth, int offset, PType type) { - return new Impl(depth, offset, type); + public static RexVar create(int scope, int offset, PType type) { + return new Impl(scope, offset, type); } /** * @return 0-indexed scope offset. */ - public abstract int getDepth(); + public abstract int getScope(); /** * @return 0-index tuple offset. @@ -42,12 +42,12 @@ public R accept(OperatorVisitor visitor, C ctx) { private static class Impl extends RexVar { - private final int depth; + private final int scope; private final int offset; private final PType type; - private Impl(int depth, int offset, PType type) { - this.depth = depth; + private Impl(int scope, int offset, PType type) { + this.scope = scope; this.offset = offset; this.type = type; } @@ -58,8 +58,8 @@ protected RexType type() { } @Override - public int getDepth() { - return depth; + public int getScope() { + return scope; } @Override diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 1c0946441..802f1460c 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -141,10 +141,9 @@ internal class PlanTransform(private val flags: Set) { override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType) = typed(ctx) { val values = node.values.map { visitRex(it, ctx) } - val type = RexType(ctx) - return when (ctx.code()) { - PType.ARRAY -> factory.rexArray(values, type) - PType.BAG -> factory.rexBag(values, type) + when (ctx.code()) { + PType.ARRAY -> operators.array(values) + PType.BAG -> operators.bag(values) else -> error("Expected bag or array, found ${ctx.name().lowercase()}") } } @@ -171,7 +170,7 @@ internal class PlanTransform(private val flags: Set) { val args = node.args.map { visitRex(it, ctx) } val fns = node.candidates.map { it.fn.signature } val name = node.candidates.first().fn.name.getName() - return factory.rexCallDynamic(name, fns, args) + operators.dispatch(name, fns, args) } override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType) = typed(ctx) { @@ -232,12 +231,13 @@ internal class PlanTransform(private val flags: Set) { // TODO: PartiQLValue doesn't have a finite decimal type, so we need to specially handle this until we remove // PartiQLValue. if (value is DecimalValue && ctx.code() == PType.DECIMAL) { - return when (val dec = value.value) { + when (val dec = value.value) { null -> operators.lit(Datum.nullValue(ctx)) else -> operators.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) } + } else { + operators.lit(Datum.of(node.value)) } - operators.lit(Datum.of(node.value)) } // RELATION OPERATORS diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt index 194406468..da538b64c 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt @@ -111,16 +111,10 @@ abstract class PartiQLTyperTestBase { val pc = PErrorCollector() if (key is TestResult.Success) { val result = testingPipeline(statement, testName, metadata, pc) -<<<<<<< HEAD - val query = result.plan.getOperation() as Action.Query - val actualType = query.getType().getPType() - // TODO: The tests need parameter checks - assert(actualType.code() == key.expectedType.code()) { -======= val query = result.plan.actions[0] as Action.Query val actualType = query.rex.type.pType - assert(actualType == key.expectedType) { ->>>>>>> 1b1aad09 (Attach ptype to rex) + // TODO: The tests need parameter checks + assert(actualType.code() == key.expectedType.code()) { buildString { this.appendLine("expected Type is : ${key.expectedType}") this.appendLine("actual Type is : $actualType") @@ -148,8 +142,8 @@ abstract class PartiQLTyperTestBase { } } else { val result = testingPipeline(statement, testName, metadata, pc) - val query = result.plan.getOperation() as Action.Query - val actualType = query.getType().getPType() + val query = result.plan.actions[0] as Action.Query + val actualType = query.rex.type.pType assert(actualType.code() == PType.DYNAMIC) { buildString { this.appendLine("expected Type is : DYNAMIC") diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index c04222597..f423c743b 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -2820,7 +2820,7 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-06"), catalog = "pql", - expected = PType.unknown().toCType() + expected = PType.dynamic().toCType() // TODO make unknown ), SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-07"), @@ -2830,7 +2830,7 @@ internal class PlanTyperTestsPorted { SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-08"), catalog = "pql", - expected = PType.unknown().toCType() + expected = PType.dynamic().toCType() // TODO make unknown ), SuccessTestCase( key = PartiQLTest.Key("basics", "nullif-09"), From 9c57242acd723a89b598d7889bacc34a24028dc6 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 14:58:04 -0800 Subject: [PATCH 14/19] Fix partiql-eval --- .../internal/compiler/StandardCompiler.kt | 6 +- partiql-plan/api/partiql-plan.api | 53 +++++---- .../main/java/org/partiql/plan/Exclusion.kt | 9 +- .../main/java/org/partiql/plan/rel/Rel.java | 9 +- .../java/org/partiql/plan/rel/RelBase.java | 5 + .../java/org/partiql/plan/rel/RelType.java | 54 ++++++++- .../main/java/org/partiql/plan/rex/Rex.java | 4 +- .../java/org/partiql/plan/rex/RexArray.java | 2 +- .../java/org/partiql/plan/rex/RexBag.java | 2 +- .../java/org/partiql/plan/rex/RexCall.java | 2 +- .../java/org/partiql/plan/rex/RexCast.java | 2 +- .../org/partiql/plan/rex/RexDispatch.java | 3 +- .../java/org/partiql/plan/rex/RexError.java | 2 +- .../java/org/partiql/plan/rex/RexLit.java | 2 +- .../java/org/partiql/plan/rex/RexPivot.java | 2 +- .../java/org/partiql/plan/rex/RexSelect.java | 2 +- .../java/org/partiql/plan/rex/RexSpread.java | 2 +- .../java/org/partiql/plan/rex/RexStruct.java | 2 +- .../org/partiql/plan/rex/RexSubqueryComp.java | 2 +- .../org/partiql/plan/rex/RexSubqueryIn.java | 2 +- .../org/partiql/plan/rex/RexSubqueryTest.java | 2 +- .../java/org/partiql/plan/rex/RexTable.java | 2 +- .../java/org/partiql/plan/rex/RexType.java | 19 +-- .../java/org/partiql/plan/rex/RexVar.java | 2 +- .../internal/transforms/PlanTransform.kt | 108 +++++++++--------- .../partiql/runner/executor/EvalExecutor.kt | 2 +- 26 files changed, 186 insertions(+), 116 deletions(-) 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 1743bbde2..e1821d561 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 @@ -302,7 +302,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { val collations = rel.getCollations().map { val expr = compile(it.column, ctx) val desc = it.order.code() == Collation.Order.DESC - val last = it.order.code() == Collation.Nulls.LAST + val last = it.nulls.code() == Collation.Nulls.LAST RelOpSort.Collation(expr, desc, last) } return RelOpSort(input, collations) @@ -494,9 +494,9 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { } override fun visitVar(rex: RexVar, ctx: Unit): ExprValue { - val depth = rex.getScope() + val scope = rex.scope val offset = rex.getOffset() - return ExprVar(depth, offset) + return ExprVar(scope, offset) } /** diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index 78d1206d0..4b1e687f9 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -1,3 +1,10 @@ +public abstract interface class org/partiql/plan/Action { +} + +public abstract interface class org/partiql/plan/Action$Query : org/partiql/plan/Action { + public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; +} + public abstract interface class org/partiql/plan/Collation { public abstract fun getColumn ()Lorg/partiql/plan/rex/Rex; public abstract fun getNulls ()Lorg/partiql/plan/Collation$Nulls; @@ -8,8 +15,8 @@ public final class org/partiql/plan/Collation$Nulls : org/partiql/spi/Enum { public static final field FIRST I public static final field LAST I public static final field UNKNOWN I - public static fun FIRST ()Lorg/partiql/plan/Collation$Order; - public static fun LAST ()Lorg/partiql/plan/Collation$Order; + public static fun FIRST ()Lorg/partiql/plan/Collation$Nulls; + public static fun LAST ()Lorg/partiql/plan/Collation$Nulls; public fun toString ()Ljava/lang/String; } @@ -117,13 +124,6 @@ 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/Operation { -} - -public abstract interface class org/partiql/plan/Operation$Query : org/partiql/plan/Operation { - public abstract fun getRex ()Lorg/partiql/plan/rex/Rex; -} - 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; @@ -370,16 +370,19 @@ public final class org/partiql/plan/Operators$DefaultImpls { } public abstract interface class org/partiql/plan/Plan { - public abstract fun getOperations ()Ljava/util/List; - public abstract fun getVersion ()Lorg/partiql/plan/Version; + public abstract fun getActions ()Ljava/util/List; + public fun getVersion ()Lorg/partiql/plan/Version; } -public abstract interface class org/partiql/plan/Version { - public abstract fun toString ()Ljava/lang/String; +public class org/partiql/plan/Version : org/partiql/spi/Enum { + public static final field UNKNOWN I + public static fun UNKNOWN ()Lorg/partiql/plan/Version; + public fun toString ()Ljava/lang/String; } 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 setType (Lorg/partiql/plan/rel/RelType;)V } public abstract class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/RelBase { @@ -411,6 +414,7 @@ public abstract class org/partiql/plan/rel/RelBase : org/partiql/plan/rel/Rel { public final fun getType ()Lorg/partiql/plan/rel/RelType; protected abstract fun operands ()Ljava/util/List; public fun setTag (I)V + public fun setType (Lorg/partiql/plan/rel/RelType;)V protected abstract fun type ()Lorg/partiql/plan/rel/RelType; } @@ -569,11 +573,15 @@ public abstract class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/RelBas protected final fun type ()Lorg/partiql/plan/rel/RelType; } -public abstract interface class org/partiql/plan/rel/RelType { - public abstract fun getField (Ljava/lang/String;)Lorg/partiql/types/Field; - public abstract fun getFieldSize ()I - public abstract fun getFields ()[Lorg/partiql/types/Field; - public abstract fun isOrdered ()Z +public class org/partiql/plan/rel/RelType { + public static final field ORDERED I + public fun getDegree ()I + public fun getField (I)Lorg/partiql/types/Field; + public fun getField (Ljava/lang/String;)Lorg/partiql/types/Field; + public fun getFields ()[Lorg/partiql/types/Field; + public fun isOrdered ()Z + public static fun of ([Lorg/partiql/types/Field;)Lorg/partiql/plan/rel/RelType; + public static fun of ([Lorg/partiql/types/Field;I)Lorg/partiql/plan/rel/RelType; } public abstract class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/RelBase { @@ -601,6 +609,7 @@ public abstract class org/partiql/plan/rel/RelUnpivot : org/partiql/plan/rel/Rel public abstract interface class org/partiql/plan/rex/Rex : org/partiql/plan/Operator { public abstract fun getType ()Lorg/partiql/plan/rex/RexType; + public abstract fun setType (Lorg/partiql/plan/rex/RexType;)V } public abstract class org/partiql/plan/rex/RexArray : org/partiql/plan/rex/RexBase { @@ -629,6 +638,7 @@ public abstract class org/partiql/plan/rex/RexBase : org/partiql/plan/rex/Rex { public final fun getType ()Lorg/partiql/plan/rex/RexType; protected abstract fun operands ()Ljava/util/List; public fun setTag (I)V + public final fun setType (Lorg/partiql/plan/rex/RexType;)V protected abstract fun type ()Lorg/partiql/plan/rex/RexType; } @@ -645,6 +655,7 @@ public abstract class org/partiql/plan/rex/RexCall : org/partiql/plan/rex/RexBas public abstract class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/RexBase { public fun ()V public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; + public static fun branch (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase$Branch; public static fun create (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase; public abstract fun getBranches ()Ljava/util/List; public abstract fun getDefault ()Lorg/partiql/plan/rex/Rex; @@ -654,7 +665,6 @@ public abstract class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/RexBas } public class org/partiql/plan/rex/RexCase$Branch { - public fun (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)V public fun getCondition ()Lorg/partiql/plan/rex/Rex; public fun getResult ()Lorg/partiql/plan/rex/Rex; } @@ -878,11 +888,10 @@ public abstract class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/RexBa } public class org/partiql/plan/rex/RexType { - public fun (Lorg/partiql/types/PType;)V - public static fun dynamic ()Lorg/partiql/plan/rex/RexType; public fun equals (Ljava/lang/Object;)Z public fun getPType ()Lorg/partiql/types/PType; public fun hashCode ()I + public static fun of (Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexType; public fun toString ()Ljava/lang/String; } @@ -890,8 +899,8 @@ public abstract class org/partiql/plan/rex/RexVar : org/partiql/plan/rex/RexBase public fun ()V public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object; public static fun create (IILorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexVar; - public abstract fun getDepth ()I public abstract fun getOffset ()I + public abstract fun getScope ()I protected final fun operands ()Ljava/util/List; } diff --git a/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt b/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt index b40d06af0..0b9b91bbb 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt +++ b/partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt @@ -34,17 +34,20 @@ public class Exclusion(variable: RexVar, items: List) { */ public fun getItems(): List = _items - // generated + /** + * UNSTABLE AND WILL BE DELETED (this only exists for unit tests) + */ override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Exclusion) return false if (_variable.scope != other._variable.scope || _variable.offset != other._variable.offset) return false if (_items != other._items) return false - return true } - // generated + /** + * UNSTABLE AND WILL BE DELETED (this only exists for unit tests) + */ override fun hashCode(): Int { var result = _variable.hashCode() result = 31 * result + _items.hashCode() diff --git a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java index 2d7608b1f..73727d2e6 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java @@ -9,8 +9,13 @@ public interface Rel extends Operator { /** - * @return RelType. + * @return the type of the rows produced by this rel. */ @NotNull - RelType getType(); + public RelType getType(); + + /** + * @param type the new type of the rows produced by this Rex. + */ + public void setType(@NotNull RelType type); } 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 85c592c9c..8a046bce9 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 @@ -33,6 +33,11 @@ public final RelType getType() { return type; } + @Override + public void setType(@NotNull RelType type) { + this.type = type; + } + @NotNull @Override public final Operator getOperand(int index) { 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 63dc672c6..60bff0736 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 @@ -4,20 +4,62 @@ import org.partiql.types.Field; /** - * Analogous to a ROW type, consider rank/cardinality or other hint mechanisms. + * Analogous to a ROW type, consider cardinality estimates or other hint mechanisms. */ -public interface RelType { +public class RelType { - int getFieldSize(); + public static final int ORDERED = 0x01; + + private final Field[] fields; + private final boolean ordered; + + private RelType(Field[] fields, boolean ordered) { + this.fields = fields; + this.ordered = ordered; + } + + @NotNull + public static RelType of(Field... fields) { + return of(fields, 0); + } + + @NotNull + public static RelType of(Field[] fields, int properties) { + boolean ordered = (properties & ORDERED) != 0; + return new RelType(fields, ordered); + } + + public int getDegree() { + return fields.length; + } + + @NotNull + public Field[] getFields() { + return fields; + } @NotNull - Field[] getFields(); + public Field getField(int index) { + if (index < 0 || index >= fields.length) { + throw new IllegalArgumentException("field index out of bounds: " + index); + } + return fields[index]; // bounds check? + } @NotNull - Field getField(String name); + public Field getField(String name) { + for (Field field : fields) { + if (field.getName().equals(name)) { + return field; + } + } + throw new IllegalArgumentException("field name not found: " + name); + } /** * @return true if the rel produces an ordered stream of rows. */ - boolean isOrdered(); + public boolean isOrdered() { + return ordered; + } } diff --git a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java index 8d5fa8171..8b8029bc8 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java +++ b/partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java @@ -9,13 +9,13 @@ public interface Rex extends Operator { /** - * @return the type of the value produced by this [Rex]. + * @return the type of the value produced by this rex. */ @NotNull public RexType getType(); /** - * @param type the new type of the value produced by this [Rex]. + * @param type the new type of the value produced by this rex. */ public void setType(RexType type); } 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 c78531535..955c2280f 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 @@ -29,7 +29,7 @@ public static RexArray create(@NotNull List values) { @NotNull @Override protected final RexType type() { - return new RexType(PType.array()); + return RexType.of(PType.array()); } @NotNull 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 a07fa2601..94c7b8604 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 @@ -30,7 +30,7 @@ public static RexBag create(@NotNull Collection values) { @NotNull @Override protected final RexType type() { - return new RexType(PType.bag()); + return RexType.of(PType.bag()); } @NotNull 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 106662081..cee7621c8 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 @@ -31,7 +31,7 @@ public static RexCall create(@NotNull Function.Instance function, @NotNull List< @Override protected RexType type() { - return new RexType(getFunction().returns); + return RexType.of(getFunction().returns); } @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 f146c09cd..8da3edf2d 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 @@ -34,7 +34,7 @@ public static RexCast create(@NotNull Rex operand, @NotNull PType target) { @NotNull protected final RexType type() { - return new RexType(getTarget()); + return RexType.of(getTarget()); } @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 b4e93b0e2..7191c9a3e 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 @@ -4,6 +4,7 @@ import org.partiql.plan.Operator; import org.partiql.plan.OperatorVisitor; import org.partiql.spi.function.Function; +import org.partiql.types.PType; import java.util.List; @@ -38,7 +39,7 @@ public static RexDispatch create(String name, List functions, List args) { @NotNull @Override protected final RexType type() { - return new RexType(PType.struct()); + return RexType.of(PType.struct()); } @NotNull 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 0f8aeee57..db20868a5 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 @@ -37,7 +37,7 @@ public static Field field(Rex key, Rex value) { @NotNull @Override protected final RexType type() { - return new RexType(PType.struct()); + return RexType.of(PType.struct()); } @Override 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 7586ea2f8..5e88bbd87 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 @@ -56,7 +56,7 @@ public static RexSubqueryComp create( @NotNull @Override protected final RexType type() { - return new RexType(PType.bool()); + return RexType.of(PType.bool()); } @Override 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 c460b2524..171c87e9d 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 @@ -35,7 +35,7 @@ public static RexSubqueryIn create(@NotNull Rel input, @NotNull List args) @Override protected final RexType type() { - return new RexType(PType.bool()); + return RexType.of(PType.bool()); } @Override 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 af734c360..0d68fcc8b 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 @@ -42,7 +42,7 @@ public static RexSubqueryTest create(@NotNull Rel input, @NotNull Test test) { @NotNull @Override protected final RexType type() { - return new RexType(PType.bool()); + return RexType.of(PType.bool()); } @Override 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 a6085c80c..08d104a67 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 @@ -28,7 +28,7 @@ public static RexTable create(@NotNull Table table) { @NotNull @Override protected final RexType type() { - return new RexType(getTable().getSchema()); + return RexType.of(getTable().getSchema()); } @Override 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 9c651b34c..5ca435186 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 @@ -1,5 +1,6 @@ package org.partiql.plan.rex; +import org.jetbrains.annotations.NotNull; import org.partiql.types.PType; /** @@ -12,10 +13,19 @@ public class RexType { private final PType type; - public RexType(PType type) { + private RexType(PType type) { this.type = type; } + /** + * @return a RexType from a PType. + */ + @NotNull + public static RexType of(@NotNull PType type) { + return new RexType(type); + } + + @NotNull public PType getPType() { return type; } @@ -43,11 +53,4 @@ public boolean equals(Object obj) { public String toString() { return type.toString(); } - - /** - * A [RexType] for an "untyped" logical plan node. - */ - public static RexType dynamic() { - return new RexType(PType.dynamic()); - } } 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 0430fcd50..f086ad401 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 @@ -54,7 +54,7 @@ private Impl(int scope, int offset, PType type) { @Override protected RexType type() { - return new RexType(type); + return RexType.of(type); } @Override diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index 802f1460c..ebd30068d 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -7,16 +7,19 @@ import org.partiql.plan.JoinType import org.partiql.plan.Operators import org.partiql.plan.Plan import org.partiql.plan.rel.RelAggregate +import org.partiql.plan.rel.RelType import org.partiql.plan.rex.Rex import org.partiql.plan.rex.RexCase import org.partiql.plan.rex.RexStruct import org.partiql.plan.rex.RexType import org.partiql.plan.rex.RexVar import org.partiql.planner.internal.PlannerFlag +import org.partiql.planner.internal.ir.Rel import org.partiql.planner.internal.ir.SetQuantifier import org.partiql.planner.internal.ir.visitor.PlanBaseVisitor import org.partiql.spi.errors.PErrorListener import org.partiql.spi.value.Datum +import org.partiql.types.Field import org.partiql.types.PType import org.partiql.value.DecimalValue import org.partiql.value.PartiQLValueExperimental @@ -87,30 +90,25 @@ internal class PlanTransform(private val flags: Set) { return operators.scan(operators.error(ctx)) } - /** - * Attach a PType to a rex. - */ - private fun typed(type: PType, f: () -> Rex): Rex { - val o = f() - o.type = RexType(type) - return o - } - // EXPRESSIONS - override fun visitRex(node: IRex, ctx: PType): Rex = super.visitRexOp(node.op, node.type) as Rex + override fun visitRex(node: IRex, ctx: PType): Rex { + val o = visitRexOp(node.op, node.type) + o.type = RexType.of(ctx) + return o + } override fun visitRexOp(node: IRex.Op, ctx: PType): Rex = super.visitRexOp(node, ctx) as Rex - override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType) = typed(ctx) { + override fun visitRexOpTupleUnion(node: IRex.Op.TupleUnion, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } - operators.spread(args) + return operators.spread(args) } - override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType) = typed(ctx) { + override fun visitRexOpSelect(node: IRex.Op.Select, ctx: PType): Any { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) - operators.select(input, constructor) + return operators.select(input, constructor) } /** @@ -120,130 +118,134 @@ internal class PlanTransform(private val flags: Set) { * @param ctx * @return */ - override fun visitRexOpSubquery(node: IRex.Op.Subquery, ctx: PType) = typed(ctx) { + override fun visitRexOpSubquery(node: IRex.Op.Subquery, ctx: PType): Any { val input = visitRel(node.rel, ctx) val constructor = visitRex(node.constructor, ctx) val isScalar = node.coercion == IRex.Op.Subquery.Coercion.SCALAR - operators.subquery(input, constructor, isScalar) + return operators.subquery(input, constructor, isScalar) } - override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType) = typed(ctx) { + override fun visitRexOpPivot(node: IRex.Op.Pivot, ctx: PType): Any { val input = visitRel(node.rel, ctx) val key = visitRex(node.key, ctx) val value = visitRex(node.value, ctx) - operators.pivot(input, key, value) + return operators.pivot(input, key, value) } - override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType) = typed(ctx) { + override fun visitRexOpStruct(node: IRex.Op.Struct, ctx: PType): Any { val fields = node.fields.map { field(it) } - operators.struct(fields) + return operators.struct(fields) } - override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType) = typed(ctx) { + override fun visitRexOpCollection(node: IRex.Op.Collection, ctx: PType): Any { val values = node.values.map { visitRex(it, ctx) } - when (ctx.code()) { + return when (ctx.code()) { PType.ARRAY -> operators.array(values) PType.BAG -> operators.bag(values) else -> error("Expected bag or array, found ${ctx.name().lowercase()}") } } - override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType) = typed(ctx) { + override fun visitRexOpCoalesce(node: IRex.Op.Coalesce, ctx: PType): Any { val args = node.args.map { visitRex(it, ctx) } - operators.coalesce(args) + return operators.coalesce(args) } - override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType) = typed(ctx) { + override fun visitRexOpNullif(node: IRex.Op.Nullif, ctx: PType): Any { val value = visitRex(node.value, ctx) val nullifier = visitRex(node.nullifier, ctx) - operators.nullIf(value, nullifier) + return operators.nullIf(value, nullifier) } - override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType) = typed(ctx) { + override fun visitRexOpCase(node: IRex.Op.Case, ctx: PType): Any { val branches = node.branches.map { branch(it) } val default = visitRex(node.default, ctx) - operators.caseWhen(null, branches, default) + return operators.caseWhen(null, branches, default) } - override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType) = typed(ctx) { + override fun visitRexOpCallDynamic(node: IRex.Op.Call.Dynamic, ctx: PType): Any { // TODO assert on function name in plan typer .. here is not the place. val args = node.args.map { visitRex(it, ctx) } val fns = node.candidates.map { it.fn.signature } val name = node.candidates.first().fn.name.getName() - operators.dispatch(name, fns, args) + return operators.dispatch(name, fns, args) } - override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType) = typed(ctx) { + override fun visitRexOpCallStatic(node: IRex.Op.Call.Static, ctx: PType): Any { val fn = node.fn val args = node.args.map { visitRex(it, ctx) } - operators.call(fn, args) + return operators.call(fn, args) } - override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType) = typed(ctx) { + override fun visitRexOpCallUnresolved(node: IRex.Op.Call.Unresolved, ctx: PType): Any { error("The Internal Node Rex.Op.Call.Unresolved should be converted to an Err Node during type resolution if resolution failed") } - override fun visitRexOpCastUnresolved(node: IRex.Op.Cast.Unresolved, ctx: PType) = typed(ctx) { + override fun visitRexOpCastUnresolved(node: IRex.Op.Cast.Unresolved, ctx: PType): Any { error("This should have been converted to an error node.") } - override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType) = typed(ctx) { + override fun visitRexOpCastResolved(node: IRex.Op.Cast.Resolved, ctx: PType): Any { val operand = visitRex(node.arg, ctx) val target = node.cast.target - operators.cast(operand, target) + return operators.cast(operand, target) } - override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType) = typed(ctx) { + override fun visitRexOpPathSymbol(node: IRex.Op.Path.Symbol, ctx: PType): Any { val operand = visitRex(node.root, ctx) val symbol = node.key - operators.pathSymbol(operand, symbol) + return operators.pathSymbol(operand, symbol) } - override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType) = typed(ctx) { + override fun visitRexOpPathKey(node: IRex.Op.Path.Key, ctx: PType): Any { val operand = visitRex(node.root, ctx) val key = visitRex(node.key, ctx) - operators.pathKey(operand, key) + return operators.pathKey(operand, key) } - override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType) = typed(ctx) { + override fun visitRexOpPathIndex(node: IRex.Op.Path.Index, ctx: PType): Any { val operand = visitRex(node.root, ctx) val index = visitRex(node.key, ctx) - operators.pathIndex(operand, index) + return operators.pathIndex(operand, index) } - override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType) = typed(ctx) { - operators.table(node.ref.table) + override fun visitRexOpVarGlobal(node: IRex.Op.Var.Global, ctx: PType): Any { + return operators.table(node.ref.table) } - override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType) = typed(ctx) { + override fun visitRexOpVarUnresolved(node: IRex.Op.Var.Unresolved, ctx: PType): Any { error("The Internal Plan Node Rex.Op.Var.Unresolved should be converted to an MISSING Node during type resolution if resolution failed") } - override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType) = typed(ctx) { + override fun visitRexOpVarLocal(node: IRex.Op.Var.Local, ctx: PType): Any { val depth = node.depth val offset = node.ref - operators.variable(depth, offset, ctx) + return operators.variable(depth, offset, ctx) } @OptIn(PartiQLValueExperimental::class) - override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType) = typed(ctx) { + override fun visitRexOpLit(node: IRex.Op.Lit, ctx: PType): Any { val value = node.value // TODO: PartiQLValue doesn't have a finite decimal type, so we need to specially handle this until we remove // PartiQLValue. if (value is DecimalValue && ctx.code() == PType.DECIMAL) { - when (val dec = value.value) { + return when (val dec = value.value) { null -> operators.lit(Datum.nullValue(ctx)) else -> operators.lit(Datum.decimal(dec, ctx.precision, ctx.scale)) } - } else { - operators.lit(Datum.of(node.value)) } + return operators.lit(Datum.of(node.value)) } // RELATION OPERATORS - override fun visitRel(node: IRel, ctx: PType): org.partiql.plan.rel.Rel = - super.visitRelOp(node.op, ctx) as org.partiql.plan.rel.Rel + override fun visitRel(node: IRel, ctx: PType): org.partiql.plan.rel.Rel { + val o = visitRelOp(node.op, ctx) + val fields = node.type.schema.map { Field.of(it.name, it.type) }.toTypedArray() + val properties = if (node.type.props.contains(Rel.Prop.ORDERED)) RelType.ORDERED else 0 + o.type = RelType.of(fields, properties) + return o + } override fun visitRelOp(node: IRel.Op, ctx: PType): org.partiql.plan.rel.Rel = super.visitRelOp(node, ctx) as org.partiql.plan.rel.Rel 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 942f35ad7..a83e0ce6e 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 @@ -193,7 +193,7 @@ class EvalExecutor( assertEquals(1, parseResult.statements.size) val stmt = parseResult.statements[0] val plan = planner.plan(stmt, session).plan - return (plan.getOperation() as Query).getRex().getType().getPType() + return (plan.actions[0] as Query).getRex().getType().getPType() } /** From afd1d94afa4cea5714f89938ceec352810b6dc89 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 15:23:57 -0800 Subject: [PATCH 15/19] Fix ktlint --- .../org/partiql/planner/internal/exclude/SubsumptionTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index 153ce816f..d016cee3a 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -8,8 +8,8 @@ import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.ArgumentsProvider import org.junit.jupiter.params.provider.ArgumentsSource import org.partiql.parser.PartiQLParser -import org.partiql.plan.Exclusion import org.partiql.plan.Action +import org.partiql.plan.Exclusion import org.partiql.plan.Operators import org.partiql.plan.rel.RelExclude import org.partiql.plan.rel.RelProject From d95f761fd66a704c4d056a959c257fe56c9159c3 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 3 Dec 2024 15:33:48 -0800 Subject: [PATCH 16/19] Fix JDK 11 build --- .../src/main/java/org/partiql/plan/OperatorTransform.java | 2 +- partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java | 2 +- partiql-plan/src/main/java/org/partiql/plan/rex/RexSpread.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java index 3916442c7..ecf2e7cf4 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java +++ b/partiql-plan/src/main/java/org/partiql/plan/OperatorTransform.java @@ -333,7 +333,7 @@ public Operator visitArray(@NotNull RexArray rex, C ctx) { @Override public Operator visitBag(@NotNull RexBag rex, C ctx) { // rewrite values (necessarily ascribes order) - List values = rex.getValues().stream().toList(); + List values = List.copyOf(rex.getValues()); List values_new = visitAll(values, ctx, this::visitRex); // rewrite bag if (values != values_new) { 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 94c7b8604..b8aa2c8be 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 @@ -36,7 +36,7 @@ protected final RexType type() { @NotNull @Override protected final List operands() { - List varargs = getValues().stream().toList(); + Collection varargs = getValues(); return List.copyOf(varargs); } 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 e19721a87..72c43d043 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 @@ -34,7 +34,7 @@ protected final RexType type() { @NotNull @Override protected final List operands() { - List varargs = getArgs().stream().toList(); + List varargs = getArgs(); return List.copyOf(varargs); } From 63c88d4332119db55dc66375dab4be17f16176ee Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 4 Dec 2024 15:05:37 -0800 Subject: [PATCH 17/19] Reset .md after bad find+replace --- CHANGELOG.md | 2 +- docs/wiki/design/Architecture Design.md | 4 ++-- docs/wiki/documentation/Exceptions.md | 2 +- docs/wiki/documentation/Functions.md | 6 +++--- ...umeric Data Type & Arithmetic Operations.md | 18 +++++++++--------- docs/wiki/documentation/Window Functions.md | 2 +- .../Rewriter to Visitor Transform Guide.md | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21dc6d8d1..cb7072584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -821,7 +821,7 @@ breaking changes if migrating from v0.9.2. The breaking changes accidentally int `PlannerPipe.Builder.plannerEventCallback` for details. - Adds the following optimization passes, none of which are enabled by default: - `FilterScanToKeyLookupPass` which performs a simple optimization common to most databases: it converts a filter - predicate covering a table's complete primary key into a single get-by-key action, thereby avoiding a full table + predicate covering a table's complete primary key into a single get-by-key operation, thereby avoiding a full table scan. This may pass leave behind some useless `and` expressions if more `and` operands exist in the filter predicate other than primary key field equality expressions. - `RemoveUselessAndsPass`, which removes any useless `and` expressions introduced by the previous pass or by the diff --git a/docs/wiki/design/Architecture Design.md b/docs/wiki/design/Architecture Design.md index b7f3ec467..fa4bb01c8 100644 --- a/docs/wiki/design/Architecture Design.md +++ b/docs/wiki/design/Architecture Design.md @@ -17,7 +17,7 @@ We can illustrate this technique with a simple integer evaluator. Consider the ```java interface Operation { - /** Evaluates the action against the given variables. */ + /** Evaluates the operation against the given variables. */ int eval(Map env); } ``` @@ -73,7 +73,7 @@ interface IntValue { } interface Operation { - /** Evaluates the action against the given variables. */ + /** Evaluates the operation against the given variables. */ IntValue eval(Map env); } ``` diff --git a/docs/wiki/documentation/Exceptions.md b/docs/wiki/documentation/Exceptions.md index 71c026ecd..981755447 100644 --- a/docs/wiki/documentation/Exceptions.md +++ b/docs/wiki/documentation/Exceptions.md @@ -26,5 +26,5 @@ This is ​**not** a complete list. Also look at `org.partiql.lang.eval.Evaluati | Expected 1 argument for `functionName` instead of `n of args` | -- | 1 argument function is called with wrong arity | | Internal error, For input string: `string` | NumberFormatException | `CAST` from String is unsuccessful | | / by zero | ArithmeticException | Division by zero | -| `Not enough or Too many` arguments | -- | Wrong action arity, e.g.: `1+1+` | +| `Not enough or Too many` arguments | -- | Wrong operation arity, e.g.: `1+1+` | diff --git a/docs/wiki/documentation/Functions.md b/docs/wiki/documentation/Functions.md index 118b3f861..fa9c6da2d 100644 --- a/docs/wiki/documentation/Functions.md +++ b/docs/wiki/documentation/Functions.md @@ -526,7 +526,7 @@ Header Purpose : Given a string, `s`, alter every upper case character in `s` to lower case. Any non-upper cased characters -remain unchanged. This action does rely on the locale specified by the runtime configuration. +remain unchanged. This operation does rely on the locale specified by the runtime configuration. The implementation, currently, relies on Java's [String.toLowerCase()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()) documentation. @@ -889,7 +889,7 @@ TO_STRING(`1969-07-20T20:18+08:00`, 'y-MM-dd''T''H:m:ssXXXXX') -- "1969-07-20T2 ### TO_TIMESTAMP -- since v0.1.0 -Given a string convert it to a timestamp. This is the inverse action of [`TO_STRING`](#to_string) +Given a string convert it to a timestamp. This is the inverse operation of [`TO_STRING`](#to_string) Signature @@ -995,7 +995,7 @@ Header Purpose : Given a string, `str`, alter every upper case character is `str` to lower case. Any non-lower cases characters remain -unchanged. This action does rely on the locale specified by the runtime configuration. +unchanged. This operation does rely on the locale specified by the runtime configuration. The implementation, currently, relies on Java's [String.toLowerCase()](https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toLowerCase()) documentation. diff --git a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md index 802d4899e..eecacb1c4 100644 --- a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md +++ b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md @@ -17,13 +17,13 @@ PartiQL also support `Positive Infinity, Negative Infinity, and NaN` as `FLOAT` Unless otherwise specified, a mathematical operator: 1) takes a field name or expression of a numeric data type as operand -2) For Unary action, the result type will be the same as the operand -3) For Binary action, and the two operands are of the same type, the result will be the same as the type of operands. -4) For Binary action, and the two operands are not of the same type, PartiQL will attempt to automatically coerce the operand. +2) For Unary operation, the result type will be the same as the operand +3) For Binary operation, and the two operands are of the same type, the result will be the same as the type of operands. +4) For Binary operation, and the two operands are not of the same type, PartiQL will attempt to automatically coerce the operand. 5) If one or more operands are MISSING, then the result will be missing. else if one or more operands are null, then the result will be null. ### Overflow -With Type Inferencer and runtime type check enabled, Integer constraint will be honored and we check if the result of the mathematical action exceeds the range that can be represented with the result type. +With Type Inferencer and runtime type check enabled, Integer constraint will be honored and we check if the result of the mathematical operation exceeds the range that can be represented with the result type. Without type inferencer and runtime type check, the default runtime integer representation is `INT8`, and overflow can still happen if the result exceed the range that can be represented with the `INT8` type. @@ -32,16 +32,16 @@ When Permissive mode is enabled, overflowed values will be shown as `MISSING` in ### Conversion Map Operators involving multiple argument data types, such as Integer + Float, the conversion map determines the datatype PartiQL uses. Decimal has the highest numeric precedence, followed by float, and finally by INT. -If either operand has type of Decimal, then PartiQL will attempt to convert the operands implicitly to Decimal before performing the action. -If none of the operand has Decimal type but any of the operands is Float, then PartiQL will attempt to convert the operands implicitly to Float before performing the action. +If either operand has type of Decimal, then PartiQL will attempt to convert the operands implicitly to Decimal before performing the operation. +If none of the operand has Decimal type but any of the operands is Float, then PartiQL will attempt to convert the operands implicitly to Float before performing the operation. ### HonorParameter -If precision and scale matter, i.e. doing action on monetary value, make sure to turn on the honorTypedOpParameters() option in Compile Option. +If precision and scale matter, i.e. doing operation on monetary value, make sure to turn on the honorTypedOpParameters() option in Compile Option. The honorTypedOpParameters() determines how CAST and other typed operations behave. The default CompileOptions uses LEGACY which ignores the additional type arguments. Using the HONOR_PARAMETERS mode will take into account type parameters. ### Unary Plus: -Returns the operand without action. +Returns the operand without operation. Syntax : ` + expression` @@ -209,7 +209,7 @@ Example ``` ### Bitwise And -Performs a bitwise logical AND action between two integer values. +Performs a bitwise logical AND operation between two integer values. Syntax : `expression & expression` diff --git a/docs/wiki/documentation/Window Functions.md b/docs/wiki/documentation/Window Functions.md index 05d5d895d..f054ac70e 100644 --- a/docs/wiki/documentation/Window Functions.md +++ b/docs/wiki/documentation/Window Functions.md @@ -186,7 +186,7 @@ LEAD(expr [, offset [, default]]) Purpose: Returns the value from a binding tuple at a given offset *after* the current binding tuple position in the window partition. -Note that `Lag` and `Lead` perform similar action and have similar semantics, except for the fact that `Lag` looks for `x` rows prior to the current row and `Lead` looks for `x` rows after. +Note that `Lag` and `Lead` perform similar operation and have similar semantics, except for the fact that `Lag` looks for `x` rows prior to the current row and `Lead` looks for `x` rows after. Arguments: * expr: diff --git a/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md b/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md index db9261adb..88fd974d4 100644 --- a/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md +++ b/docs/wiki/upgrades/Rewriter to Visitor Transform Guide.md @@ -129,7 +129,7 @@ It's also worth noting that `innerRewriteDataManipulation` and the visitor trans fun transformDataManipulationEvaluationOrder(node: PartiqlAst.Statement.Dml): PartiqlAst.Statement { val from = node.from?.let { transformFromSource(it) } val where = node.where?.let { transformStatementDml_where(node) } - val dmlOperation = transformDmlOp(node.action) + val dmlOperation = transformDmlOp(node.operation) val metas = transformMetas(node.metas) return PartiqlAst.build { From 1a0f6a9418e08665b5827a0af730c27245b1f1b3 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Thu, 5 Dec 2024 09:03:52 -0800 Subject: [PATCH 18/19] Adds operand concept for handling vararg inputs --- docs/wiki/v1/compiler.md | 4 +- partiql-eval/api/partiql-eval.api | 11 +-- .../java/org/partiql/eval/compiler/Match.java | 39 +++-------- .../org/partiql/eval/compiler/Strategy.java | 14 +++- .../internal/compiler/StandardCompiler.kt | 15 ++-- .../org/partiql/eval/compiler/StrategyTest.kt | 2 +- partiql-plan/README.md | 65 ++++++++++++++---- partiql-plan/api/partiql-plan.api | 25 +++++-- .../main/java/org/partiql/plan/Operand.java | 68 +++++++++++++++++++ .../main/java/org/partiql/plan/Operator.java | 12 ++-- .../org/partiql/plan/OperatorVisitor.java | 6 +- .../org/partiql/plan/rel/RelAggregate.java | 6 +- .../java/org/partiql/plan/rel/RelBase.java | 13 ++-- .../org/partiql/plan/rel/RelCorrelate.java | 8 +-- .../org/partiql/plan/rel/RelDistinct.java | 6 +- .../java/org/partiql/plan/rel/RelExcept.java | 8 +-- .../java/org/partiql/plan/rel/RelExclude.java | 6 +- .../java/org/partiql/plan/rel/RelFilter.java | 11 ++- .../org/partiql/plan/rel/RelIntersect.java | 8 +-- .../java/org/partiql/plan/rel/RelIterate.java | 6 +- .../java/org/partiql/plan/rel/RelJoin.java | 13 ++-- .../java/org/partiql/plan/rel/RelLimit.java | 8 +-- .../java/org/partiql/plan/rel/RelOffset.java | 8 +-- .../java/org/partiql/plan/rel/RelProject.java | 6 +- .../java/org/partiql/plan/rel/RelScan.java | 6 +- .../java/org/partiql/plan/rel/RelSort.java | 6 +- .../java/org/partiql/plan/rel/RelType.java | 2 +- .../java/org/partiql/plan/rel/RelUnion.java | 8 +-- .../java/org/partiql/plan/rel/RelUnpivot.java | 6 +- .../java/org/partiql/plan/rex/RexArray.java | 7 +- .../java/org/partiql/plan/rex/RexBag.java | 11 ++- .../java/org/partiql/plan/rex/RexBase.java | 13 ++-- .../java/org/partiql/plan/rex/RexCall.java | 8 +-- .../java/org/partiql/plan/rex/RexCase.java | 15 ++-- .../java/org/partiql/plan/rex/RexCast.java | 7 +- .../org/partiql/plan/rex/RexCoalesce.java | 8 +-- .../org/partiql/plan/rex/RexDispatch.java | 8 +-- .../java/org/partiql/plan/rex/RexError.java | 4 +- .../java/org/partiql/plan/rex/RexLit.java | 4 +- .../java/org/partiql/plan/rex/RexNullIf.java | 8 +-- .../org/partiql/plan/rex/RexPathIndex.java | 11 ++- .../java/org/partiql/plan/rex/RexPathKey.java | 11 ++- .../org/partiql/plan/rex/RexPathSymbol.java | 6 +- .../java/org/partiql/plan/rex/RexPivot.java | 10 ++- .../java/org/partiql/plan/rex/RexSelect.java | 11 ++- .../java/org/partiql/plan/rex/RexSpread.java | 7 +- .../java/org/partiql/plan/rex/RexStruct.java | 4 +- .../org/partiql/plan/rex/RexSubquery.java | 6 +- .../org/partiql/plan/rex/RexSubqueryComp.java | 6 +- .../org/partiql/plan/rex/RexSubqueryIn.java | 6 +- .../org/partiql/plan/rex/RexSubqueryTest.java | 6 +- .../java/org/partiql/plan/rex/RexTable.java | 4 +- .../java/org/partiql/plan/rex/RexType.java | 2 +- .../java/org/partiql/plan/rex/RexVar.java | 4 +- 54 files changed, 356 insertions(+), 227 deletions(-) create mode 100644 partiql-plan/src/main/java/org/partiql/plan/Operand.java 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(); } From 4682c2ed85e46b95b90acd920987abf02854c72a Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Thu, 5 Dec 2024 14:04:35 -0800 Subject: [PATCH 19/19] Address latest PR feedback --- partiql-eval/api/partiql-eval.api | 2 +- .../org/partiql/eval/compiler/Strategy.java | 7 +++- .../internal/compiler/StandardCompiler.kt | 39 +++++++++---------- .../org/partiql/eval/compiler/StrategyTest.kt | 2 +- partiql-plan/api/partiql-plan.api | 6 +-- .../src/main/java/org/partiql/plan/Plan.java | 6 +-- .../org/partiql/plan/rel/RelAggregate.java | 9 ++--- .../java/org/partiql/plan/rel/RelBase.java | 2 + .../java/org/partiql/plan/rel/RelJoin.java | 1 + .../java/org/partiql/plan/rex/RexBase.java | 2 + .../java/org/partiql/plan/rex/RexCall.java | 2 + .../java/org/partiql/plan/rex/RexCase.java | 1 + .../java/org/partiql/plan/rex/RexCast.java | 1 + .../org/partiql/plan/rex/RexCoalesce.java | 2 + .../org/partiql/plan/rex/RexDispatch.java | 1 + .../java/org/partiql/plan/rex/RexError.java | 2 + .../java/org/partiql/plan/rex/RexLit.java | 1 + .../java/org/partiql/plan/rex/RexNullIf.java | 1 + .../org/partiql/plan/rex/RexPathIndex.java | 1 + .../java/org/partiql/plan/rex/RexPathKey.java | 1 + .../org/partiql/plan/rex/RexPathSymbol.java | 1 + .../java/org/partiql/plan/rex/RexPivot.java | 1 + .../java/org/partiql/plan/rex/RexStruct.java | 1 + .../org/partiql/plan/rex/RexSubquery.java | 1 + .../org/partiql/plan/rex/RexSubqueryComp.java | 1 + .../org/partiql/plan/rex/RexSubqueryIn.java | 2 + .../org/partiql/plan/rex/RexSubqueryTest.java | 1 + .../java/org/partiql/plan/rex/RexTable.java | 1 + .../java/org/partiql/plan/rex/RexVar.java | 2 + .../main/kotlin/org/partiql/plan/Operators.kt | 2 +- .../partiql/planner/internal/SqlPlanner.kt | 4 +- .../internal/transforms/PlanTransform.kt | 4 +- .../planner/PlanEquivalenceOperatorVisitor.kt | 4 +- .../planner/PlannerPErrorReportingTests.kt | 2 +- .../internal/exclude/SubsumptionTest.kt | 2 +- .../internal/typer/PartiQLTyperTestBase.kt | 4 +- .../internal/typer/PlanTyperTestsPorted.kt | 4 +- .../partiql/runner/executor/EvalExecutor.kt | 2 +- 38 files changed, 75 insertions(+), 53 deletions(-) diff --git a/partiql-eval/api/partiql-eval.api b/partiql-eval/api/partiql-eval.api index 6dda94908..60e5c7812 100644 --- a/partiql-eval/api/partiql-eval.api +++ b/partiql-eval/api/partiql-eval.api @@ -69,7 +69,7 @@ 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/compiler/Strategy$Callback;)Lorg/partiql/eval/Expr; + public abstract fun apply (Lorg/partiql/eval/compiler/Match;Lorg/partiql/eval/Mode;Lorg/partiql/eval/compiler/Strategy$Callback;)Lorg/partiql/eval/Expr; public fun getPattern ()Lorg/partiql/eval/compiler/Pattern; } 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 0a10bc5be..5593c4d2d 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 @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.partiql.eval.Expr; +import org.partiql.eval.Mode; import org.partiql.plan.Operator; /** @@ -34,11 +35,12 @@ public Pattern getPattern() { * Applies the strategy to a logical plan operator and returns the physical operation (expr). * * @param match holds the matched operators + * @param mode evaluation mode * @param callback for compiling arguments of matched operators * @return the physical operation */ @NotNull - public abstract Expr apply(@NotNull Match match, @NotNull Callback callback); + public abstract Expr apply(@NotNull Match match, @NotNull Mode mode, @NotNull Callback callback); /** * A compilation callback for strategies to compile arguments of matched operators. @@ -48,6 +50,7 @@ public interface Callback { /** * @return a physical operator (expr) for the logical operator. */ - Expr apply(Operator operator); + @NotNull + Expr apply(@NotNull 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 cd2c584d1..1bea972c2 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 @@ -124,11 +124,8 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun prepare(plan: Plan, mode: Mode, ctx: Context): Statement { try { - val visitor = _Operator_Visitor(mode) - if (plan.actions.size != 1) { - throw IllegalArgumentException("Only single actions are supported") - } - val operation = plan.actions[0] + val visitor = Visitor(mode) + val operation = plan.action val statement: Statement = when { operation is Action.Query -> visitor.compile(operation) else -> throw IllegalArgumentException("Only query statements are supported") @@ -146,10 +143,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { /** * Transforms plan relation operators into the internal physical operators. */ - @Suppress("ClassName") - private inner class _Operator_Visitor(mode: Mode) : OperatorVisitor { + private inner class Visitor(mode: Mode) : OperatorVisitor { - private val mode = mode.code() + private val mode = mode + private val MODE = mode.code() /** * Compile a query operation to a query statement. @@ -179,7 +176,7 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { // assume single match val operand = Operand.single(operator) val match = Match(operand) - return strategy.apply(match, ::compileWithStrategies) + return strategy.apply(match, mode, ::compileWithStrategies) } } return operator.accept(this, Unit) @@ -246,10 +243,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun visitIterate(rel: RelIterate, ctx: Unit): ExprRelation { val input = compile(rel.getRex(), ctx) - return when (mode) { + return when (MODE) { Mode.PERMISSIVE -> RelOpIteratePermissive(input) Mode.STRICT -> RelOpIterate(input) - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } @@ -291,10 +288,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun visitScan(rel: RelScan, ctx: Unit): ExprRelation { val input = compile(rel.rex, ctx) - return when (mode) { + return when (MODE) { Mode.PERMISSIVE -> RelOpScanPermissive(input) Mode.STRICT -> RelOpScan(input) - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } @@ -320,10 +317,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { override fun visitUnpivot(rel: RelUnpivot, ctx: Unit): ExprRelation { val input = compile(rel.rex, ctx) - return when (mode) { + return when (MODE) { Mode.PERMISSIVE -> RelOpUnpivot.Permissive(input) Mode.STRICT -> RelOpUnpivot.Strict(input) - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } @@ -437,10 +434,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { val input = compile(rex.getInput(), ctx) val key = compile(rex.getKey(), ctx) val value = compile(rex.getValue(), ctx) - return when (mode) { + return when (MODE) { Mode.PERMISSIVE -> ExprPivotPermissive(input, key, value) Mode.STRICT -> ExprPivot(input, key, value) - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } @@ -457,10 +454,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { val v = compile(it.value, ctx).catch() ExprStructField(k, v) } - return when (mode) { + return when (MODE) { Mode.PERMISSIVE -> ExprStructPermissive(fields) Mode.STRICT -> ExprStructStrict(fields) - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } @@ -503,10 +500,10 @@ internal class StandardCompiler(strategies: List) : PartiQLCompiler { /** * Some places "catch" an error and return the MISSING value. */ - private fun ExprValue.catch(): ExprValue = when (mode) { + private fun ExprValue.catch(): ExprValue = when (MODE) { Mode.PERMISSIVE -> ExprPermissive(this) Mode.STRICT -> this - else -> throw IllegalStateException("Unsupported execution mode: $mode") + else -> throw IllegalStateException("Unsupported execution mode: $MODE") } } } 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 3e909318a..c165ba7a5 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, callback: Callback): Expr { + override fun apply(match: Match, mode: Mode, callback: Callback): Expr { trigged = true return MyLimit() } diff --git a/partiql-plan/api/partiql-plan.api b/partiql-plan/api/partiql-plan.api index 42fd74b39..a670c05ce 100644 --- a/partiql-plan/api/partiql-plan.api +++ b/partiql-plan/api/partiql-plan.api @@ -385,7 +385,7 @@ public final class org/partiql/plan/Operators$DefaultImpls { } public abstract interface class org/partiql/plan/Plan { - public abstract fun getActions ()Ljava/util/List; + public abstract fun getAction ()Lorg/partiql/plan/Action; public fun getVersion ()Lorg/partiql/plan/Version; } @@ -409,7 +409,7 @@ public abstract class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/R public abstract fun getGroups ()Ljava/util/List; public abstract fun getInput ()Lorg/partiql/plan/rel/Rel; public abstract fun getMeasures ()Ljava/util/List; - public static fun measure (Lorg/partiql/spi/function/Aggregation;Ljava/util/List;Ljava/lang/Boolean;)Lorg/partiql/plan/rel/RelAggregate$Measure; + public static fun measure (Lorg/partiql/spi/function/Aggregation;Ljava/util/List;Z)Lorg/partiql/plan/rel/RelAggregate$Measure; protected final fun operands ()Ljava/util/List; protected final fun type ()Lorg/partiql/plan/rel/RelType; } @@ -418,7 +418,7 @@ public class org/partiql/plan/rel/RelAggregate$Measure { public fun copy (Ljava/util/List;)Lorg/partiql/plan/rel/RelAggregate$Measure; public fun getAgg ()Lorg/partiql/spi/function/Aggregation; public fun getArgs ()Ljava/util/List; - public fun isDistinct ()Ljava/lang/Boolean; + public fun isDistinct ()Z } public abstract class org/partiql/plan/rel/RelBase : org/partiql/plan/rel/Rel { diff --git a/partiql-plan/src/main/java/org/partiql/plan/Plan.java b/partiql-plan/src/main/java/org/partiql/plan/Plan.java index 28a6beb3d..c4707803c 100644 --- a/partiql-plan/src/main/java/org/partiql/plan/Plan.java +++ b/partiql-plan/src/main/java/org/partiql/plan/Plan.java @@ -2,8 +2,6 @@ import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * A plan holds operations that can be executed. */ @@ -18,8 +16,8 @@ default public Version getVersion() { } /** - * @return statement actions to execute. + * @return statement action to execute. */ @NotNull - public List getActions(); + public Action getAction(); } 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 333961957..f4320d962 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 @@ -27,7 +27,7 @@ public static RelAggregate create(@NotNull Rel input, @NotNull List mea * @return new {@link Measure} instance */ @NotNull - public static Measure measure(@NotNull Aggregation agg, @NotNull List args, @NotNull Boolean distinct) { + public static Measure measure(@NotNull Aggregation agg, @NotNull List args, @NotNull boolean distinct) { return new Measure(agg, args, distinct); } @@ -88,9 +88,9 @@ public static class Measure { private final Aggregation agg; private final List args; - private final Boolean distinct; + private final boolean distinct; - private Measure(Aggregation agg, List args, Boolean distinct) { + private Measure(Aggregation agg, List args, boolean distinct) { this.agg = agg; this.args = args; this.distinct = distinct; @@ -106,8 +106,7 @@ public List getArgs() { return args; } - @NotNull - public Boolean isDistinct() { + public boolean isDistinct() { return distinct; } 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 00ce25419..6363a8b35 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 @@ -61,6 +61,7 @@ public final List getOperands() { * * @return computed type. */ + @NotNull protected abstract RelType type(); /** @@ -68,5 +69,6 @@ public final List getOperands() { * * @return computed operands. */ + @NotNull protected abstract List operands(); } 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 e33722d06..4b82888b5 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 @@ -45,6 +45,7 @@ public static RelJoin create(@NotNull Rel left, @NotNull Rel right, @NotNull Rex @NotNull public abstract Rex getCondition(); + @NotNull @Override protected RelType type() { throw new UnsupportedOperationException("compute join type"); 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 8ab53c628..076b9df2f 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 @@ -61,6 +61,7 @@ public final List getOperands() { * * @return computed type. */ + @NotNull protected abstract RexType type(); /** @@ -68,5 +69,6 @@ public final List getOperands() { * * @return computed operands. */ + @NotNull 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 7cd2bcb81..f444723f8 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 @@ -29,11 +29,13 @@ public static RexCall create(@NotNull Function.Instance function, @NotNull List< @NotNull public abstract List getArgs(); + @NotNull @Override protected RexType type() { return RexType.of(getFunction().returns); } + @NotNull @Override protected List operands() { Operand c0 = Operand.vararg(getArgs()); 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 a440a2e2a..43ba348f4 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 @@ -46,6 +46,7 @@ protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected List operands() { Rex match = getMatch(); 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 e8b939e2d..374b77b3a 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 @@ -37,6 +37,7 @@ protected final RexType type() { return RexType.of(getTarget()); } + @NotNull @Override protected List operands() { Operand c0 = Operand.single(getOperand()); 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 f33ac89b0..2440570a7 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 @@ -25,11 +25,13 @@ public static RexCoalesce create(List args) { @NotNull public abstract List getArgs(); + @NotNull @Override protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.vararg(getArgs()); 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 be39c6bfd..3c1d176eb 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 @@ -42,6 +42,7 @@ protected final RexType type() { return RexType.of(PType.dynamic()); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.vararg(getArgs()); 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 d18962618..fc1c3d22a 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 @@ -21,12 +21,14 @@ public static RexError create() { return new Impl(); } + @NotNull @Override protected RexType type() { // TODO SHOULD BE UNKNOWN return RexType.of(PType.dynamic()); } + @NotNull @Override 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 ff8f34617..86b9129ee 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 @@ -29,6 +29,7 @@ protected final RexType type() { return RexType.of(getDatum().getType()); } + @NotNull @Override 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 b95905e86..1909f8fae 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 @@ -41,6 +41,7 @@ protected final RexType type() { return getV1().getType(); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getV1()); 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 f986587ef..4f7b54a01 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 @@ -36,6 +36,7 @@ protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getOperand()); 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 0a1f15d45..90765f2ea 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 @@ -37,6 +37,7 @@ protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected List operands() { Operand c0 = Operand.single(getOperand()); 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 fd77bd0b4..6240f57a0 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 @@ -37,6 +37,7 @@ protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getOperand()); 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 d98d6a487..91a229115 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 @@ -45,6 +45,7 @@ protected final RexType type() { return RexType.of(PType.struct()); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getInput()); 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 9752ebfab..74e6362dd 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 @@ -40,6 +40,7 @@ protected final RexType type() { return RexType.of(PType.struct()); } + @NotNull @Override 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 49f334d5d..11dff39af 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 @@ -39,6 +39,7 @@ protected final RexType type() { throw new UnsupportedOperationException("Derive type is not implemented"); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getInput()); 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 3518cf9d4..f1e907412 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 @@ -59,6 +59,7 @@ protected final RexType type() { return RexType.of(PType.bool()); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getInput()); 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 cab4210fe..02b9b34ee 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 @@ -33,11 +33,13 @@ public static RexSubqueryIn create(@NotNull Rel input, @NotNull List args) @NotNull public abstract List getArgs(); + @NotNull @Override protected final RexType type() { return RexType.of(PType.bool()); } + @NotNull @Override protected final List operands() { Operand c0 = Operand.single(getInput()); 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 54a299c35..da590b9ec 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 @@ -45,6 +45,7 @@ protected final RexType type() { return RexType.of(PType.bool()); } + @NotNull @Override protected List operands() { Operand c0 = Operand.single(getInput()); 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 679258938..cc073d79e 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 @@ -31,6 +31,7 @@ protected final RexType type() { return RexType.of(getTable().getSchema()); } + @NotNull @Override protected final List operands() { return List.of(); 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 282e5dd58..05a18460c 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 @@ -30,6 +30,7 @@ public static RexVar create(int scope, int offset, PType type) { */ public abstract int getOffset(); + @NotNull @Override protected final List operands() { return List.of(); @@ -52,6 +53,7 @@ private Impl(int scope, int offset, PType type) { this.type = type; } + @NotNull @Override protected RexType type() { return RexType.of(type); diff --git a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt index b52160861..572788903 100644 --- a/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt +++ b/partiql-plan/src/main/kotlin/org/partiql/plan/Operators.kt @@ -181,7 +181,7 @@ public interface Operators { public fun limit(input: Rel, limit: Rex): RelLimit = RelLimit.create(input, limit) /** - * Create a [RelLimit] instance. + * Create a [RelOffset] instance. * * @param input * @param offset diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt index a8b116aec..abef56a6a 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/SqlPlanner.kt @@ -70,9 +70,7 @@ internal class SqlPlanner( val error = PError.INTERNAL_ERROR(PErrorKind.SEMANTIC(), null, t) ctx.errorListener.report(error) val query = Action.Query { Operators.STANDARD.error(PType.dynamic()) } - val plan = object : Plan { - override fun getActions(): MutableList = mutableListOf(query) - } + val plan = Plan { query } return Result(plan) } } diff --git a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt index ebd30068d..8d1537e38 100644 --- a/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt +++ b/partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/PlanTransform.kt @@ -50,9 +50,7 @@ internal class PlanTransform(private val flags: Set) { val root = visitor.visitRex(query.root, query.root.type) val action = Action.Query { root } // TODO replace with standard implementations (or just remove plan transform altogether when possible). - return object : Plan { - override fun getActions(): MutableList = mutableListOf(action) - } + return Plan { action } } private class Visitor( diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt index c9936443e..bbb5535e3 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlanEquivalenceOperatorVisitor.kt @@ -58,8 +58,8 @@ object PlanEquivalenceOperatorVisitor : OperatorVisitor { if (other !is Plan) { return false } - val op1 = plan.actions[0] - val op2 = other.actions[0] + val op1 = plan.action + val op2 = other.action return visitOperation(op1, op2) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt index 75dc8d26e..7dc4c9c43 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerPErrorReportingTests.kt @@ -404,7 +404,7 @@ internal class PlannerPErrorReportingTests { plan, pc, tc.assertion ) - val statement = plan.actions[0] as Action.Query + val statement = plan.action as Action.Query val actualType = statement.rex.type.pType assertEquals(tc.expectedType, actualType) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt index d016cee3a..ab8ee3284 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/exclude/SubsumptionTest.kt @@ -44,7 +44,7 @@ class SubsumptionTest { val statement = parseResult.statements[0] val session = Session.builder().catalog("default").catalogs(catalog).build() val plan = planner.plan(statement, session).plan - val excludeClause = getExcludeClause(plan.actions[0]).getExclusions() + val excludeClause = getExcludeClause(plan.action).getExclusions() assertEquals(tc.expectedExcludeExprs, excludeClause) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt index da538b64c..4eebfbeb3 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PartiQLTyperTestBase.kt @@ -111,7 +111,7 @@ abstract class PartiQLTyperTestBase { val pc = PErrorCollector() if (key is TestResult.Success) { val result = testingPipeline(statement, testName, metadata, pc) - val query = result.plan.actions[0] as Action.Query + val query = result.plan.action as Action.Query val actualType = query.rex.type.pType // TODO: The tests need parameter checks assert(actualType.code() == key.expectedType.code()) { @@ -142,7 +142,7 @@ abstract class PartiQLTyperTestBase { } } else { val result = testingPipeline(statement, testName, metadata, pc) - val query = result.plan.actions[0] as Action.Query + val query = result.plan.action as Action.Query val actualType = query.rex.type.pType assert(actualType.code() == PType.DYNAMIC) { buildString { diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt index f423c743b..5cf20ac19 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/PlanTyperTestsPorted.kt @@ -3840,7 +3840,7 @@ internal class PlanTyperTestsPorted { val collector = PErrorCollector() val plan = infer(input, session, collector) - when (val statement = plan.actions[0]) { + when (val statement = plan.action) { is Action.Query -> { assert(collector.problems.isEmpty()) { // Throw internal error for debugging @@ -3882,7 +3882,7 @@ internal class PlanTyperTestsPorted { val input = tc.query ?: testProvider[tc.key!!]!!.statement val plan = infer(input, session, collector) - when (val operation = plan.actions[0]) { + when (val operation = plan.action) { is Action.Query -> { assert(collector.problems.isNotEmpty()) { buildString { 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 a83e0ce6e..b28415ec0 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 @@ -193,7 +193,7 @@ class EvalExecutor( assertEquals(1, parseResult.statements.size) val stmt = parseResult.statements[0] val plan = planner.plan(stmt, session).plan - return (plan.actions[0] as Query).getRex().getType().getPType() + return (plan.action as Query).getRex().getType().getPType() } /**