Skip to content

Commit

Permalink
Fix normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Apr 17, 2024
1 parent 41a2f79 commit b54f1b0
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +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)
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)
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

0 comments on commit b54f1b0

Please sign in to comment.