From 16e98a588d9720e2176d561c2911253bf5084692 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Mon, 26 Aug 2024 14:54:49 +0530 Subject: [PATCH 1/3] feat: fix tilda precedence Signed-off-by: Manan Gupta --- go/test/endtoend/vtgate/vitess_tester/join/join.test | 2 ++ go/vt/sqlparser/normalizer_test.go | 8 ++++++++ go/vt/sqlparser/precedence.go | 3 +-- go/vt/sqlparser/precedence_test.go | 1 + go/vt/vtgate/planbuilder/testdata/onecase.json | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go/test/endtoend/vtgate/vitess_tester/join/join.test b/go/test/endtoend/vtgate/vitess_tester/join/join.test index 72d79a1206e..1eb8781f657 100644 --- a/go/test/endtoend/vtgate/vitess_tester/join/join.test +++ b/go/test/endtoend/vtgate/vitess_tester/join/join.test @@ -77,3 +77,5 @@ from t1 where t1.id IN (1, 2) group by t2.id, t4.col; +# Dual query that is using tilda operator in a complex expression +SELECT 1 WHERE (~ (1||0)) IS NULL; diff --git a/go/vt/sqlparser/normalizer_test.go b/go/vt/sqlparser/normalizer_test.go index c574b00832d..45e24407ef9 100644 --- a/go/vt/sqlparser/normalizer_test.go +++ b/go/vt/sqlparser/normalizer_test.go @@ -418,6 +418,13 @@ func TestNormalize(t *testing.T) { "bv2": sqltypes.Int64BindVariable(2), "bv3": sqltypes.TestBindVariable([]any{1, 2}), }, + }, { + in: "SELECT 1 WHERE (~ (1||0)) IS NULL", + outstmt: "select :bv1 /* INT64 */ from dual where ~(:bv1 /* INT64 */ or :bv2 /* INT64 */) is null", + outbv: map[string]*querypb.BindVariable{ + "bv1": sqltypes.Int64BindVariable(1), + "bv2": sqltypes.Int64BindVariable(0), + }, }} parser := NewTestParser() for _, tc := range testcases { @@ -508,6 +515,7 @@ func TestNormalizeOneCasae(t *testing.T) { err = Normalize(tree, NewReservedVars("vtg", known), bv) require.NoError(t, err) normalizerOutput := String(tree) + require.EqualValues(t, testOne.output, normalizerOutput) if normalizerOutput == "otheradmin" || normalizerOutput == "otherread" { return } diff --git a/go/vt/sqlparser/precedence.go b/go/vt/sqlparser/precedence.go index ec590b23f95..6df5e8e227e 100644 --- a/go/vt/sqlparser/precedence.go +++ b/go/vt/sqlparser/precedence.go @@ -38,7 +38,6 @@ const ( P14 P15 P16 - P17 ) // precedenceFor returns the precedence of an expression. @@ -83,7 +82,7 @@ func precedenceFor(in Expr) Precendence { switch node.Operator { case UPlusOp, UMinusOp: return P4 - case BangOp: + default: return P3 } } diff --git a/go/vt/sqlparser/precedence_test.go b/go/vt/sqlparser/precedence_test.go index 0d29d8b87e3..0a14df5a2c1 100644 --- a/go/vt/sqlparser/precedence_test.go +++ b/go/vt/sqlparser/precedence_test.go @@ -158,6 +158,7 @@ func TestParens(t *testing.T) { {in: "(10 - 2) - 1", expected: "10 - 2 - 1"}, {in: "10 - (2 - 1)", expected: "10 - (2 - 1)"}, {in: "0 <=> (1 and 0)", expected: "0 <=> (1 and 0)"}, + {in: "(~ (1||0)) IS NULL", expected: "~(1 or 0) is null"}, } parser := NewTestParser() diff --git a/go/vt/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 9d653b2f6e9..714a3e8624a 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,7 +1,7 @@ [ { "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "", + "query": "SELECT 1 WHERE (~ (1||0)) IS NULL", "plan": { } } From 6e02b9f47e90d5c727739a86cddd8c210950344e Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Mon, 26 Aug 2024 20:06:11 +0530 Subject: [PATCH 2/3] test: clear out onecase table Signed-off-by: Manan Gupta --- go/vt/vtgate/planbuilder/testdata/onecase.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 714a3e8624a..9d653b2f6e9 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,7 +1,7 @@ [ { "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "SELECT 1 WHERE (~ (1||0)) IS NULL", + "query": "", "plan": { } } From 67c93e47e7f328caa27c83ddb13a924e5460854b Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 27 Aug 2024 13:01:17 +0200 Subject: [PATCH 3/3] split test file Signed-off-by: Andres Taylor --- go/test/endtoend/vtgate/vitess_tester/dual/queries.test | 4 ++++ go/test/endtoend/vtgate/vitess_tester/join/join.test | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 go/test/endtoend/vtgate/vitess_tester/dual/queries.test diff --git a/go/test/endtoend/vtgate/vitess_tester/dual/queries.test b/go/test/endtoend/vtgate/vitess_tester/dual/queries.test new file mode 100644 index 00000000000..77a6e1595e0 --- /dev/null +++ b/go/test/endtoend/vtgate/vitess_tester/dual/queries.test @@ -0,0 +1,4 @@ +# file with tests that only use the dual table + +# Dual query that is using tilda operator in a complex expression +SELECT 1 WHERE (~ (1||0)) IS NULL; diff --git a/go/test/endtoend/vtgate/vitess_tester/join/join.test b/go/test/endtoend/vtgate/vitess_tester/join/join.test index 1eb8781f657..e550145f8d5 100644 --- a/go/test/endtoend/vtgate/vitess_tester/join/join.test +++ b/go/test/endtoend/vtgate/vitess_tester/join/join.test @@ -76,6 +76,3 @@ from t1 left join (select t4.col, count(*) as count from t4 group by t4.col) t3 on t3.col = t2.id where t1.id IN (1, 2) group by t2.id, t4.col; - -# Dual query that is using tilda operator in a complex expression -SELECT 1 WHERE (~ (1||0)) IS NULL;