Skip to content

Commit

Permalink
Adds default impls with standard 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 beb149e
Show file tree
Hide file tree
Showing 17 changed files with 534 additions and 10 deletions.
41 changes: 41 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public abstract class RelAggregate extends RelBase {

// TODO GROUP STRATEGY: https://github.com/partiql/partiql-lang-kotlin/issues/1664

/**
* @return a standard {@link RelAggregate} instance.
*/
@NotNull
public static RelAggregate standard(@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 a standard {@link RelCorrelate} instance.
*/
@NotNull
public static RelCorrelate standard(@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 a standard {@link RelDistinct} instance.
*/
@NotNull
public static RelDistinct standard(@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;
}
}
}
38 changes: 38 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelExcept.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
*/
public abstract class RelExcept extends RelBase {

/**
* @return a standard {@link RelExcept} instance.
*/
@NotNull
public static RelExcept standard(@NotNull Rel left, @NotNull Rel right, boolean all) {
return new Impl(left, right, all);
}

/**
* @return true if ALL else DISTINCT.
*/
Expand Down Expand Up @@ -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 a standard {@link RelExclude} instance
*/
@NotNull
public static RelExclude standard(@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 a standard {@link RelFilter} instance.
*/
@NotNull
public static RelFilter standard(@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;
}
}
}
38 changes: 38 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelIntersect.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
*/
public abstract class RelIntersect extends RelBase {

/**
* @return a standard {@link RelIntersect} instance.
*/
@NotNull
public static RelIntersect standard(@NotNull Rel left, @NotNull Rel right, boolean all) {
return new Impl(left, right, all);
}

/**
* @return true if ALL else DISTINCT.
*/
Expand Down Expand Up @@ -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;
}
}
}
23 changes: 23 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelIterate.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
*/
public abstract class RelIterate extends RelBase {

/**
* @return a standard {@link RelIterate} instance.
*/
@NotNull
public static RelIterate standard(@NotNull Rex rex) {
return new Impl(rex);
}

/**
* @return input rex (child 0)
*/
Expand All @@ -35,4 +43,19 @@ protected final List<Operator> children() {
public <R, C> R accept(@NotNull Visitor<R, C> 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;
}
}
}
Loading

0 comments on commit beb149e

Please sign in to comment.