Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Exists(func) #235

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion expr/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ func (t *tree) v(depth int) Node {
case lex.TokenIdentity:
n := NewIdentityNode(&cur)
t.Next() // Consume identity

return n
case lex.TokenNull:
t.Next()
Expand Down
5 changes: 3 additions & 2 deletions lex/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (l *Lexer) ErrMsg(t Token, msg string) error {
// NextToken returns the next token from the input.
func (l *Lexer) NextToken() Token {
for {
//u.Debugf("token: start=%v pos=%v peek5=%s", l.start, l.pos, l.PeekX(5))
//debugf("token: start=%v pos=%v peek5=%s", l.start, l.pos, l.PeekX(5))
select {
case token := <-l.tokens:
return token
Expand Down Expand Up @@ -2537,9 +2537,10 @@ func LexExpression(l *Lexer) StateFn {
l.Emit(TokenUdfExpr)
l.ConsumeWord("(")
l.Emit(TokenLeftParenthesis)
l.SkipWhiteSpaces()
l.Push("LexExpression", l.clauseState())
l.Push("LexParenRight", LexParenRight)
return LexExpression
return LexListOfArgs
}
l.Emit(TokenExists)
return LexExpression
Expand Down
13 changes: 13 additions & 0 deletions rel/parse_filterql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ func parseFilterSelectsTest(t *testing.T, st selsTest) {
}
}

func TestFilterQLBug234(t *testing.T) {
t.Parallel()
_, err := rel.ParseFilterQL(`
FILTER AND (
EXISTS(abc),
EXISTS(abcd), -- hello a comment
EXISTS(abcde)
modified < "now-30d"
) FROM user
`)
assert.Equal(t, nil, err)
}

type foo struct{}

func (*foo) Type() value.ValueType { return value.BoolType }
Expand Down
25 changes: 13 additions & 12 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,23 @@ func TestMain(m *testing.M) {

var (
t0 = dateparse.MustParse("12/18/2015")
t1 = dateparse.MustParse("12/18/2039")
tfuture = dateparse.MustParse("12/18/2039")
tcreated = dateparse.MustParse("12/18/2019")
// This is the message context which will be added to all tests below
// and be available to the VM runtime for evaluation by using
// key's such as "int5" or "user_id"
msgContext = datasource.NewContextMap(map[string]interface{}{
"int5": value.NewIntValue(5),
"str5": value.NewStringValue("5"),
"created": value.NewTimeValue(tcreated),
"bvalt": value.NewBoolValue(true),
"bvalf": value.NewBoolValue(false),
"user_id": value.NewStringValue("abc"),
"urls": value.NewStringsValue([]string{"abc", "123"}),
"hits": value.NewMapIntValue(map[string]int64{"google.com": 5, "bing.com": 1}),
"email": value.NewStringValue("bob@bob.com"),
"mt": value.NewMapTimeValue(map[string]time.Time{"event0": t0, "event1": t1}),
"int5": value.NewIntValue(5),
"str5": value.NewStringValue("5"),
"created": value.NewTimeValue(tcreated),
"createdfuture": value.NewTimeValue(tfuture),
"bvalt": value.NewBoolValue(true),
"bvalf": value.NewBoolValue(false),
"user_id": value.NewStringValue("abc"),
"urls": value.NewStringsValue([]string{"abc", "123"}),
"hits": value.NewMapIntValue(map[string]int64{"google.com": 5, "bing.com": 1}),
"email": value.NewStringValue("bob@bob.com"),
"mt": value.NewMapTimeValue(map[string]time.Time{"event0": t0, "event1": tfuture}),
}, true)
vmTestsx = []vmTest{
vmt(`mt.event1 > now()`, true, noError),
Expand All @@ -69,7 +70,7 @@ var (
vmTests = []vmTest{

// Date math
vmt(`created > "now-1M"`, true, noError),
vmt(`createdfuture > "now-1M"`, true, noError),
vmt(`now() > todate("01/01/2014")`, true, noError),
vmt(`todate("now+3d") > now()`, true, noError),
vmt(`created < 2032220220175`, true, noError), // Really not sure i want to support this?
Expand Down