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

Question: can we support short-circuit logic ? #898

Closed
chengjingtao opened this issue May 22, 2023 · 4 comments · Fixed by #899
Closed

Question: can we support short-circuit logic ? #898

chengjingtao opened this issue May 22, 2023 · 4 comments · Fixed by #899

Comments

@chengjingtao
Copy link

chengjingtao commented May 22, 2023

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'

duglin added a commit that referenced this issue May 22, 2023
Fixes: #898

Signed-off-by: Doug Davis <dug@microsoft.com>
@duglin
Copy link
Contributor

duglin commented May 22, 2023

See: #899

duglin added a commit to duglin/sdk-go that referenced this issue May 22, 2023
Fixes: cloudevents#898

Signed-off-by: Doug Davis <dug@microsoft.com>
lionelvillard pushed a commit that referenced this issue May 22, 2023
Fixes: #898

Signed-off-by: Doug Davis <dug@microsoft.com>
@chengjingtao
Copy link
Author

Really a great job 👍🏻

And by the way when we plan to publish a new release ?
If so, I could use it as a released version.

@duglin @lionelvillard

@duglin
Copy link
Contributor

duglin commented May 23, 2023

there are a couple of PRs that are really close to being merged - so maybe after those go in we can look at cutting a new release.

@chengjingtao
Copy link
Author

thanks for your reply. I get it .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants