Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v1-unpivot' into v1-conformanc…
Browse files Browse the repository at this point in the history
…e-tracker
  • Loading branch information
johnedquinn committed Apr 17, 2024
2 parents defcb92 + 00a14e7 commit 2db6589
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
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 @@ -159,27 +159,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

0 comments on commit 2db6589

Please sign in to comment.