From 5d582668d2ba0cb7622ba1e9bd3deb4e84be6f9f Mon Sep 17 00:00:00 2001 From: John Ed Quinn Date: Wed, 25 Sep 2024 11:56:53 -0700 Subject: [PATCH] Re-adds DML variants of PartiQLResult --- .../PartiQLCompilerPipelineAsyncExample.kt | 5 +++- .../main/kotlin/org/partiql/cli/query/Cli.kt | 3 ++ .../org/partiql/cli/shell/RunnableWriter.kt | 5 ++++ .../coverage/api/impl/PartiQLTestExtension.kt | 3 ++ .../org/partiql/lang/eval/PartiQLResult.kt | 30 +++++++++++++++++++ .../PartiQLCompilerPipelineFactory.kt | 3 ++ .../PartiQLCompilerPipelineFactoryAsync.kt | 3 ++ 7 files changed, 51 insertions(+), 1 deletion(-) diff --git a/examples/src/main/kotlin/org/partiql/examples/PartiQLCompilerPipelineAsyncExample.kt b/examples/src/main/kotlin/org/partiql/examples/PartiQLCompilerPipelineAsyncExample.kt index 793b507f5..e8247e1a7 100644 --- a/examples/src/main/kotlin/org/partiql/examples/PartiQLCompilerPipelineAsyncExample.kt +++ b/examples/src/main/kotlin/org/partiql/examples/PartiQLCompilerPipelineAsyncExample.kt @@ -77,7 +77,10 @@ class PartiQLCompilerPipelineAsyncExample(out: PrintStream) : Example(out) { } val exprValue = when (result) { is PartiQLResult.Value -> result.value - is PartiQLResult.Explain.Domain -> TODO("DML and Explain not covered in this example") + is PartiQLResult.Delete, + is PartiQLResult.Explain.Domain, + is PartiQLResult.Insert, + is PartiQLResult.Replace -> TODO("DML and Explain not covered in this example") } print("result", exprValue) } diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/query/Cli.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/query/Cli.kt index 2d57ba76a..93bf794c9 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/query/Cli.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/query/Cli.kt @@ -150,6 +150,9 @@ internal class Cli( private fun outputResult(result: PartiQLResult) { when (result) { is PartiQLResult.Value -> outputResult(result.value) + is PartiQLResult.Delete, + is PartiQLResult.Replace, + is PartiQLResult.Insert -> TODO("Delete, Replace, and Insert do not have CLI support yet.") is PartiQLResult.Explain.Domain -> { OutputStreamWriter(output).use { it.append(ExplainFormatter.format(result)) diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/RunnableWriter.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/RunnableWriter.kt index 871829ea9..bd6ab6e2b 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/RunnableWriter.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/RunnableWriter.kt @@ -72,6 +72,11 @@ internal class RunnableWriter( out.println(explain) out.success("OK!") } + is PartiQLResult.Insert, + is PartiQLResult.Replace, + is PartiQLResult.Delete -> { + out.warn("Insert/Replace/Delete are not yet supported") + } } } diff --git a/partiql-coverage/src/main/kotlin/org/partiql/coverage/api/impl/PartiQLTestExtension.kt b/partiql-coverage/src/main/kotlin/org/partiql/coverage/api/impl/PartiQLTestExtension.kt index a94e981b9..d152f42d5 100644 --- a/partiql-coverage/src/main/kotlin/org/partiql/coverage/api/impl/PartiQLTestExtension.kt +++ b/partiql-coverage/src/main/kotlin/org/partiql/coverage/api/impl/PartiQLTestExtension.kt @@ -123,7 +123,10 @@ internal class PartiQLTestExtension : TestTemplateInvocationContextProvider { // NOTE: This is a hack to materialize data, then retrieve CoverageData. val str = when (result) { is PartiQLResult.Value -> ConfigurableExprValueFormatter.standard.format(result.value) + is PartiQLResult.Delete -> TODO("@PartiQLTest does not yet support unit testing of Delete.") is PartiQLResult.Explain.Domain -> TODO("@PartiQLTest does not yet support unit testing of Explain.") + is PartiQLResult.Insert -> TODO("@PartiQLTest does not yet support unit testing of Insert.") + is PartiQLResult.Replace -> TODO("@PartiQLTest does not yet support unit testing of Replace.") } assert(str.length > -1) diff --git a/partiql-lang/src/main/kotlin/org/partiql/lang/eval/PartiQLResult.kt b/partiql-lang/src/main/kotlin/org/partiql/lang/eval/PartiQLResult.kt index f87dde366..2b5b5fc9c 100644 --- a/partiql-lang/src/main/kotlin/org/partiql/lang/eval/PartiQLResult.kt +++ b/partiql-lang/src/main/kotlin/org/partiql/lang/eval/PartiQLResult.kt @@ -42,6 +42,36 @@ sealed class PartiQLResult { override fun getCoverageStructure(): CoverageStructure? = coverageStructure.invoke() } + class Insert( + val target: String, + val rows: Iterable, + private val coverageData: () -> CoverageData? = { null }, + private val coverageStructure: () -> CoverageStructure? = { null } + ) : PartiQLResult() { + override fun getCoverageData(): CoverageData? = coverageData.invoke() + override fun getCoverageStructure(): CoverageStructure? = coverageStructure.invoke() + } + + class Delete( + val target: String, + val rows: Iterable, + private val coverageData: () -> CoverageData? = { null }, + private val coverageStructure: () -> CoverageStructure? = { null } + ) : PartiQLResult() { + override fun getCoverageData(): CoverageData? = coverageData.invoke() + override fun getCoverageStructure(): CoverageStructure? = coverageStructure.invoke() + } + + class Replace( + val target: String, + val rows: Iterable, + private val coverageData: () -> CoverageData? = { null }, + private val coverageStructure: () -> CoverageStructure? = { null } + ) : PartiQLResult() { + override fun getCoverageData(): CoverageData? = coverageData.invoke() + override fun getCoverageStructure(): CoverageStructure? = coverageStructure.invoke() + } + sealed class Explain : PartiQLResult() { data class Domain(val value: DomainNode, val format: String?) : Explain() { override fun getCoverageData(): CoverageData? = null diff --git a/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactory.kt b/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactory.kt index ee025dad4..cc74c58a3 100644 --- a/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactory.kt +++ b/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactory.kt @@ -93,6 +93,9 @@ internal class PartiQLCompilerPipelineFactory() : PipelineFactory { override fun evaluate(query: String): ExprValue { val statement = pipeline.compile(query) return when (val result = statement.eval(session)) { + is PartiQLResult.Delete, + is PartiQLResult.Insert, + is PartiQLResult.Replace -> error("DML is not supported by test suite") is PartiQLResult.Value -> result.value is PartiQLResult.Explain -> error("EXPLAIN is not supported by test suite") } diff --git a/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactoryAsync.kt b/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactoryAsync.kt index 646a7420d..7ab694726 100644 --- a/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactoryAsync.kt +++ b/partiql-lang/src/test/kotlin/org/partiql/lang/eval/evaluatortestframework/PartiQLCompilerPipelineFactoryAsync.kt @@ -95,6 +95,9 @@ internal class PartiQLCompilerPipelineFactoryAsync : PipelineFactory { return runBlocking { val statement = pipeline.compile(query) when (val result = statement.eval(session)) { + is PartiQLResult.Delete, + is PartiQLResult.Insert, + is PartiQLResult.Replace -> error("DML is not supported by test suite") is PartiQLResult.Value -> result.value is PartiQLResult.Explain -> error("EXPLAIN is not supported by test suite") }