Skip to content

Commit

Permalink
Fix order by and group by normalization (#14764)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Dec 13, 2023
1 parent 4a6da63 commit 256268d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/vt/sqlparser/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (nz *normalizer) walkUpSelect(cursor *Cursor) bool {
parent := cursor.Parent()
switch parent.(type) {
case *Order, GroupBy:
return false
return true
case *Limit:
nz.convertLiteral(node, cursor)
default:
Expand Down
9 changes: 9 additions & 0 deletions go/vt/sqlparser/normalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ func TestNormalize(t *testing.T) {
"v1": sqltypes.HexValBindVariable([]byte("x'31'")),
"v2": sqltypes.Int64BindVariable(31),
},
}, {
// ORDER BY and GROUP BY variable
in: "select a, b from t group by 1, field(a,1,2,3) order by 1 asc, field(a,1,2,3)",
outstmt: "select a, b from t group by 1, field(a, :bv1 /* INT64 */, :bv2 /* INT64 */, :bv3 /* INT64 */) order by 1 asc, field(a, :bv1 /* INT64 */, :bv2 /* INT64 */, :bv3 /* INT64 */) asc",
outbv: map[string]*querypb.BindVariable{
"bv1": sqltypes.Int64BindVariable(1),
"bv2": sqltypes.Int64BindVariable(2),
"bv3": sqltypes.Int64BindVariable(3),
},
}}
for _, tc := range testcases {
t.Run(tc.in, func(t *testing.T) {
Expand Down

0 comments on commit 256268d

Please sign in to comment.