fix ProjectionList{}.As method (issue #364)
This commit is contained in:
parent
f37af464f4
commit
fb66fbd31c
2 changed files with 14 additions and 3 deletions
|
|
@ -45,6 +45,10 @@ func (pl ProjectionList) As(tableAlias string) ProjectionList {
|
|||
newProjectionList = append(newProjectionList, p.As(tableAlias))
|
||||
case ColumnExpression:
|
||||
newProjectionList = append(newProjectionList, newAlias(p, tableAlias+"."+p.Name()))
|
||||
case ColumnList:
|
||||
for _, c := range p {
|
||||
newProjectionList = append(newProjectionList, newAlias(c, tableAlias+"."+c.Name()))
|
||||
}
|
||||
case *alias:
|
||||
newAlias := *p
|
||||
_, columnName := extractTableAndColumnName(newAlias.alias)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ func TestProjectionAs(t *testing.T) {
|
|||
AVG(table1ColInt).AS("avg"),
|
||||
AVG(table1ColInt).AS("t.avg"),
|
||||
},
|
||||
ColumnList{table2Col3, table2Col4},
|
||||
}
|
||||
|
||||
aliasedProjectionList := projectionList.As("new_alias.*")
|
||||
|
|
@ -22,7 +23,9 @@ SUM(table1.col_int) AS "new_alias.sum",
|
|||
SUM(table1.col_int) AS "new_alias.sum",
|
||||
table1.col_bool AS "new_alias.col_bool",
|
||||
AVG(table1.col_int) AS "new_alias.avg",
|
||||
AVG(table1.col_int) AS "new_alias.avg"`)
|
||||
AVG(table1.col_int) AS "new_alias.avg",
|
||||
table2.col3 AS "new_alias.col3",
|
||||
table2.col4 AS "new_alias.col4"`)
|
||||
|
||||
subQueryProjections := projectionList.fromImpl(NewSelectTable(nil, "subQuery"))
|
||||
|
||||
|
|
@ -32,7 +35,9 @@ AVG(table1.col_int) AS "new_alias.avg"`)
|
|||
"subQuery"."table.sum" AS "table.sum",
|
||||
"subQuery"."table1.col_bool" AS "table1.col_bool",
|
||||
"subQuery".avg AS "avg",
|
||||
"subQuery"."t.avg" AS "t.avg"`)
|
||||
"subQuery"."t.avg" AS "t.avg",
|
||||
"subQuery"."table2.col3" AS "table2.col3",
|
||||
"subQuery"."table2.col4" AS "table2.col4"`)
|
||||
|
||||
aliasedSubQueryProjectionList := subQueryProjections.(ProjectionList).As("subAlias")
|
||||
|
||||
|
|
@ -42,5 +47,7 @@ AVG(table1.col_int) AS "new_alias.avg"`)
|
|||
"subQuery"."table.sum" AS "subAlias.sum",
|
||||
"subQuery"."table1.col_bool" AS "subAlias.col_bool",
|
||||
"subQuery".avg AS "subAlias.avg",
|
||||
"subQuery"."t.avg" AS "subAlias.avg"`)
|
||||
"subQuery"."t.avg" AS "subAlias.avg",
|
||||
"subQuery"."table2.col3" AS "subAlias.col3",
|
||||
"subQuery"."table2.col4" AS "subAlias.col4"`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue