Skip to content

Commit

Permalink
Fixes to UNPIVOT normalization and empty struct typing
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Apr 17, 2024
1 parent 04e33a8 commit 41a2f79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ internal object NormalizeFromSource : AstPass {
override fun visitFromValue(node: From.Value, ctx: Int): From {
val expr = visitExpr(node.expr, ctx) as Expr
val asAlias = node.asAlias ?: expr.toBinder(ctx)
return if (expr !== node.expr || asAlias !== node.asAlias) {
node.copy(expr = expr, asAlias = asAlias)
val atAlias = node.atAlias ?: expr.toBinder(ctx + 1)
val byAlias = node.byAlias ?: expr.toBinder(ctx + 2)
return if (expr !== node.expr || asAlias !== node.asAlias || atAlias !== node.atAlias || byAlias !== node.byAlias) {
node.copy(expr = expr, asAlias = asAlias, atAlias = atAlias, byAlias = byAlias)
} else {
node
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,22 @@ internal class PlanTyper(
* TODO handle NULL|STRUCT type
*/
override fun visitRelOpUnpivot(node: Rel.Op.Unpivot, ctx: Rel.Type?): Rel {
// descend, with GLOBAL resolution strategy
val rex = node.rex.type(emptyList(), outer, Scope.GLOBAL)

// key type, always a string.
val kType = STRING

// value type, possibly coerced.
val vType = rex.type.allTypes.map { type ->
val vTypes = rex.type.allTypes.map { type ->
when (type) {
is StructType -> {
if (type.contentClosed || type.constraints.contains(TupleConstraint.Open(false))) {
if ((type.contentClosed || type.constraints.contains(TupleConstraint.Open(false))) && type.fields.isNotEmpty()) {
unionOf(type.fields.map { it.value }.toSet()).flatten()
} else {
ANY
}
}
else -> type
}
}.let {
unionOf(it.toSet()).flatten()
}
val vType = unionOf(vTypes.toSet()).flatten()

// rewrite
val type = ctx!!.copyWithSchema(listOf(kType, vType))
Expand Down
4 changes: 2 additions & 2 deletions test/partiql-tests-runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ val generateTestReport by tasks.registering(Test::class) {
environment(Env.PARTIQL_EQUIV, file("$tests/eval-equiv/").absolutePath)
environment("conformanceReportDir", reportDir)
include("org/partiql/runner/ConformanceTestEval.class", "org/partiql/runner/ConformanceTestLegacy.class")
if (project.hasProperty("Engine")) {
val engine = property("Engine")!! as String
if (project.hasProperty("engine")) {
val engine = project.property("engine")!! as String
if (engine.toLowerCase() == "legacy") {
exclude("org/partiql/runner/ConformanceTestEval.class")
} else if (engine.toLowerCase() == "eval") {
Expand Down

0 comments on commit 41a2f79

Please sign in to comment.