Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
partialDDL bool
ignoreNormalizerTest bool
}{{
input: "select a and b member of (c) from dual",
}, {
input: "select * from foo limit 5 + 5",
}, {
input: "create table x(location GEOMETRYCOLLECTION DEFAULT (POINT(7.0, 3.0)))",
Expand Down
4 changes: 1 addition & 3 deletions go/vt/sqlparser/precedence.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func precedenceFor(in Expr) Precendence {
return P13
case *BetweenExpr:
return P12
case *ComparisonExpr:
return P11
case *IsExpr:
case *ComparisonExpr, *IsExpr, *MemberOfExpr:
return P11
case *BinaryExpr:
switch node.Operator {
Expand Down
29 changes: 29 additions & 0 deletions go/vt/sqlparser/precedence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray newline :).

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -161,6 +163,11 @@ func TestParens(t *testing.T) {
{in: "(~ (1||0)) IS NULL", expected: "~(1 or 0) is null"},
{in: "1 not like ('a' is null)", expected: "1 not like ('a' is null)"},
{in: ":vtg1 not like (:vtg2 is null)", expected: ":vtg1 not like (:vtg2 is null)"},
{in: "a and b member of (c)", expected: "a and b member of (c)"},
{
in: "foo is null and (bar = true or cast('1448364' as unsigned) member of (baz))",
expected: "foo is null and (bar = true or cast('1448364' as unsigned) member of (baz))",
},
}

parser := NewTestParser()
Expand Down Expand Up @@ -196,3 +203,25 @@ func TestRandom(t *testing.T) {
require.Equal(t, outputOfParseResult, inputQ)
}
}

func TestPrecedenceOfMemberOfWithAndWithoutParser(t *testing.T) {
// This test was used to expose the difference in precedence between the parser and the ast formatter
expression := "a and b member of (c)"

// hand coded ast with the expected precedence
ast1 := &AndExpr{
Left: NewColName("a"),
Right: &MemberOfExpr{
Value: NewColName("b"),
JSONArr: NewColName("c"),
},
}

assert.Equal(t, expression, String(ast1))

// Now let's try it through the parser
ast2, err := NewTestParser().ParseExpr(expression)
require.NoError(t, err)

assert.Equal(t, expression, String(ast2))
}
Loading
Loading