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

CESQL v1 fixes #1066

Merged
merged 13 commits into from
Jul 15, 2024
Merged

CESQL v1 fixes #1066

merged 13 commits into from
Jul 15, 2024

Conversation

Cali0707
Copy link
Contributor

This PR updates the CESQL implementation here to match the changes made in the spec v1 that was approved today. Since there are a lot of changes, I've tried to organize them by commit

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
…correct type

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
…rror types

Signed-off-by: Calum Murray <cmurray@redhat.com>
…or types

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707 Cali0707 requested a review from a team as a code owner June 13, 2024 19:44
@Cali0707
Copy link
Contributor Author

There is one more change I would like to include (either as a follow up or in this PR), but I wasn't sure what the API should be for it:

Currently this SDK only supports the "fail fast" error handling mode, where the CESQL engine returns as soon as it encounters an error. However, I would like to allow users to choose which error handling strategy they would like to use (and then maybe default to fail fast to avoid breaking changes as much as possible). Any ideas on what a good API could be for that?

@Cali0707
Copy link
Contributor Author

cc @duglin @pierDipi @embano1

@duglin
Copy link
Contributor

duglin commented Jun 14, 2024

rebase is needed

@Cali0707
Copy link
Contributor Author

@duglin can you re-check?

lionelvillard
lionelvillard previously approved these changes Jul 2, 2024
Copy link
Contributor

@lionelvillard lionelvillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

sql/v2/errors/errors.go Outdated Show resolved Hide resolved
@lionelvillard
Copy link
Contributor

@duglin for second approval/merge

Signed-off-by: Calum Murray <cmurray@redhat.com>
@matzew
Copy link
Member

matzew commented Jul 4, 2024

LGTM, thanks for the work, @Cali0707

@duglin
Copy link
Contributor

duglin commented Jul 12, 2024

rebase needed


return cesqlError{
kind: parseError,
message: strings.Join(errorMessages, ","),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bold assumption that "," will never be used in an error message.... ever. I would have thought that "\n" would be better (or a less likely character, like "|", if you still wanted a single line) so that people could more easily split this into individual errors later on if needed. Not a show-stopper though.


func IsGenericError(err error) bool {
if cesqlErr, ok := err.(cesqlError); ok {
return cesqlErr.kind < parseError || cesqlErr.kind > functionEvaluationError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels risky to me. If someone adds a new error type will they remember to update this "return" line? I wonder if it would be safer to add a dummy error type to the end of the "const" list and then say >= dummyLastError here instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably also use "0" instead of "parseError" in case someone adds a new item to the front of the const list.

@@ -56,6 +64,10 @@ tests:
- name: abc is not equal to abc (diamond operator)
expression: "'abc' <> 'abc'"
result: false
- name: Diamond operator returns false when encountering a missing attribute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny, never heard it called "Diamond operator" before. I like it! Now I feel like I've been missing out all of these years.

return false
case AnyType:
// by default, return false
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this one, but I'm curious why it defaults to "false" (here and before) instead of "nil" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it just because it needs to be of a well-known type, and "nil" doesn't fit that requirement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout the spec whenever the return type is ambiguous we always have it defaulting to Boolean, which has a zero value of false. So, this way that works without much effort on our part in the SDK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense - thanks

@duglin
Copy link
Contributor

duglin commented Jul 12, 2024

Just a few minor comments, none should stop this from being merged though.
so LGTM once the rebase is one and @Cali0707 says it's ready to go after looking at the comments.

Signed-off-by: Calum Murray <cmurray@redhat.com>
- Parse errors are joined by "|" instead of ","
- Safer checking of generic errors

Signed-off-by: Calum Murray <cmurray@redhat.com>
Copy link
Contributor

@duglin duglin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@duglin duglin merged commit dc3d9b1 into cloudevents:main Jul 15, 2024
9 checks passed
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 this pull request may close these issues.

None yet

4 participants