Skip to content

Commit

Permalink
Adds standard impls with named constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Nov 28, 2024
1 parent 54d0340 commit 48a79d5
Show file tree
Hide file tree
Showing 41 changed files with 1,248 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ internal class StandardCompiler(strategies: List<Strategy>) : 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Measure> measures, @NotNull List<Rex> groups) {
return new Impl(input, measures, groups);
}

/**
* @return the input (child 0)
Expand Down Expand Up @@ -47,6 +55,8 @@ public <R, C> R accept(@NotNull Visitor<R, C> visitor, C ctx) {

/**
* An aggregation function along with its arguments and any additional filters (e.g. DISTINCT).
* <br>
* TODO unnest ??
*/
public static class Measure {

Expand Down Expand Up @@ -75,4 +85,35 @@ public Boolean isDistinct() {
return distinct;
}
}

private static class Impl extends RelAggregate {

private final Rel input;
private final List<Measure> measures;
private final List<Rex> groups;

public Impl(Rel input, List<Measure> measures, List<Rex> groups) {
this.input = input;
this.measures = measures;
this.groups = groups;
}

@NotNull
@Override
public Rel getInput() {
return input;
}

@NotNull
@Override
public List<Measure> getMeasures() {
return measures;
}

@NotNull
@Override
public List<Rex> getGroups() {
return groups;
}
}
}
39 changes: 39 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -45,4 +53,35 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
23 changes: 23 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelDistinct.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -34,4 +42,19 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
42 changes: 40 additions & 2 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -46,4 +54,34 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
32 changes: 32 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelExclude.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exclusion> exclusions) {
return new Impl(input, exclusions);
}

/**
* @return input rel (child 0)
*/
Expand Down Expand Up @@ -41,4 +49,28 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> visitor, C ctx) {
return visitor.visitExclude(this, ctx);
}

private static class Impl extends RelExclude {

private final Rel input;
private final List<Exclusion> exclusions;

public Impl(Rel input, List<Exclusion> exclusions) {
this.input = input;
this.exclusions = exclusions;
}

@NotNull
@Override
public Rel getInput() {
return input;
}

@NotNull
@Override
public List<Exclusion> getExclusions() {
return exclusions;
}
}

}
31 changes: 31 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -42,4 +50,27 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
42 changes: 40 additions & 2 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -46,4 +54,34 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
Loading

0 comments on commit 48a79d5

Please sign in to comment.