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

Updates engine to be based upon the V1 plan interfaces #1548

Closed
wants to merge 12 commits into from
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build
~$*
.gradle
out/

partiql-parser/src/main/gen

# Created by https://www.toptal.com/developers/gitignore/api/vim,git,java,emacs,kotlin,eclipse,intellij+all,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,git,java,emacs,kotlin,eclipse,intellij+all,macos
Expand Down
18 changes: 7 additions & 11 deletions partiql-cli/src/main/kotlin/org/partiql/cli/pipeline/Pipeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.partiql.errors.ProblemSeverity
import org.partiql.eval.PartiQLEngine
import org.partiql.eval.PartiQLResult
import org.partiql.parser.PartiQLParser
import org.partiql.plan.PartiQLPlan
import org.partiql.plan.v1.PartiQLPlan
import org.partiql.planner.PartiQLPlanner
import org.partiql.spi.connector.Connector
import java.time.Instant
Expand Down Expand Up @@ -41,11 +41,6 @@ internal class Pipeline private constructor(
.catalog(currentCatalog)
.catalogs(*catalogs.toTypedArray())
.build()

fun engine() = PartiQLEngine.Session(
catalogs = connectors,
mode = mode
)
}

/**
Expand All @@ -69,12 +64,13 @@ internal class Pipeline private constructor(
if (errors.isNotEmpty()) {
throw RuntimeException(errors.joinToString())
}
return result.plan
TODO("Add V1 planner to the CLI")
}

private fun execute(plan: PartiQLPlan, session: Session): PartiQLResult {
val statement = engine.prepare(plan, session.engine())
return engine.execute(statement)
// val statement = engine.prepare(plan, session.mode, session.planner())
// return engine.execute(statement)
TODO("Add V1 planner to the CLI")
}

private class ProblemListener : ProblemCallback {
Expand All @@ -91,14 +87,14 @@ internal class Pipeline private constructor(
fun default(): Pipeline {
val parser = PartiQLParser.default()
val planner = PartiQLPlanner.standard()
val engine = PartiQLEngine.default()
val engine = PartiQLEngine.standard()
return Pipeline(parser, planner, engine)
}

fun strict(): Pipeline {
val parser = PartiQLParser.default()
val planner = PartiQLPlanner.builder().signal().build()
val engine = PartiQLEngine.default()
val engine = PartiQLEngine.standard()
return Pipeline(parser, planner, engine)
}
}
Expand Down
30 changes: 9 additions & 21 deletions partiql-eval/api/partiql-eval.api
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
public abstract interface class org/partiql/eval/PartiQLEngine {
public static final field Companion Lorg/partiql/eval/PartiQLEngine$Companion;
public static fun builder ()Lorg/partiql/eval/PartiQLEngineBuilder;
public static fun default ()Lorg/partiql/eval/PartiQLEngine;
public abstract fun execute (Lorg/partiql/eval/PartiQLStatement;)Lorg/partiql/eval/PartiQLResult;
public abstract fun prepare (Lorg/partiql/plan/PartiQLPlan;Lorg/partiql/eval/PartiQLEngine$Session;)Lorg/partiql/eval/PartiQLStatement;
public static fun builder ()Lorg/partiql/eval/builder/PartiQLEngineBuilder;
public abstract fun prepare (Lorg/partiql/plan/v1/PartiQLPlan;Lorg/partiql/eval/PartiQLEngine$Mode;Lorg/partiql/planner/catalog/Session;)Lorg/partiql/eval/PartiQLStatement;
public static fun standard ()Lorg/partiql/eval/PartiQLEngine;
}

public final class org/partiql/eval/PartiQLEngine$Companion {
public final fun builder ()Lorg/partiql/eval/PartiQLEngineBuilder;
public final fun default ()Lorg/partiql/eval/PartiQLEngine;
public final fun builder ()Lorg/partiql/eval/builder/PartiQLEngineBuilder;
public final fun standard ()Lorg/partiql/eval/PartiQLEngine;
}

public final class org/partiql/eval/PartiQLEngine$Mode : java/lang/Enum {
Expand All @@ -18,19 +17,6 @@ public final class org/partiql/eval/PartiQLEngine$Mode : java/lang/Enum {
public static fun values ()[Lorg/partiql/eval/PartiQLEngine$Mode;
}

public final class org/partiql/eval/PartiQLEngine$Session {
public fun <init> ()V
public fun <init> (Ljava/util/Map;Lorg/partiql/eval/PartiQLEngine$Mode;)V
public synthetic fun <init> (Ljava/util/Map;Lorg/partiql/eval/PartiQLEngine$Mode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getCatalogs ()Ljava/util/Map;
public final fun getMode ()Lorg/partiql/eval/PartiQLEngine$Mode;
}

public final class org/partiql/eval/PartiQLEngineBuilder {
public fun <init> ()V
public final fun build ()Lorg/partiql/eval/PartiQLEngine;
}

public abstract interface class org/partiql/eval/PartiQLResult {
}

Expand All @@ -57,9 +43,11 @@ public final class org/partiql/eval/PartiQLResult$Value : org/partiql/eval/Parti
}

public abstract interface class org/partiql/eval/PartiQLStatement {
public abstract fun execute ()Ljava/lang/Object;
public abstract fun execute (Lorg/partiql/planner/catalog/Session;)Lorg/partiql/eval/PartiQLResult;
}

public abstract interface class org/partiql/eval/PartiQLStatement$Query : org/partiql/eval/PartiQLStatement {
public final class org/partiql/eval/builder/PartiQLEngineBuilder {
public fun <init> ()V
public final fun build ()Lorg/partiql/eval/PartiQLEngine;
}

1 change: 0 additions & 1 deletion partiql-eval/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies {
testImplementation(Deps.junitVintage) // Enables JUnit4
}

// Disabled for partiql-eval project at initialization.
kotlin {
explicitApi = null
}
Expand Down
23 changes: 11 additions & 12 deletions partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.partiql.eval

import org.partiql.plan.PartiQLPlan
import org.partiql.spi.connector.Connector
import org.partiql.eval.builder.PartiQLEngineBuilder
import org.partiql.plan.v1.PartiQLPlan
import org.partiql.planner.catalog.Session

/**
* PartiQL's Experimental Engine.
Expand All @@ -17,28 +18,26 @@ import org.partiql.spi.connector.Connector
* This engine also internalizes the mechanics of the engine itself. Internally, it creates a physical plan to operate on,
* and it executes directly on that plan. The limited number of APIs exposed in this library is intentional to allow for
* under-the-hood experimentation by the PartiQL Community.
*
*
* TODO rename PartiQLEngine to PartiQLCompiler as it produces the statement (statement holds its own execution logic).
*/
public interface PartiQLEngine {

public fun prepare(plan: PartiQLPlan, session: Session): PartiQLStatement<*>

// TODO: Pass session variable during statement execution once we finalize data structure for session.
public fun execute(statement: PartiQLStatement<*>): PartiQLResult
public fun prepare(plan: PartiQLPlan, mode: Mode, session: Session): PartiQLStatement

companion object {

@JvmStatic
public fun builder(): PartiQLEngineBuilder = PartiQLEngineBuilder()

@JvmStatic
fun default() = PartiQLEngineBuilder().build()
fun standard() = PartiQLEngineBuilder().build()
}

public class Session(
val catalogs: Map<String, Connector> = mapOf(),
val mode: Mode = Mode.PERMISSIVE
)

/**
* TODO move mode to the session ??
*/
public enum class Mode {
PERMISSIVE,
STRICT // AKA, Type Checking Mode in the PartiQL Specification
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.partiql.eval

import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.planner.catalog.Session

/**
* Represents a compiled PartiQL Plan ready for execution.
* Represents a compiled PartiQL statement ready for execution.
*/
sealed interface PartiQLStatement<T> {
public interface PartiQLStatement {

public fun execute(): T

@OptIn(PartiQLValueExperimental::class)
interface Query : PartiQLStatement<PartiQLValue>
public fun execute(session: Session): PartiQLResult
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.partiql.eval.builder

import org.partiql.eval.PartiQLEngine
import org.partiql.eval.internal.SqlEngine

class PartiQLEngineBuilder {

/**
* Build the builder, return an implementation of a [PartiQLEngine]
*
* @return
*/
public fun build(): PartiQLEngine = SqlEngine()
}
Loading
Loading