Skip to content

Commit

Permalink
airframe-sql: Fix column aliasing in CTEResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe committed Feb 9, 2023
1 parent d576c60 commit a7ebe6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object CTEResolver extends LogSupport {
}
// Add a projection for renaming columns
val selectItems = resolvedQuery.outputAttributes.zip(aliases).map { case (col, alias) =>
SingleColumn(col, None, col.nodeLocation).withAlias(alias.value)
col.withAlias(alias.value)
}
Project(resolvedQuery, selectItems, resolvedQuery.nodeLocation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,11 @@ class SQLGeneratorTest extends AirSpec {
val sql = SQLGenerator.print(resolvedPlan).toLowerCase
sql shouldBe "select * from a as t1"
}

test("CTE with column names") {
val resolvedPlan =
SQLAnalyzer.analyze("with t1 (xid) as (select id as pid from A) select xid from t1", "default", demoCatalog)
val sql = SQLGenerator.print(resolvedPlan).toLowerCase
sql shouldBe "with t1 as (select id as xid from (select id as pid from a)) select xid from t1"
}
}

0 comments on commit a7ebe6a

Please sign in to comment.