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 72d79a1206e..e550145f8d5 100644 --- a/go/test/endtoend/vtgate/vitess_tester/join/join.test +++ b/go/test/endtoend/vtgate/vitess_tester/join/join.test @@ -76,4 +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; - 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()