Skip to content

Commit b44fda8

Browse files
committed
patched binary walk
1 parent 4b126d4 commit b44fda8

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

expr/binary.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,20 @@ func (b *Binary) walk(fn func(ident node.Node, values *Values, operator, parentO
7070
if err != nil {
7171
return err
7272
}
73+
7374
if binY, ok := b.Y.(*Binary); ok {
7475
if nested, ok := binY.Y.(*Binary); ok {
7576
if err = nested.walk(fn, binY.Op); err != nil {
7677
return err
7778
}
7879
}
80+
if nested, ok := binY.Y.(*Parenthesis); ok {
81+
if nestedBin, ok := nested.X.(*Binary); ok {
82+
if err = nestedBin.walk(fn, binY.Op); err != nil {
83+
return err
84+
}
85+
}
86+
}
7987

8088
}
8189
return nil

expr/values.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ func NewValues(n node.Node) (*Values, error) {
9797
values.append(Value{Placeholder: true})
9898
return &values, nil
9999
case *Binary:
100-
if actual.Y.(*Binary) != nil {
100+
switch actualY := actual.Y.(type) {
101+
case *Binary:
101102
return NewValues(actual.X)
103+
case *Parenthesis:
104+
return NewValues(actualY.X)
102105
}
106+
103107
return NewValues(actual.Y)
104108
case *Literal:
105109
switch actual.Kind {
@@ -153,6 +157,14 @@ func NewValues(n node.Node) (*Values, error) {
153157
values.append(vMax.X...)
154158
return &values, nil
155159
}
160+
case []node.Node:
161+
for _, item := range actual {
162+
if aValue, ok := item.(*Literal); ok {
163+
v, _ := NewValue(aValue.Value)
164+
values.append(*v)
165+
}
166+
}
167+
return &values, nil
156168
}
157169

158170
return nil, fmt.Errorf("unsupported value node: %T", n)

query_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestBinaryWalk(t *testing.T) {
16-
query, _ := ParseQuery("SELECT * FROM t WHERE a = 1 AND b = 2 AND c IN(1,2)")
16+
query, _ := ParseQuery("SELECT * FROM t WHERE a = 1 AND b = 2 AND (c IN(1,2))")
1717
binary, ok := query.Qualify.X.(*expr.Binary)
1818
if !assert.True(t, ok) {
1919
return

0 commit comments

Comments
 (0)