Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audits the org.partiql.plan.rex package #1710

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions partiql-plan/api/partiql-plan.api
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ public class org/partiql/plan/rex/RexSubqueryComp$Comparison : org/partiql/spi/E
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;
Expand All @@ -862,7 +861,6 @@ public class org/partiql/plan/rex/RexSubqueryComp$Quantifier : org/partiql/spi/E
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;
Expand Down
4 changes: 3 additions & 1 deletion partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
import org.partiql.plan.Operator;

/**
* A [Rex] is an [Operator] that produces a value.
* A {@link Rex} is an {@link Operator} that produces a value.
*/
public interface Rex extends Operator {

/**
* Gets the type of the value produced by this rex.
* @return the type of the value produced by this rex.
*/
@NotNull
public RexType getType();

/**
* Sets the 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);
Expand Down
3 changes: 3 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
public abstract class RexArray extends RexBase {

/**
* Creates a new RexArray instance.
* @param values the values of the array
* @return new RexArray instance
*/
@NotNull
Expand All @@ -21,6 +23,7 @@ public static RexArray create(@NotNull List<Rex> values) {
}

/**
* Gets the values of the array.
* @return the values of the array, also the operands.
*/
@NotNull
Expand Down
3 changes: 3 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public abstract class RexBag extends RexBase {

/**
* Creates a new bag expression.
* @param values bag values
* @return new RexBag instance
*/
@NotNull
Expand All @@ -24,6 +26,7 @@ public static RexBag create(@NotNull Collection<Rex> values) {
}

/**
* Gets the values of the bag.
* @return the values of the bag, also the operands (unordered).
*/
@NotNull
Expand Down
4 changes: 0 additions & 4 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ public final List<Operand> getOperands() {
}

/**
* PROTECTED (could also be package private atm).
*
* @return computed type.
*/
@NotNull
protected abstract RexType type();

/**
* PROTECTED (could also be package private atm).
*
* @return computed operands.
*/
@NotNull
Expand Down
8 changes: 8 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@
*/
public abstract class RexCall extends RexBase {

/**
* Creates a new scalar function expression.
* @param function the function instance backing the call
* @param args the arguments to the function
* @return a new scalar function expression
*/
@NotNull
public static RexCall create(@NotNull Function.Instance function, @NotNull List<Rex> args) {
return new Impl(function, args);
}

/**
* Returns the function to invoke.
* @return the function to invoke
*/
@NotNull
public abstract Function.Instance getFunction();

/**
* Returns the list of function arguments.
* @return the list of function arguments
*/
@NotNull
public abstract List<Rex> getArgs();
Expand Down
16 changes: 16 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,45 @@
*/
public abstract class RexCase extends RexBase {

/**
* Creates a new case expression.
* @param match the match expression, or {@code null} if none (operand 0)
* @param branches the list of branches (not operands)
* @param def the default expression, or {@code null} if none (not an operand)
* @return the new case expression
*/
@NotNull
public static RexCase create(@Nullable Rex match, @NotNull List<Branch> branches, @Nullable Rex def) {
return new Impl(match, branches, def);
}

/**
* Creates a new branch.
* @param condition the condition expression
* @param result the result expression
* @return the new branch
*/
@NotNull
public static Branch branch(@NotNull Rex condition, @NotNull Rex result) {
return new Branch(condition, result);
}

/**
* Gets the match expression, or {@code null} if none (operand 0).
* @return the match expression, or {@code null} if none (operand 0)
*/
@Nullable
public abstract Rex getMatch();

/**
* Gets the list of branches (not operands).
* @return the list of branches (not operands).
*/
@NotNull
public abstract List<Branch> getBranches();

/**
* Gets the default expression, or {@code null} if none (not an operand).
* @return the default expression, or {@code null} if none (not an operand)
*/
@Nullable
Expand Down
8 changes: 7 additions & 1 deletion partiql-plan/src/main/java/org/partiql/plan/rex/RexCast.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,32 @@
public abstract class RexCast extends RexBase {

/**
* @return new RexCast instance
* Creates a new cast instance.
* @param operand operand rex (operand 0)
* @param target target type
* @return new cast instance
*/
@NotNull
public static RexCast create(@NotNull Rex operand, @NotNull PType target) {
return new Impl(operand, target);
}

/**
* Gets the operand rex.
* @return operand rex (operand 0)
*/
@NotNull
public abstract Rex getOperand();

/**
* Gets the target type.
* @return target type
*/
@NotNull
public abstract PType getTarget();

@NotNull
@Override
protected final RexType type() {
return RexType.of(getTarget());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public abstract class RexCoalesce extends RexBase {

/**
* Create a new RexCoalesce instance.
* @param args list of operands
* @return new RexCoalesce instance
*/
@NotNull
Expand All @@ -20,6 +22,7 @@ public static RexCoalesce create(List<Rex> args) {
}

/**
* Gets the list of arguments.
* @return the list of arguments (also the operands).
*/
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
public abstract class RexDispatch extends RexBase {

/**
* Creates a new RexDispatch instance.
* @param name dynamic function name
* @param functions functions to dispatch to
* @param args function arguments
* @return new RexDispatch instance
*/
@NotNull
Expand All @@ -23,16 +27,19 @@ public static RexDispatch create(String name, List<Function> functions, List<Rex

/**
* Dynamic function name.
* @return dynamic function name
*/
public abstract String getName();

/**
* Returns the functions to dispatch to.
* @return functions to dispatch to
*/
public abstract List<Function> getFunctions();

/**
* Returns the list of function arguments.
* @return function arguments
*/
public abstract List<Rex> getArgs();

Expand Down
4 changes: 2 additions & 2 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexError.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public abstract class RexError extends RexBase {

/**
* Creates a new instance of RexError.
* @return new RexError instance
*/
@NotNull
Expand All @@ -24,8 +25,7 @@ public static RexError create() {
@NotNull
@Override
protected RexType type() {
// TODO SHOULD BE UNKNOWN
return RexType.of(PType.dynamic());
return RexType.of(PType.unknown());
}

@NotNull
Expand Down
6 changes: 6 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rex/RexLit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
public abstract class RexLit extends RexBase {

/**
* Creates a new literal value expression.
* @param value the literal value
* @return new RexLit instance
*/
@NotNull
public static RexLit create(@NotNull Datum value) {
return new Impl(value);
}

/**
* Returns the literal value.
* @return the literal value
*/
@NotNull
public abstract Datum getDatum();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
public abstract class RexNullIf extends RexBase {

/**
* Creates a new RexNullIf instance.
* @param v1 left operand
* @param v2 right operand
* @return new RexNullIf instance
*/
@NotNull
Expand All @@ -20,24 +23,26 @@ public static RexNullIf create(@NotNull Rex v1, @NotNull Rex v2) {
}

/**
* Gets the left operand.
* @return v1 rex (operand 0)
*/
@NotNull
public abstract Rex getV1();

/**
* Gets the right operand.
* @return v2 rex (operand 1)
*/
@NotNull
public abstract Rex getV2();

/**
* Gets the type of this expression.
* @return minimal common supertype of (NULL, typeof(v1))
*/
@NotNull
@Override
protected final RexType type() {

return getV1().getType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
public abstract class RexPathIndex extends RexBase {

/**
* Creates a new RexPathIndex instance.
* @param operand operand rex (operand 0)
* @param index index rex
* @return new RexPathIndex instance
*/
@NotNull
Expand All @@ -20,12 +23,14 @@ public static RexPathIndex create(@NotNull Rex operand, @NotNull Rex index) {
}

/**
* Gets the operand.
* @return operand rex (operand 0)
*/
@NotNull
public abstract Rex getOperand();

/**
* Gets the index.
* @return index rex
*/
public abstract Rex getIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
public abstract class RexPathKey extends RexBase {

/**
* Creates a new instance of RexPathKey
* @param operand operand rex (operand 0)
* @param key key rex
* @return new RexPathKey instance
*/
@NotNull
Expand All @@ -20,12 +23,14 @@ public static RexPathKey create(@NotNull Rex operand, @NotNull Rex key) {
}

/**
* Gets the operand rex.
* @return operand rex (operand 0)
*/
@NotNull
public abstract Rex getOperand();

/**
* Gets the key rex.
* @return key rex.
*/
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
public abstract class RexPathSymbol extends RexBase {

/**
* Creates a new RexPathSymbol instance.
* @param operand operand rex (operand 0)
* @param symbol symbol string
* @return new RexPathSymbol instance
*/
@NotNull
Expand All @@ -20,12 +23,14 @@ public static RexPathSymbol create(@NotNull Rex operand, @NotNull String symbol)
}

/**
* Gets the operand rex.
* @return operand rex (operand 0)
*/
@NotNull
public abstract Rex getOperand();

/**
* Gets the symbol string.
* @return symbol string
*/
@NotNull
Expand Down
Loading
Loading