-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds operand concept for handling vararg inputs
- Loading branch information
Showing
54 changed files
with
356 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 10 additions & 29 deletions
39
partiql-eval/src/main/java/org/partiql/eval/compiler/Match.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.partiql.plan; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* Operands in an operator tree used for strategy and rule pattern matching. | ||
*/ | ||
public interface Operand extends Iterable<Operator> { | ||
|
||
/** | ||
* @return a single operand | ||
*/ | ||
public static Operand single(Operator operator) { | ||
return new Single(operator); | ||
} | ||
|
||
/** | ||
* @return a variadic operand | ||
* | ||
* See ImmutableCollections.java ListCopy. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static Operand vararg(List<? extends Operator> operators) { | ||
return new Variadic((List<Operator>) operators); | ||
} | ||
|
||
/** | ||
* A single operator. | ||
*/ | ||
public class Single implements Operand { | ||
|
||
@NotNull | ||
public final Operator operator; | ||
|
||
private Single(@NotNull Operator operator) { | ||
this.operator = operator; | ||
} | ||
|
||
|
||
@NotNull | ||
@Override | ||
public Iterator<Operator> iterator() { | ||
return List.of(operator).iterator(); | ||
} | ||
} | ||
|
||
/** | ||
* A variadic operator. | ||
*/ | ||
public class Variadic implements Operand { | ||
|
||
@NotNull | ||
public final List<Operator> operators; | ||
|
||
private Variadic(@NotNull List<Operator> operators) { | ||
this.operators = operators; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Iterator<Operator> iterator() { | ||
return operators.iterator(); | ||
} | ||
} | ||
} |
Oops, something went wrong.