Skip to content

Commit

Permalink
Fix partiql-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Dec 3, 2024
1 parent 81f5eca commit 9c57242
Show file tree
Hide file tree
Showing 26 changed files with 186 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ internal class StandardCompiler(strategies: List<Strategy>) : PartiQLCompiler {
val collations = rel.getCollations().map {
val expr = compile(it.column, ctx)
val desc = it.order.code() == Collation.Order.DESC
val last = it.order.code() == Collation.Nulls.LAST
val last = it.nulls.code() == Collation.Nulls.LAST
RelOpSort.Collation(expr, desc, last)
}
return RelOpSort(input, collations)
Expand Down Expand Up @@ -494,9 +494,9 @@ internal class StandardCompiler(strategies: List<Strategy>) : PartiQLCompiler {
}

override fun visitVar(rex: RexVar, ctx: Unit): ExprValue {
val depth = rex.getScope()
val scope = rex.scope
val offset = rex.getOffset()
return ExprVar(depth, offset)
return ExprVar(scope, offset)
}

/**
Expand Down
53 changes: 31 additions & 22 deletions partiql-plan/api/partiql-plan.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
public abstract interface class org/partiql/plan/Action {
}

public abstract interface class org/partiql/plan/Action$Query : org/partiql/plan/Action {
public abstract fun getRex ()Lorg/partiql/plan/rex/Rex;
}

public abstract interface class org/partiql/plan/Collation {
public abstract fun getColumn ()Lorg/partiql/plan/rex/Rex;
public abstract fun getNulls ()Lorg/partiql/plan/Collation$Nulls;
Expand All @@ -8,8 +15,8 @@ public final class org/partiql/plan/Collation$Nulls : org/partiql/spi/Enum {
public static final field FIRST I
public static final field LAST I
public static final field UNKNOWN I
public static fun FIRST ()Lorg/partiql/plan/Collation$Order;
public static fun LAST ()Lorg/partiql/plan/Collation$Order;
public static fun FIRST ()Lorg/partiql/plan/Collation$Nulls;
public static fun LAST ()Lorg/partiql/plan/Collation$Nulls;
public fun toString ()Ljava/lang/String;
}

Expand Down Expand Up @@ -117,13 +124,6 @@ public class org/partiql/plan/JoinType : org/partiql/spi/Enum {
public static fun RIGHT ()Lorg/partiql/plan/JoinType;
}

public abstract interface class org/partiql/plan/Operation {
}

public abstract interface class org/partiql/plan/Operation$Query : org/partiql/plan/Operation {
public abstract fun getRex ()Lorg/partiql/plan/rex/Rex;
}

public abstract interface class org/partiql/plan/Operator {
public abstract fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun getOperand (I)Lorg/partiql/plan/Operator;
Expand Down Expand Up @@ -370,16 +370,19 @@ public final class org/partiql/plan/Operators$DefaultImpls {
}

public abstract interface class org/partiql/plan/Plan {
public abstract fun getOperations ()Ljava/util/List;
public abstract fun getVersion ()Lorg/partiql/plan/Version;
public abstract fun getActions ()Ljava/util/List;
public fun getVersion ()Lorg/partiql/plan/Version;
}

public abstract interface class org/partiql/plan/Version {
public abstract fun toString ()Ljava/lang/String;
public class org/partiql/plan/Version : org/partiql/spi/Enum {
public static final field UNKNOWN I
public static fun UNKNOWN ()Lorg/partiql/plan/Version;
public fun toString ()Ljava/lang/String;
}

public abstract interface class org/partiql/plan/rel/Rel : org/partiql/plan/Operator {
public abstract fun getType ()Lorg/partiql/plan/rel/RelType;
public abstract fun setType (Lorg/partiql/plan/rel/RelType;)V
}

public abstract class org/partiql/plan/rel/RelAggregate : org/partiql/plan/rel/RelBase {
Expand Down Expand Up @@ -411,6 +414,7 @@ public abstract class org/partiql/plan/rel/RelBase : org/partiql/plan/rel/Rel {
public final fun getType ()Lorg/partiql/plan/rel/RelType;
protected abstract fun operands ()Ljava/util/List;
public fun setTag (I)V
public fun setType (Lorg/partiql/plan/rel/RelType;)V
protected abstract fun type ()Lorg/partiql/plan/rel/RelType;
}

Expand Down Expand Up @@ -569,11 +573,15 @@ public abstract class org/partiql/plan/rel/RelSort : org/partiql/plan/rel/RelBas
protected final fun type ()Lorg/partiql/plan/rel/RelType;
}

public abstract interface class org/partiql/plan/rel/RelType {
public abstract fun getField (Ljava/lang/String;)Lorg/partiql/types/Field;
public abstract fun getFieldSize ()I
public abstract fun getFields ()[Lorg/partiql/types/Field;
public abstract fun isOrdered ()Z
public class org/partiql/plan/rel/RelType {
public static final field ORDERED I
public fun getDegree ()I
public fun getField (I)Lorg/partiql/types/Field;
public fun getField (Ljava/lang/String;)Lorg/partiql/types/Field;
public fun getFields ()[Lorg/partiql/types/Field;
public fun isOrdered ()Z
public static fun of ([Lorg/partiql/types/Field;)Lorg/partiql/plan/rel/RelType;
public static fun of ([Lorg/partiql/types/Field;I)Lorg/partiql/plan/rel/RelType;
}

public abstract class org/partiql/plan/rel/RelUnion : org/partiql/plan/rel/RelBase {
Expand Down Expand Up @@ -601,6 +609,7 @@ public abstract class org/partiql/plan/rel/RelUnpivot : org/partiql/plan/rel/Rel

public abstract interface class org/partiql/plan/rex/Rex : org/partiql/plan/Operator {
public abstract fun getType ()Lorg/partiql/plan/rex/RexType;
public abstract fun setType (Lorg/partiql/plan/rex/RexType;)V
}

public abstract class org/partiql/plan/rex/RexArray : org/partiql/plan/rex/RexBase {
Expand Down Expand Up @@ -629,6 +638,7 @@ public abstract class org/partiql/plan/rex/RexBase : org/partiql/plan/rex/Rex {
public final fun getType ()Lorg/partiql/plan/rex/RexType;
protected abstract fun operands ()Ljava/util/List;
public fun setTag (I)V
public final fun setType (Lorg/partiql/plan/rex/RexType;)V
protected abstract fun type ()Lorg/partiql/plan/rex/RexType;
}

Expand All @@ -645,6 +655,7 @@ public abstract class org/partiql/plan/rex/RexCall : org/partiql/plan/rex/RexBas
public abstract class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/RexBase {
public fun <init> ()V
public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static fun branch (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase$Branch;
public static fun create (Lorg/partiql/plan/rex/Rex;Ljava/util/List;Lorg/partiql/plan/rex/Rex;)Lorg/partiql/plan/rex/RexCase;
public abstract fun getBranches ()Ljava/util/List;
public abstract fun getDefault ()Lorg/partiql/plan/rex/Rex;
Expand All @@ -654,7 +665,6 @@ public abstract class org/partiql/plan/rex/RexCase : org/partiql/plan/rex/RexBas
}

public class org/partiql/plan/rex/RexCase$Branch {
public fun <init> (Lorg/partiql/plan/rex/Rex;Lorg/partiql/plan/rex/Rex;)V
public fun getCondition ()Lorg/partiql/plan/rex/Rex;
public fun getResult ()Lorg/partiql/plan/rex/Rex;
}
Expand Down Expand Up @@ -878,20 +888,19 @@ public abstract class org/partiql/plan/rex/RexTable : org/partiql/plan/rex/RexBa
}

public class org/partiql/plan/rex/RexType {
public fun <init> (Lorg/partiql/types/PType;)V
public static fun dynamic ()Lorg/partiql/plan/rex/RexType;
public fun equals (Ljava/lang/Object;)Z
public fun getPType ()Lorg/partiql/types/PType;
public fun hashCode ()I
public static fun of (Lorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexType;
public fun toString ()Ljava/lang/String;
}

public abstract class org/partiql/plan/rex/RexVar : org/partiql/plan/rex/RexBase {
public fun <init> ()V
public fun accept (Lorg/partiql/plan/OperatorVisitor;Ljava/lang/Object;)Ljava/lang/Object;
public static fun create (IILorg/partiql/types/PType;)Lorg/partiql/plan/rex/RexVar;
public abstract fun getDepth ()I
public abstract fun getOffset ()I
public abstract fun getScope ()I
protected final fun operands ()Ljava/util/List;
}

9 changes: 6 additions & 3 deletions partiql-plan/src/main/java/org/partiql/plan/Exclusion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,20 @@ public class Exclusion(variable: RexVar, items: List<Item>) {
*/
public fun getItems(): List<Item> = _items

// generated
/**
* UNSTABLE AND WILL BE DELETED (this only exists for unit tests)
*/
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Exclusion) return false
if (_variable.scope != other._variable.scope || _variable.offset != other._variable.offset) return false
if (_items != other._items) return false

return true
}

// generated
/**
* UNSTABLE AND WILL BE DELETED (this only exists for unit tests)
*/
override fun hashCode(): Int {
var result = _variable.hashCode()
result = 31 * result + _items.hashCode()
Expand Down
9 changes: 7 additions & 2 deletions partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
public interface Rel extends Operator {

/**
* @return RelType.
* @return the type of the rows produced by this rel.
*/
@NotNull
RelType getType();
public RelType getType();

/**
* @param type the new type of the rows produced by this Rex.
*/
public void setType(@NotNull RelType type);
}
5 changes: 5 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public final RelType getType() {
return type;
}

@Override
public void setType(@NotNull RelType type) {
this.type = type;
}

@NotNull
@Override
public final Operator getOperand(int index) {
Expand Down
54 changes: 48 additions & 6 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,62 @@
import org.partiql.types.Field;

/**
* Analogous to a ROW type, consider rank/cardinality or other hint mechanisms.
* Analogous to a ROW type, consider cardinality estimates or other hint mechanisms.
*/
public interface RelType {
public class RelType {

int getFieldSize();
public static final int ORDERED = 0x01;

private final Field[] fields;
private final boolean ordered;

private RelType(Field[] fields, boolean ordered) {
this.fields = fields;
this.ordered = ordered;
}

@NotNull
public static RelType of(Field... fields) {
return of(fields, 0);
}

@NotNull
public static RelType of(Field[] fields, int properties) {
boolean ordered = (properties & ORDERED) != 0;
return new RelType(fields, ordered);
}

public int getDegree() {
return fields.length;
}

@NotNull
public Field[] getFields() {
return fields;
}

@NotNull
Field[] getFields();
public Field getField(int index) {
if (index < 0 || index >= fields.length) {
throw new IllegalArgumentException("field index out of bounds: " + index);
}
return fields[index]; // bounds check?
}

@NotNull
Field getField(String name);
public Field getField(String name) {
for (Field field : fields) {
if (field.getName().equals(name)) {
return field;
}
}
throw new IllegalArgumentException("field name not found: " + name);
}

/**
* @return true if the rel produces an ordered stream of rows.
*/
boolean isOrdered();
public boolean isOrdered() {
return ordered;
}
}
4 changes: 2 additions & 2 deletions partiql-plan/src/main/java/org/partiql/plan/rex/Rex.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
public interface Rex extends Operator {

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

/**
* @param type the new 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static RexArray create(@NotNull List<Rex> values) {
@NotNull
@Override
protected final RexType type() {
return new RexType(PType.array());
return RexType.of(PType.array());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static RexBag create(@NotNull Collection<Rex> values) {
@NotNull
@Override
protected final RexType type() {
return new RexType(PType.bag());
return RexType.of(PType.bag());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static RexCall create(@NotNull Function.Instance function, @NotNull List<

@Override
protected RexType type() {
return new RexType(getFunction().returns);
return RexType.of(getFunction().returns);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static RexCast create(@NotNull Rex operand, @NotNull PType target) {

@NotNull
protected final RexType type() {
return new RexType(getTarget());
return RexType.of(getTarget());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.partiql.plan.Operator;
import org.partiql.plan.OperatorVisitor;
import org.partiql.spi.function.Function;
import org.partiql.types.PType;

import java.util.List;

Expand Down Expand Up @@ -38,7 +39,7 @@ public static RexDispatch create(String name, List<Function> functions, List<Rex
@NotNull
@Override
protected final RexType type() {
return RexType.dynamic();
return RexType.of(PType.dynamic());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static RexError create() {
@Override
protected RexType type() {
// TODO SHOULD BE UNKNOWN
return new RexType(PType.dynamic());
return RexType.of(PType.dynamic());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static RexLit create(@NotNull Datum value) {
@NotNull
@Override
protected final RexType type() {
return new RexType(getDatum().getType());
return RexType.of(getDatum().getType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static RexPivot create(@NotNull Rel input, @NotNull Rex key, @NotNull Rex
@NotNull
@Override
protected final RexType type() {
return new RexType(PType.struct());
return RexType.of(PType.struct());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static RexSelect create(@NotNull Rel input, @NotNull Rex constructor) {
@NotNull
@Override
protected final RexType type() {
return new RexType(PType.bag());
return RexType.of(PType.bag());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static RexSpread create(@NotNull List<Rex> args) {
@NotNull
@Override
protected final RexType type() {
return new RexType(PType.struct());
return RexType.of(PType.struct());
}

@NotNull
Expand Down
Loading

0 comments on commit 9c57242

Please sign in to comment.