Skip to content

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

@chengjingtao

Description

@chengjingtao

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions