Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to UNPIVOT normalization and empty struct typing #1431

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ 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)
var i = ctx
var asAlias = node.asAlias
var atAlias = node.atAlias
// derive AS alias
if (asAlias == null) {
asAlias = expr.toBinder(i++)
}
// derive AT binder
if (atAlias == null && node.type == From.Value.Type.UNPIVOT) {
atAlias = expr.toBinder(i++)
}
return if (expr !== node.expr || asAlias !== node.asAlias || atAlias !== node.atAlias) {
node.copy(expr = expr, asAlias = asAlias, atAlias = atAlias)
} else {
node
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,22 @@ internal class PlanTyper(private val env: Env) {
* 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
Loading