Skip to content

Commit

Permalink
Moves property within NormalizeSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Oct 11, 2023
1 parent e2b12e7 commit daafef5
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ internal object NormalizeSelect : AstPass {

private object Visitor : AstRewriter<Int>() {

/**
* This is used to give projections a name. For example:
* ```
* SELECT t.* FROM t AS t
* ```
*
* Will get converted into:
* ```
* SELECT VALUE TUPLEUNION(
* CASE
* WHEN t IS STRUCT THEN t
* ELSE { '_1': t }
* END
* )
* FROM t AS t
* ```
*
* In order to produce the struct's key in `{ '_1': t }` above, we use [col] to produce the column name
* given the ordinal.
*/
private val col = { index: Int -> "_${index + 1}" }

override fun visitExprSFW(node: Expr.SFW, ctx: Int) = ast {
val sfw = super.visitExprSFW(node, ctx) as Expr.SFW
when (val select = sfw.select) {
Expand Down Expand Up @@ -231,8 +253,6 @@ internal object NormalizeSelect : AstPass {
}
}

private val col = { index: Int -> "_${index + 1}" }

// t -> t.* AS _i
private fun String.star(i: Int) = ast {
val expr = exprVar(id(this@star), Expr.Var.Scope.DEFAULT)
Expand Down

0 comments on commit daafef5

Please sign in to comment.