From fb1d183c7dae160fac8bf821c00f37a1c8a31507 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 5 Aug 2024 15:04:23 -0700 Subject: [PATCH] Updates partiql-eval and runner to fix build --- .../eval/internal/PartiQLEngineDefaultTest.kt | 41 ++++++------- .../partiql/plugins/memory/MemoryConnector.kt | 26 ++++----- .../partiql/runner/executor/EvalExecutor.kt | 57 ++++++++----------- 3 files changed, 58 insertions(+), 66 deletions(-) diff --git a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt index 957b38d840..6069fb9c0d 100644 --- a/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt +++ b/partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt @@ -1,6 +1,7 @@ package org.partiql.eval.internal import com.amazon.ionelement.api.createIonElementLoader +import com.amazon.ionelement.api.loadSingleElement import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.parallel.Execution @@ -13,10 +14,11 @@ import org.partiql.parser.PartiQLParser import org.partiql.plan.PartiQLPlan import org.partiql.plan.debug.PlanPrinter import org.partiql.planner.builder.PartiQLPlannerBuilder +import org.partiql.planner.catalog.Name import org.partiql.planner.catalog.Session -import org.partiql.plugins.memory.MemoryCatalog import org.partiql.plugins.memory.MemoryConnector -import org.partiql.spi.connector.ConnectorSession +import org.partiql.plugins.memory.MemoryTable +import org.partiql.types.PType import org.partiql.types.StaticType import org.partiql.value.CollectionValue import org.partiql.value.PartiQLValue @@ -28,6 +30,7 @@ import org.partiql.value.int32Value import org.partiql.value.int64Value import org.partiql.value.intValue import org.partiql.value.io.PartiQLValueIonWriterBuilder +import org.partiql.value.ion.IonDatum import org.partiql.value.listValue import org.partiql.value.missingValue import org.partiql.value.nullValue @@ -1258,19 +1261,22 @@ class PartiQLEngineDefaultTest { internal fun assert() { val statement = parser.parse(input).root - val catalogBuilder = MemoryCatalog.builder().name("memory") - globals.forEach { global -> - catalogBuilder.define(global.name, global.type, loader.loadSingleElement(global.value)) - } - val catalog = catalogBuilder.build() - val connector = MemoryConnector(catalog) - val connectorSession = object : ConnectorSession { - override fun getQueryId(): String = "q" - override fun getUserId(): String = "u" - } + val connector = MemoryConnector.builder() + .name("memory") + .apply { + globals.forEach { + val table = MemoryTable.of( + name = Name.of(it.name), + schema = PType.fromStaticType(it.type), + datum = IonDatum.of(loadSingleElement(it.value)) + ) + define(table) + } + } + .build() val session = Session.builder() .catalog("memory") - .catalogs("memory" to connector.getMetadata(connectorSession)) + .catalogs(connector.getCatalog()) .build() val plan = planner.plan(statement, session) val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode)) @@ -1344,15 +1350,10 @@ class PartiQLEngineDefaultTest { private fun run(mode: PartiQLEngine.Mode): Pair { val statement = parser.parse(input).root - val catalog = MemoryCatalog.builder().name("memory").build() - val connector = MemoryConnector(catalog) - val connectorSession = object : ConnectorSession { - override fun getQueryId(): String = "q" - override fun getUserId(): String = "u" - } + val connector = MemoryConnector.builder().name("memory").build() val session = Session.builder() .catalog("memory") - .catalogs("memory" to connector.getMetadata(connectorSession)) + .catalogs(connector.getCatalog()) .build() val plan = planner.plan(statement, session) val prepared = engine.prepare(plan.plan, PartiQLEngine.Session(mapOf("memory" to connector), mode = mode)) diff --git a/plugins/partiql-memory/src/main/kotlin/org/partiql/plugins/memory/MemoryConnector.kt b/plugins/partiql-memory/src/main/kotlin/org/partiql/plugins/memory/MemoryConnector.kt index 8cdc731122..735c5067f1 100644 --- a/plugins/partiql-memory/src/main/kotlin/org/partiql/plugins/memory/MemoryConnector.kt +++ b/plugins/partiql-memory/src/main/kotlin/org/partiql/plugins/memory/MemoryConnector.kt @@ -55,25 +55,25 @@ public class MemoryConnector private constructor( @JvmStatic public fun builder(): Builder = Builder() + } - public class Builder internal constructor() { + public class Builder internal constructor() { - private var name: String? = null - private var tables: MutableMap = mutableMapOf() + private var name: String? = null + private var tables: MutableMap = mutableMapOf() - public fun name(name: String): Builder = apply { this.name = name } + public fun name(name: String): Builder = apply { this.name = name } - // TODO REMOVE AFTER CREATE TABLE IS ADDED TO CATALOG - public fun define(name: String, type: StaticType): Builder { - val table = MemoryTable.empty(name, PType.fromStaticType(type)) - return define(table) - } + // TODO REMOVE AFTER CREATE TABLE IS ADDED TO CATALOG + public fun define(name: String, type: StaticType): Builder { + val table = MemoryTable.empty(name, PType.fromStaticType(type)) + return define(table) + } - // TODO REMOVE AFTER CREATE TABLE IS ADDED TO CATALOG - public fun define(table: MemoryTable): Builder = apply { tables[table.getName()] = table } + // TODO REMOVE AFTER CREATE TABLE IS ADDED TO CATALOG + public fun define(table: MemoryTable): Builder = apply { tables[table.getName()] = table } - public fun build(): MemoryConnector = MemoryConnector(name!!, tables) - } + public fun build(): MemoryConnector = MemoryConnector(name!!, tables) } /** diff --git a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt index 1209969176..30915bdbe6 100644 --- a/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt +++ b/test/partiql-tests-runner/src/test/kotlin/org/partiql/runner/executor/EvalExecutor.kt @@ -10,22 +10,19 @@ import com.amazon.ionelement.api.toIonValue import org.partiql.eval.PartiQLEngine import org.partiql.eval.PartiQLResult import org.partiql.eval.PartiQLStatement +import org.partiql.eval.value.Datum import org.partiql.lang.eval.CompileOptions import org.partiql.lang.eval.TypingMode import org.partiql.parser.PartiQLParser import org.partiql.plan.Statement import org.partiql.planner.PartiQLPlanner -import org.partiql.plugins.memory.MemoryCatalog +import org.partiql.planner.catalog.Name import org.partiql.plugins.memory.MemoryConnector -import org.partiql.plugins.memory.MemoryObject +import org.partiql.plugins.memory.MemoryTable import org.partiql.runner.ION import org.partiql.runner.test.TestExecutor -import org.partiql.spi.BindingCase -import org.partiql.spi.BindingName import org.partiql.spi.connector.Connector -import org.partiql.spi.connector.ConnectorSession import org.partiql.types.PType -import org.partiql.types.StaticType import org.partiql.value.PartiQLValue import org.partiql.value.PartiQLValueExperimental import org.partiql.value.io.PartiQLValueIonReaderBuilder @@ -35,7 +32,7 @@ import org.partiql.planner.catalog.Session as PlannerSession @OptIn(PartiQLValueExperimental::class) class EvalExecutor( private val plannerSession: PlannerSession, - private val evalSession: PartiQLEngine.Session + private val evalSession: PartiQLEngine.Session, ) : TestExecutor, PartiQLResult> { override fun prepare(statement: String): PartiQLStatement<*> { @@ -111,6 +108,7 @@ class EvalExecutor( } return false } + companion object { val parser = PartiQLParser.default() val planner = PartiQLPlanner.standard() @@ -128,12 +126,7 @@ class EvalExecutor( val session = PlannerSession.builder() .catalog(catalog) - .catalogs( - "default" to connector.getMetadata(object : ConnectorSession { - override fun getQueryId(): String = "query" - override fun getUserId(): String = "user" - }) - ) + .catalogs(connector.getCatalog()) .build() val mode = when (options.typingMode) { @@ -161,22 +154,20 @@ class EvalExecutor( env.fields.forEach { map[it.name] = inferEnv(it.value) } - val catalog = MemoryCatalog.builder().name("default").build() - catalog.load(env) - return MemoryConnector(catalog) + return MemoryConnector.builder() + .name("default") + .apply { load(env) } + .build() } + /** + * Uses the planner to infer the type of the environment. + */ private fun inferEnv(env: AnyElement): PType { - val catalog = MemoryCatalog.builder().name("conformance_test").build() - val connector = MemoryConnector(catalog) + val catalog = MemoryConnector.builder().name("default").build().getCatalog() val session = PlannerSession.builder() .catalog("default") - .catalogs( - "default" to connector.getMetadata(object : ConnectorSession { - override fun getQueryId(): String = "query" - override fun getUserId(): String = "user" - }) - ) + .catalogs(catalog) .build() val stmt = parser.parse("`$env`").root val plan = planner.plan(stmt, session) @@ -188,17 +179,17 @@ class EvalExecutor( * * TODO until this point, PartiQL Kotlin has only done top-level bindings. */ - private fun MemoryCatalog.load(env: StructElement) { + private fun MemoryConnector.Builder.load(env: StructElement) { for (f in env.fields) { - val k = f.name - val v = f.value - // convert to binding - val path = BindingPath(steps = listOf(BindingName(k, BindingCase.SENSITIVE))) - val item = MemoryObject( - type = StaticType.ANY, - value = PartiQLValueIonReaderBuilder.standard().build(v).read(), + val name = Name.of(f.name) + val value = PartiQLValueIonReaderBuilder.standard().build(f.value).read() + val table = MemoryTable.of( + name = name, + schema = PType.typeDynamic(), + datum = Datum.nullValue(), + // datum = Datum.of(value) ) - this.insert(path, item) + define(table) } } }