From 48a79d5d8bdbc7ddb49f0449d4cffa5636d7cdbf Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Wed, 27 Nov 2024 19:04:31 -0500 Subject: [PATCH] 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 e791764375..1292dbc9b2 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 2c6635eeab..0f51a0188f 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 364d0caa2f..1722d3ae50 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 d5119c3401..14be950c42 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 9c22fa30c2..8c3a8096aa 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 9c8a9b0045..a489a249b7 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 2aa50813b4..9834958c69 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 d5b15c4a57..47e26bd579 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 067fc07c72..7c85bafddf 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 5b33845520..1447e985c8 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 49d439c960..22475108fe 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 4def97fcc8..5cad944862 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 9fcba7add4..591e566779 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 e5e2474157..6be7c2b161 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 eecc771e26..f10eb8a5ee 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 6305acab9b..e60ac42157 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 5e0ce16b2a..45d12c4529 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 3355c11c35..1baf206f8a 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 38f3285579..a4797dbbcb 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 230a5bd58e..ce1eb0e449 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 4d1a8dba81..2258a0ce60 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 843b9e217e..c775ea8701 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 db5e8e25d0..dc91dcc658 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 0f37829f0b..c83be1a5ff 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 adb28ee8b9..9d000eeca6 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 3af906727a..011faac306 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 8ef173582e..5356c73919 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 67d0eaeea4..24af36e1e0 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 03555a7e0f..ec1ff61dcb 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 0d85219862..89a48f7137 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 b1eaa24b25..97806a21e8 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 50f529cc12..52636adfb6 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 547495bb06..57ca437efd 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 1f9ee71574..d70696ec21 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 c91b14865f..a6e349f315 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 2f907b78b6..3cfcef706b 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 bdc1a77ef4..d4cbf67acf 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 642ee71c4e..a25259347a 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 d28d37d420..0c25ffbaf7 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 c1d4a77b21..c6904d623f 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 2fe7291b60..81afdbc879 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.