From 0816b987aadd3dad7b77fc2b5e1f2c343ee00f96 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 30 Apr 2024 15:47:27 +0200 Subject: [PATCH] fix: make sure string literals as columns are handled well Signed-off-by: Andres Taylor --- go/vt/sqlparser/ast_funcs.go | 9 +++++++-- go/vt/vtgate/planbuilder/testdata/union_cases.json | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/go/vt/sqlparser/ast_funcs.go b/go/vt/sqlparser/ast_funcs.go index 3943aa84b1f..24fb1c9da15 100644 --- a/go/vt/sqlparser/ast_funcs.go +++ b/go/vt/sqlparser/ast_funcs.go @@ -2194,8 +2194,13 @@ func (ae *AliasedExpr) ColumnName() string { return ae.As.String() } - if col, ok := ae.Expr.(*ColName); ok { - return col.Name.String() + switch node := ae.Expr.(type) { + case *ColName: + return node.Name.String() + case *Literal: + if node.Type == StrVal { + return node.Val + } } return String(ae.Expr) diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index cb9b5113b67..1f77b8e3f20 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -601,8 +601,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select dt.c0 as `'b'`, dt.c1 as `'c'`, weight_string(dt.c0), weight_string(dt.c1) from (select 'b', 'c' from `user` where 1 != 1) as dt(c0, c1) where 1 != 1", - "Query": "select dt.c0 as `'b'`, dt.c1 as `'c'`, weight_string(dt.c0), weight_string(dt.c1) from (select distinct 'b', 'c' from `user`) as dt(c0, c1)", + "FieldQuery": "select dt.c0 as b, dt.c1 as c, weight_string(dt.c0), weight_string(dt.c1) from (select 'b', 'c' from `user` where 1 != 1) as dt(c0, c1) where 1 != 1", + "Query": "select dt.c0 as b, dt.c1 as c, weight_string(dt.c0), weight_string(dt.c1) from (select distinct 'b', 'c' from `user`) as dt(c0, c1)", "Table": "`user`" } ] @@ -639,8 +639,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select dt.c0 as `'b'`, dt.c1 as `'c'`, weight_string(dt.c0), weight_string(dt.c1) from (select 'b', 'c' from `user` where 1 != 1) as dt(c0, c1) where 1 != 1", - "Query": "select dt.c0 as `'b'`, dt.c1 as `'c'`, weight_string(dt.c0), weight_string(dt.c1) from (select distinct 'b', 'c' from `user`) as dt(c0, c1)", + "FieldQuery": "select dt.c0 as b, dt.c1 as c, weight_string(dt.c0), weight_string(dt.c1) from (select 'b', 'c' from `user` where 1 != 1) as dt(c0, c1) where 1 != 1", + "Query": "select dt.c0 as b, dt.c1 as c, weight_string(dt.c0), weight_string(dt.c1) from (select distinct 'b', 'c' from `user`) as dt(c0, c1)", "Table": "`user`" }, {