Skip to content

Commit

Permalink
Updates rels to java abc
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Nov 27, 2024
1 parent 3d6ddac commit 7886f19
Show file tree
Hide file tree
Showing 63 changed files with 838 additions and 766 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal class StandardCompiler(strategies: List<Strategy>) : PartiQLCompiler {

override fun visitAggregate(rel: RelAggregate, ctx: Unit): ExprRelation {
val input = compile(rel.getInput(), ctx)
val aggs = rel.getCalls().map { call ->
val aggs = rel.getMeasures().map { call ->
val agg = call.getAgg()
val args = call.getArgs().map { compile(it, ctx).catch() }
val distinct = call.isDistinct()
Expand Down Expand Up @@ -241,7 +241,7 @@ internal class StandardCompiler(strategies: List<Strategy>) : PartiQLCompiler {
}

override fun visitIterate(rel: RelIterate, ctx: Unit): ExprRelation {
val input = compile(rel.getInput(), ctx)
val input = compile(rel.getRex(), ctx)
return when (mode) {
Mode.PERMISSIVE -> RelOpIteratePermissive(input)
Mode.STRICT -> RelOpIterate(input)
Expand Down
105 changes: 90 additions & 15 deletions partiql-plan/src/main/java/org/partiql/plan/Collation.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,105 @@
package org.partiql.plan
package org.partiql.plan;

import org.partiql.plan.rex.Rex
import org.jetbrains.annotations.NotNull;
import org.partiql.plan.rex.Rex;
import org.partiql.spi.Enum;

/**
* TODO DOCUMENTATION
* Represents a collation, which is a resolved sort specification.
*/
public interface Collation {

/**
* TODO REPLACE WITH COLUMN INDEX
* 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>
*
* @return the column to sort by
*/
public fun getRex(): Rex
public Rex getColumn();

public fun getOrder(): Order
/**
* @return ASC, DESC, or OTHER
*/
public Order getOrder();

/**
* @return NULL ordering
*/
public Nulls getNulls();

/**
* Collation value ordering.
*/
public final class Order extends Enum {

private Order(int code) {
super(code);
}

public fun getNulls(): Nulls
public static final int UNKNOWN = 0;
public static final int ASC = 1;
public static final int DESC = 2;

public enum class Order {
ASC,
DESC,
OTHER,
@NotNull
public static Order ASC() {
return new Order(ASC);
}

@NotNull
public static Order DESC() {
return new Order(DESC);
}

@Override
public String toString() {
int code = code();
switch (code) {
case ASC:
return "ASC";
case DESC:
return "DESC";
default:
return String.valueOf(code);
}
}
}

public enum class Nulls {
FIRST,
LAST,
OTHER,
/**
* Collation null ordering.
*/
public final class Nulls extends Enum {

private Nulls(int code) {
super(code);
}

public static final int UNKNOWN = 0;
public static final int FIRST = 1;
public static final int LAST = 2;

@NotNull
public static Order FIRST() {
return new Order(FIRST);
}

@NotNull
public static Order LAST() {
return new Order(LAST);
}

@Override
public String toString() {
int code = code();
switch (code) {
case FIRST:
return "FIRST";
case LAST:
return "LAST";
default:
return String.valueOf(code);
}
}
}
}
46 changes: 35 additions & 11 deletions partiql-plan/src/main/java/org/partiql/plan/Operator.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
package org.partiql.plan
package org.partiql.plan;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
* Operator is the interface for a logical plan operator.
* The interface for all logical plan operators.
*/
public interface Operator {

public fun <R, C> accept(visitor: Visitor<R, C>, ctx: C): R
/**
* Tag getter.
*/
public int getTag();

/**
* Get i-th child (input) operator.
* Tag setter.
*
* @param index
* @param tag new tag value.
*/
public fun getChild(index: Int) {
throw UnsupportedOperationException("getChild")
}
public void setTag(int tag);

/**
* Get all child (input) operators.
* Visitor accept.
*
* @return
* @param visitor visitor implementation.
* @param ctx visitor scoped args.
* @param <R> Visitor return type.
* @param <C> Visitor context type (scoped args).
* @return R
*/
public abstract <R, C> R accept(Visitor<R, C> visitor, C ctx);

/**
* Get i-th child (input) operator.
*
* @param index child index
* @return child operator
*/
@NotNull
public abstract Operator getChild(int index);

/**
* @return all child (input) operators.
*/
public fun getChildren(): Collection<Operator>
@NotNull
public abstract List<Operator> getChildren();
}
2 changes: 1 addition & 1 deletion partiql-plan/src/main/java/org/partiql/plan/rel/Rel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface Rel extends Operator {
* @return RelType.
*/
@NotNull
public RelType getType();
RelType getType();
}
43 changes: 33 additions & 10 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelAggregate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,58 @@
import org.partiql.spi.function.Aggregation;

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

/**
* Interface for an aggregation operator.
* <br>
* TODO GROUP STRATEGY <a href="https://github.com/partiql/partiql-lang-kotlin/issues/1664">ISSUE</a>
* The logical aggregation abstract base class.
*/
public interface RelAggregate extends Rel {
public abstract class RelAggregate extends RelBase {

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

private final RelType type = null;
private List<Operator> children = null;

/**
* @return the input (child 0)
*/
@NotNull
public abstract Rel getInput();

@NotNull
public Rel getInput();
public abstract Collection<Measure> getMeasures();

@NotNull
public Collection<Measure> getMeasures();
public abstract Collection<Rex> getGroups();

@NotNull
public Collection<Rex> getGroups();
@Override
public final RelType getType() {
if (type == null) {
throw new UnsupportedOperationException("Derive type is not implemented");
}
return type;
}

@NotNull
public Collection<Operator> getChildren();
@Override
public final List<Operator> getChildren() {
if (children == null) {
Rel c0 = getInput();
children = List.of(c0);
}
return children;
}

@Override
default public <R, C> R accept(Visitor<R, C> visitor, C ctx) {
public <R, C> R accept(Visitor<R, C> visitor, C ctx) {
return visitor.visitAggregate(this, ctx);
}

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

private final Aggregation agg;
private final Collection<Rex> args;
Expand Down
28 changes: 28 additions & 0 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.partiql.plan.rel;

import org.jetbrains.annotations.NotNull;
import org.partiql.plan.Operator;

/**
* Abstract base class for all relational operators.
*/
public abstract class RelBase implements Rel {

private int tag = 0;

@Override
public int getTag() {
return tag;
}

@Override
public void setTag(int tag) {
this.tag = tag;
}

@NotNull
@Override
public Operator getChild(int index) {
return getChildren().get(index);
}
}
45 changes: 39 additions & 6 deletions partiql-plan/src/main/java/org/partiql/plan/rel/RelCorrelate.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,57 @@
package org.partiql.plan.rel;

import org.jetbrains.annotations.NotNull;
import org.partiql.plan.JoinType;
import org.partiql.plan.Operator;
import org.partiql.plan.Visitor;

import java.util.List;

/**
* Logical operator for nested-loop joins (correlated subqueries // lateral joins).
* Logical nested-loop joins (correlated subqueries // lateral joins) abstract base class.
*/
public interface RelCorrelate extends Rel {
public abstract class RelCorrelate extends RelBase {

private final RelType type = null;
private List<Operator> children = null;

/**
* @return the left input (child 0)
*/
@NotNull
public abstract Rel getLeft();

/**
* @return the right input (child 1)
*/
@NotNull
public abstract Rel getRight();

@NotNull
public Rel getLeft();
public abstract JoinType getJoinType();

@NotNull
public Rel getRight();
@Override
public final RelType getType() {
if (type == null) {
throw new UnsupportedOperationException("Derive type is not implemented");
}
return type;
}

@NotNull
public Rel getJoinType();
@Override
public final List<Operator> getChildren() {
if (children == null) {
Rel c0 = getLeft();
Rel c1 = getRight();
children = List.of(c0, c1);
}
return children;
}

@Override
default public <R, C> R accept(Visitor<R, C> visitor, C ctx) {
public <R, C> R accept(Visitor<R, C> visitor, C ctx) {
return visitor.visitCorrelate(this, ctx);
}
}
Loading

0 comments on commit 7886f19

Please sign in to comment.