Skip to content

Commit

Permalink
Fix local build
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Nov 5, 2024
1 parent 31e3cdd commit e03a35a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 25 deletions.
13 changes: 6 additions & 7 deletions partiql-eval/api/partiql-eval.api
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public abstract interface class org/partiql/eval/Statement {
}

public class org/partiql/eval/compiler/Match {
public fun <init> (Lorg/partiql/plan/Operator;)V
public fun <init> ([Lorg/partiql/plan/Operator;)V
public fun get (I)Lorg/partiql/plan/Operator;
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 abstract interface class org/partiql/eval/compiler/PartiQLCompiler {
Expand All @@ -63,16 +63,15 @@ public class org/partiql/eval/compiler/PartiQLCompiler$Builder {
}

public class org/partiql/eval/compiler/Pattern {
protected fun <init> (Ljava/lang/Class;)V
protected fun <init> (Ljava/lang/Class;Ljava/util/function/Predicate;Ljava/util/List;)V
public fun <init> (Ljava/lang/Class;)V
protected fun <init> (Ljava/lang/Class;Ljava/util/function/Predicate;)V
public fun matches (Lorg/partiql/plan/Operator;)Z
}

public abstract class org/partiql/eval/compiler/Strategy {
public final field pattern Lorg/partiql/eval/compiler/Pattern;
protected fun <init> (Lorg/partiql/eval/compiler/Pattern;)V
public abstract fun apply (Lorg/partiql/eval/compiler/Match;)Lorg/partiql/eval/Expr;
public static fun pattern (Ljava/lang/Class;)Lorg/partiql/eval/compiler/Pattern;
public static fun pattern (Ljava/lang/Class;Ljava/util/function/Predicate;)Lorg/partiql/eval/compiler/Pattern;
public fun getPattern ()Lorg/partiql/eval/compiler/Pattern;
}

Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,6 @@ public Builder addStrategy(Strategy strategy) {
return this;
}

/**
* Adds a list of strategies to the compiler.
*
* @param strategies The strategies to add.
* @return this.
*/
public Builder addAllStrategies(@NotNull List<Strategy> strategies) {
this.strategies.addAll(strategies);
return this;
}

/**
* @return A new [PartiQLCompiler].
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.partiql.eval.compiler

import org.partiql.eval.Environment
import org.partiql.eval.Expr
import org.partiql.eval.ExprRelation
import org.partiql.eval.Mode
import org.partiql.eval.Row
import org.partiql.eval.Statement
import org.partiql.eval.internal.operator.rex.ExprLit
import org.partiql.parser.PartiQLParser
import org.partiql.plan.rel.RelLimit
import org.partiql.planner.PartiQLPlanner
import org.partiql.spi.catalog.Session
import org.partiql.spi.value.Datum
import kotlin.test.Test
import kotlin.test.assertTrue

Expand All @@ -20,7 +21,13 @@ public class StrategyTest {
private val parser = PartiQLParser.standard()
private val planner = PartiQLPlanner.standard()
private val session = Session.empty()
private val nil = ExprLit(Datum.nullValue())

private class MyLimit : ExprRelation {
override fun open(env: Environment) = error("open")
override fun close() = error("close")
override fun hasNext(): Boolean = false
override fun next(): Row = error("next")
}

@Test
fun strategy() {
Expand All @@ -29,23 +36,23 @@ public class StrategyTest {
val strategy = object : Strategy(pattern) {
override fun apply(match: Match): Expr {
trigged = true
return nil
return MyLimit()
}
}
// ignore output
val input = "select * from [1,2] limit 100"
compile(input, listOf(strategy))
compile(input, strategy)
// assert the strategy was triggered
assertTrue(trigged, "the compiler did not apply the custom strategy")
}

// Helper to "compile with strategies".
private fun compile(input: String, strategies: List<Strategy>): Statement {
private fun compile(input: String, strategy: Strategy): Statement {
val mode = Mode.STRICT()
val ast = parser.parse(input).statements[0]
val plan = planner.plan(ast, session).plan
val compiler = PartiQLCompiler.builder()
.addAllStrategies(strategies)
.addStrategy(strategy)
.build()
return compiler.prepare(plan, mode)
}
Expand Down
Loading

0 comments on commit e03a35a

Please sign in to comment.