From 8059bd23790a8489b8328d1bf4cfbe4a5ed77e6d Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 13 Dec 2023 12:57:18 +0530 Subject: [PATCH] feat: fix order by and group by normalization Signed-off-by: Manan Gupta --- go/vt/sqlparser/normalizer.go | 2 +- go/vt/sqlparser/normalizer_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/go/vt/sqlparser/normalizer.go b/go/vt/sqlparser/normalizer.go index 3cc5fc4cb60..b1728a47fb1 100644 --- a/go/vt/sqlparser/normalizer.go +++ b/go/vt/sqlparser/normalizer.go @@ -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: diff --git a/go/vt/sqlparser/normalizer_test.go b/go/vt/sqlparser/normalizer_test.go index f6545b44388..f0771d437fa 100644 --- a/go/vt/sqlparser/normalizer_test.go +++ b/go/vt/sqlparser/normalizer_test.go @@ -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) {