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

[V1] Address 1.0 partiql-plan feedback and cleanup #1665

Merged
merged 19 commits into from
Dec 6, 2024
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
4 changes: 2 additions & 2 deletions docs/wiki/v1/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ I have labelled these children in the illustration so that you can see where the
RelLimit
/ \
x:<Value> RelOffset
/ \
y:<Value> z:<Rel>
/ \
y:<Value> z:<Rel>
```

The compiler will look for this pattern in the operator tree, and produce a match like so,
Expand Down
2 changes: 1 addition & 1 deletion partiql-ast/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ The Visitor pattern is the most widely misunderstood pattern in all of Design Pa

The trouble starts with terminology. The pattern isn’t about “visiting”, and the “accept” method in it doesn’t conjure up any helpful imagery either. Many think the pattern has to do with traversing trees, which isn’t the case at all. We are going to use it on a set of classes that are tree-like, but that’s a coincidence. As you’ll see, the pattern works as well on a single object.

The Visitor pattern is really about approximating the functional style within an OOP language. It lets us add new columns to that table easily. We can define all of the behavior for a new operation on a set of types in one place, without having to touch the types themselves. It does this the same way we solve almost every problem in computer science: by adding a layer of indirection.
The Visitor pattern is really about approximating the functional style within an OOP language. It lets us add new columns to that table easily. We can define all of the behavior for a new action on a set of types in one place, without having to touch the types themselves. It does this the same way we solve almost every problem in computer science: by adding a layer of indirection.

-- Robert Nystrom, Crafting Interpreters
____
Expand Down
11 changes: 7 additions & 4 deletions partiql-eval/api/partiql-eval.api
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ public abstract interface class org/partiql/eval/Statement {
}

public class org/partiql/eval/compiler/Match {
public fun <init> (Lorg/partiql/plan/Operator;Ljava/util/List;)V
public fun children (I)Ljava/util/List;
public fun operator (I)Lorg/partiql/plan/Operator;
public fun <init> (Lorg/partiql/plan/Operand;)V
public fun getOperand ()Lorg/partiql/plan/Operand;
}

public abstract interface class org/partiql/eval/compiler/PartiQLCompiler {
Expand All @@ -70,7 +69,11 @@ public class org/partiql/eval/compiler/Pattern {

public abstract class org/partiql/eval/compiler/Strategy {
public fun <init> (Lorg/partiql/eval/compiler/Pattern;)V
public abstract fun apply (Lorg/partiql/eval/compiler/Match;)Lorg/partiql/eval/Expr;
public abstract fun apply (Lorg/partiql/eval/compiler/Match;Lorg/partiql/eval/Mode;Lorg/partiql/eval/compiler/Strategy$Callback;)Lorg/partiql/eval/Expr;
public fun getPattern ()Lorg/partiql/eval/compiler/Pattern;
}

public abstract interface class org/partiql/eval/compiler/Strategy$Callback {
public abstract fun apply (Lorg/partiql/plan/Operator;)Lorg/partiql/eval/Expr;
}

39 changes: 10 additions & 29 deletions partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
package org.partiql.eval.compiler;

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

import java.util.Collections;
import java.util.List;
import org.partiql.plan.Operand;

/**
* Match represents a subtree match to be sent to the
*/
public class Match {

private final Operator[] operators;
private final List<List<Expr>> children;
private final Operand[] operands;

/**
* Single operator match with zero-or-more inputs.
* Single operand match with zero-or-more inputs.
*
* @param operator matched logical operator.
* @param children compiled child operators.
* @param operand matched logical operand.
*/
public Match(@NotNull Operator operator, @NotNull List<Expr> children) {
this.operators = new Operator[]{operator};
this.children = Collections.singletonList(children);
}

/**
* Get the i-th operator (pre-order) matched by the pattern.
*
* @param i 0-indexed
* @return Operator
*/
@NotNull
public Operator operator(int i) {
return operators[i];
public Match(@NotNull Operand operand) {
this.operands = new Operand[]{operand};
}

/**
* Get the i-th input to this pattern.
* Get the first (or only) operand
*
* @param i 0-indexed
* @return Expr
* @return Operand
*/
@NotNull
public List<Expr> children(int i) {
return children.get(i);
public Operand getOperand() {
return operands[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jetbrains.annotations.NotNull;
import org.partiql.eval.Expr;
import org.partiql.eval.Mode;
import org.partiql.plan.Operator;

/**
Expand Down Expand Up @@ -34,8 +35,22 @@ public Pattern getPattern() {
* Applies the strategy to a logical plan operator and returns the physical operation (expr).
*
* @param match holds the matched operators
* @param mode evaluation mode
* @param callback for compiling arguments of matched operators
* @return the physical operation
*/
@NotNull
public abstract Expr apply(@NotNull Match match);
public abstract Expr apply(@NotNull Match match, @NotNull Mode mode, @NotNull Callback callback);

/**
* A compilation callback for strategies to compile arguments of matched operators.
*/
public interface Callback {

/**
* @return a physical operator (expr) for the logical operator.
*/
@NotNull
Expr apply(@NotNull Operator operator);
}
}
Loading
Loading