-
Notifications
You must be signed in to change notification settings - Fork 242
Question: can we support short-circuit logic ? #898
Copy link
Copy link
Closed
Description
Hi, If I have a key in SQL expression but not exists in cloudevent, Evaluate will return missing attribute error.
Can we support short-circuit logic to avoid filling all needed fields empty in cloudevent ?
import (
cesql "github.com/cloudevents/sdk-go/sql/v2/parser"
cloudevents "github.com/cloudevents/sdk-go/v2"
)
func TestShortCircuit(t *testing.T) {
sql := "(EXISTS revisiontype AND revisiontype = Branch) OR (branch = master)"
expression, err := cesql.Parse(string(sql))
evt := cloudevents.NewEvent("1.0")
evt.SetID("evt-1")
evt.SetType("what-ever")
evt.SetSource("/event")
evt.SetExtension("branch", "master")
val, err := expression.Evaluate(evt)
if err != nil {
t.Errorf("err should be nil: %s", err.Error())
} else {
if !val.(bool) {
t.Errorf("should be true ,but :%s", val)
}
}
}
=== RUN TestShortCircuit
filters_test.go:49: err should be nil: missing attribute 'revisiontype'
--- FAIL: TestShortCircuit (0.00s)Expected: expression.Evaluate(evt) should return true, because "branch = master" matched
Actual: errors happened: missing attribute 'revisiontype'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels