Skip to content

Commit

Permalink
Updates standard operator factory; removes builders
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Dec 2, 2024
1 parent 48a79d5 commit 0e10601
Show file tree
Hide file tree
Showing 12 changed files with 493 additions and 1,180 deletions.
3 changes: 1 addition & 2 deletions partiql-plan/src/main/java/org/partiql/plan/Collation.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public interface Collation {
/**
* API WARNING – THIS WILL BE REPLACED WITH AN `int` IN 1.0.
* <br>
* TODO replace with an `int` in 1.0
* TODO <a href="https://github.com/partiql/partiql-lang-kotlin/issues/1664">...</a>
* TODO <a href="https://github.com/partiql/partiql-lang-kotlin/issues/1664">replace with an `int` in 1.0</a>
*
* @return the column to sort by
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <pre>
* l, r <=> l CROSS JOIN r <=> l JOIN r ON TRUE
* </pre>
*/
public abstract class RelCorrelate extends RelBase {

Expand Down
33 changes: 16 additions & 17 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelJoin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,16 +9,16 @@
import java.util.List;

/**
* Logical join abstract base class.
* Logical theta-join abstract base class.
*/
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);
}

/**
Expand All @@ -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() {
Expand All @@ -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
Expand All @@ -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;
}
}
}
15 changes: 8 additions & 7 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.partiql.plan.Visitor;
import org.partiql.types.PType;

import java.util.Collection;
import java.util.List;

/**
Expand All @@ -16,15 +17,15 @@ public abstract class RexBag extends RexBase {
* @return new RexBag instance
*/
@NotNull
public static RexBag create(@NotNull List<Rex> values) {
public static RexBag create(@NotNull Collection<Rex> 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<Rex> getValues();
public abstract Collection<Rex> getValues();

@NotNull
@Override
Expand All @@ -35,7 +36,7 @@ protected final RexType type() {
@NotNull
@Override
protected final List<Operator> children() {
List<Rex> varargs = getValues();
List<Rex> varargs = getValues().stream().toList();
return List.copyOf(varargs);
}

Expand All @@ -46,15 +47,15 @@ public <R, C> R accept(@NotNull Visitor<R, C> visitor, C ctx) {

private static class Impl extends RexBag {

private final List<Rex> values;
private final Collection<Rex> values;

private Impl(List<Rex> values) {
private Impl(Collection<Rex> values) {
this.values = values;
}

@NotNull
@Override
public List<Rex> getValues() {
public Collection<Rex> getValues() {
return values;
}
}
Expand Down
21 changes: 11 additions & 10 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

/**
Expand All @@ -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<Operator> children() {
return List.of();
Expand All @@ -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
Expand Down
Loading

0 comments on commit 0e10601

Please sign in to comment.