Skip to content

Commit

Permalink
Re-adds DML variants of PartiQLResult
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Sep 25, 2024
1 parent d9abbcd commit 5d58266
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions partiql-cli/src/main/kotlin/org/partiql/cli/query/Cli.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ sealed class PartiQLResult {
override fun getCoverageStructure(): CoverageStructure? = coverageStructure.invoke()
}

class Insert(
val target: String,
val rows: Iterable<ExprValue>,
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<ExprValue>,
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<ExprValue>,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 5d58266

Please sign in to comment.