Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yliuuuu committed May 15, 2024
1 parent 0f14c1d commit 21fa3de
Show file tree
Hide file tree
Showing 7 changed files with 584 additions and 449 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ internal object DDLFeatureGate {
override fun visitTypeCollection(node: Type.Collection, ctx: Unit) {
when (val type = node.type) {
is Type.Collection -> {
val elementType = type.type ?: return
val elementType = type.type ?: return super.visitTypeCollection(node, ctx)
if (elementType is Type.Collection) {
if (elementType.constraints.isNotEmpty()) {
throw IllegalArgumentException(
"Unsupported Feature - nested Collection Constraint"
)
}
TODO("Unsupported Feature - nested Collection Constraint")
} else super.visitTypeCollection(node, ctx)
}
}
else -> super.visitTypeCollection(node, ctx)
Expand All @@ -41,19 +39,15 @@ internal object DDLFeatureGate {
val fieldType = node.type
if (fieldType is Type.Record) {
if (fieldType.constraints.isNotEmpty()) {
throw IllegalArgumentException(
"Unsupported Feature - Check constraint on Struct Field"
)
}
}
TODO("Unsupported Feature - Check constraint on Struct Field")
} else super.visitTypeRecordField(node, ctx)
} else super.visitTypeRecordField(node, ctx)
}

override fun visitConstraint(node: Constraint, ctx: Unit) {
val name = node.name ?: return
if (!name.startsWith("$"))
throw IllegalArgumentException(
"Unsupported Feature - Named constraint"
)
TODO("Unsupported Feature - Named constraint")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,20 @@ internal object ConstraintResolver {
}

override fun visitTypeRecord(node: Type.Record, ctx: Ctx): StaticType {
// TODO: For struct level constraint are only check
// TODO: For now struct level constraint are only check
// and struct by default is closed and unique
// For now we dump check constraint in struct meta
val constraintMeta = node.constraints.mapNotNull { constr ->
if (constr.definition is Constraint.Definition.Check) {
field(constr.name!!, ionString(constr.definition.sql))
} else null
}.let { if (it.isNotEmpty()) { mapOf("check_constraints" to ionStructOf(it)) } else emptyMap() }
val seen = mutableSetOf<String>()
val resolvedField = node.fields.map {
StructType.Field(
it.name.normalize(),
visitTypeRecordField(it, ctx)
)
).also { field -> if (!seen.add(field.key)) TODO("Throw duplicated binding") }
}

return StructType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ internal class PlanTyper(private val env: Env) {
* Types a DDL statement.
*/

private inner class DdlTyper() : PlanRewriter<List<Type.Record.Field>>() {
internal inner class DdlTyper : PlanRewriter<List<Type.Record.Field>>() {
override fun visitStatementDDL(node: Statement.DDL, ctx: List<Type.Record.Field>): Statement.DDL {
when (node.op) {
is DdlOp.CreateTable -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.partiql.planner.internal.ddl

import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.planner.internal.ir.PartiQLPlan
import org.partiql.planner.internal.ir.statementDDL
import org.partiql.planner.internal.transforms.PlanTransform
import org.partiql.types.StaticType
import kotlin.test.assertEquals

internal class DDLPlanTests {
val transform = PlanTransform(setOf())
val typer = DDLTestBase.typer
fun run(tc: DDLTestBase.TestCase) {
if (tc.publicPlan != null) {
val typed = typer.resolve(statementDDL(StaticType.ANY, tc.untyped))
val internal = PartiQLPlan(typed)
assertEquals(tc.publicPlan, transform.transform(internal, {}).statement)
} else {
assertThrows<NotImplementedError> {
val typed = typer.resolve(statementDDL(StaticType.ANY, tc.untyped))
val internal = PartiQLPlan(typed)
transform.transform(internal, {})
}
}
}

companion object {
@JvmStatic
fun testCases() = DDLTestBase.testCases()
}

@ParameterizedTest
@MethodSource("testCases")
fun test(tc: DDLTestBase.TestCase) = run(tc)
}
Loading

0 comments on commit 21fa3de

Please sign in to comment.