Skip to content

Commit

Permalink
Merge v1-udop-strat
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Oct 17, 2024
2 parents 8e9a540 + 7835732 commit 8cf5e65
Show file tree
Hide file tree
Showing 82 changed files with 823 additions and 836 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.partiql.ast.Statement
import org.partiql.errors.Problem
import org.partiql.errors.ProblemCallback
import org.partiql.errors.ProblemSeverity
import org.partiql.eval.Mode
import org.partiql.eval.PartiQLEvaluator
import org.partiql.eval.compiler.PartiQLCompiler
import org.partiql.parser.PartiQLParser
import org.partiql.plan.Plan
import org.partiql.planner.PartiQLPlanner
Expand All @@ -15,7 +14,7 @@ import org.partiql.spi.value.Datum
internal class Pipeline private constructor(
private val parser: PartiQLParser,
private val planner: PartiQLPlanner,
private val evaluator: PartiQLEvaluator,
private val compiler: PartiQLCompiler,
) {

/**
Expand Down Expand Up @@ -62,14 +61,14 @@ internal class Pipeline private constructor(
fun default(): Pipeline {
val parser = PartiQLParser.standard()
val planner = PartiQLPlanner.standard()
val evaluator = PartiQLEvaluator.standard(Mode.PERMISSIVE())
val evaluator = PartiQLCompiler.standard()
return Pipeline(parser, planner, evaluator)
}

fun strict(): Pipeline {
val parser = PartiQLParser.standard()
val planner = PartiQLPlanner.builder().signal().build()
val evaluator = PartiQLEvaluator.standard()
val evaluator = PartiQLCompiler.standard()
return Pipeline(parser, planner, evaluator)
}
}
Expand Down
56 changes: 38 additions & 18 deletions partiql-eval/api/partiql-eval.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
public class org/partiql/eval/Environment {
public fun <init> ()V
public fun get (II)Lorg/partiql/spi/value/Datum;
public fun push (Lorg/partiql/eval/Row;)Lorg/partiql/eval/Environment;
public fun toString ()Ljava/lang/String;
}

public class org/partiql/eval/Mode {
public static final field PERMISSIVE I
public static final field STRICT I
Expand All @@ -6,31 +13,44 @@ public class org/partiql/eval/Mode {
public fun code ()I
}

public abstract interface class org/partiql/eval/PartiQLCompiler {
public static fun builder ()Lorg/partiql/eval/PartiQLCompiler$Builder;
public abstract fun prepare (Lorg/partiql/plan/Plan;)Lorg/partiql/eval/Statement;
public static fun standard ()Lorg/partiql/eval/PartiQLCompiler;
public static fun standard (Lorg/partiql/eval/Mode;)Lorg/partiql/eval/PartiQLCompiler;
public class org/partiql/eval/Row {
public final field values [Lorg/partiql/spi/value/Datum;
public fun <init> ()V
public fun <init> ([Lorg/partiql/spi/value/Datum;)V
public fun concat (Lorg/partiql/eval/Row;)Lorg/partiql/eval/Row;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public static fun of ([Lorg/partiql/spi/value/Datum;)Lorg/partiql/eval/Row;
public fun toString ()Ljava/lang/String;
}

public class org/partiql/eval/PartiQLCompiler$Builder {
public fun build ()Lorg/partiql/eval/PartiQLCompiler;
public fun mode (Lorg/partiql/eval/Mode;)Lorg/partiql/eval/PartiQLCompiler$Builder;
public abstract interface class org/partiql/eval/Statement {
public abstract fun execute ()Lorg/partiql/spi/value/Datum;
}

public abstract interface class org/partiql/eval/PartiQLEvaluator {
public static fun builder ()Lorg/partiql/eval/PartiQLEvaluator$Builder;
public abstract fun eval (Lorg/partiql/plan/Plan;)Lorg/partiql/spi/value/Datum;
public static fun standard ()Lorg/partiql/eval/PartiQLEvaluator;
public static fun standard (Lorg/partiql/eval/Mode;)Lorg/partiql/eval/PartiQLEvaluator;
public abstract interface class org/partiql/eval/compiler/PartiQLCompiler {
public static fun builder ()Lorg/partiql/eval/compiler/PartiQLCompiler$Builder;
public abstract fun prepare (Lorg/partiql/plan/Plan;Lorg/partiql/eval/Mode;)Lorg/partiql/eval/Statement;
public static fun standard ()Lorg/partiql/eval/compiler/PartiQLCompiler;
}

public class org/partiql/eval/PartiQLEvaluator$Builder {
public fun build ()Lorg/partiql/eval/PartiQLEvaluator;
public fun compiler (Lorg/partiql/eval/PartiQLCompiler;)Lorg/partiql/eval/PartiQLEvaluator$Builder;
public class org/partiql/eval/compiler/PartiQLCompiler$Builder {
public fun build ()Lorg/partiql/eval/compiler/PartiQLCompiler;
}

public abstract interface class org/partiql/eval/Statement {
public abstract fun execute ()Lorg/partiql/spi/value/Datum;
public abstract interface class org/partiql/eval/operator/Expression : org/partiql/eval/operator/Operator {
public abstract fun eval (Lorg/partiql/eval/Environment;)Lorg/partiql/spi/value/Datum;
}

public abstract interface class org/partiql/eval/operator/Operator {
}

public abstract interface class org/partiql/eval/operator/Relation : java/lang/AutoCloseable, java/util/Iterator, org/partiql/eval/operator/Operator {
public abstract fun close ()V
public abstract fun hasNext ()Z
public synthetic fun next ()Ljava/lang/Object;
public abstract fun next ()Lorg/partiql/eval/Row;
public abstract fun open (Lorg/partiql/eval/Environment;)V
public fun remove ()V
}

6 changes: 4 additions & 2 deletions partiql-eval/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
Expand Down Expand Up @@ -36,7 +38,7 @@ dependencies {
}

kotlin {
explicitApi = null
explicitApi = ExplicitApiMode.Strict
}

tasks.shadowJar {
Expand All @@ -53,7 +55,7 @@ components.withType(AdhocComponentWithVariants::class.java).forEach { c ->
publish {
artifactId = "partiql-eval"
name = "PartiQL Lang Kotlin Evaluator"
description = "Experimental PartiQL plan-based evaluator"
description = "The PartiQL reference implementation evaluator."
}

tasks.processTestResources {
Expand Down
82 changes: 82 additions & 0 deletions partiql-eval/src/main/java/org/partiql/eval/Environment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.partiql.eval;

import org.partiql.spi.value.Datum;

/**
* This class holds the evaluation environment.
* <br>
* Developer Note: Attempts have been made at an interpreter stack, but has not worked well with nested lazy values.
* For example, an expression may return an inner lazy value (think subqueries), but the stack state may have changed
* BEFORE the inner lazy value is accessed. Here is my best attempt at illustrating this,
* <code>
* 0: +-PUSH(row)
* 1: +--|----bag.eval() // lazy iterator (push/pop and eval variables)
* 2: | +-POP
* 3: |
* 4: +-- .next() // woah! we called bag.next() from line:1, but we popped on line:2 so line:1 is invalid!
* </code>
* <br>
* The most basic solution we have is to pass a new environment into each nested scope.
*/
public class Environment {

private final Row[] stack;

/**
* Default constructor with empty stack.
*/
public Environment() {
this.stack = new Row[]{};
}

/**
* Private constructor with given stack.
* @param stack
*/
private Environment(Row[] stack) {
this.stack = stack;
}

/**
* Push a new row onto the stack.
*/
public Environment push(Row row) {
int n = stack.length;
Row[] next = new Row[n + 1];
next[0] = row;
if (n > 0) {
System.arraycopy(stack, 0, next, 1, n);
}
return new Environment(next);
}

/**
* Returns the variable at the specified depth and offset.
*
* @param depth Scope depth.
* @param offset Variable offset.
* @return Datum.
*/
public Datum get(int depth, int offset) {
try {
return stack[depth].values[offset];
} catch (IndexOutOfBoundsException ex) {
throw new RuntimeException("Invalid variable reference [$depth:$offset]\n$this");
}
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[stack]--------------\n");
for (int i = 0; i < stack.length; i++) {
sb.append("$i: $row");
sb.append("---------------------");
}
// if (scope.isEmpty()) {
// appendLine("empty")
// appendLine("---------------------")
// }
return "stack";
}
}
73 changes: 0 additions & 73 deletions partiql-eval/src/main/java/org/partiql/eval/PartiQLCompiler.java

This file was deleted.

68 changes: 0 additions & 68 deletions partiql-eval/src/main/java/org/partiql/eval/PartiQLEvaluator.java

This file was deleted.

Loading

0 comments on commit 8cf5e65

Please sign in to comment.