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

#1047 Expose AddFunction API for CESQL Parser #1051

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dgeorgievski
Copy link
Contributor

As discussed in #1047 added support for addition of user defined functions.

  • AddFunction API
  • TCK tests for user defined functions.
  • Instructions on using user defined functions in README file.

@Cali0707, waiting on your feedback. The PR has a working version of the implementation, but it might need to be refined especially when it comes to testing,

I've noticed that the test/tck_test.go manages all the testing of SQL expressions and functions. I've also added runtime/functions_resolver_test.go to be able to test the new runtime.AddFunction function. Is that ok?

@dgeorgievski dgeorgievski requested a review from a team as a code owner May 3, 2024 16:52
Copy link
Contributor

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

Hey @dgeorgievski at a first look, these changes seem good! My only thought is to maybe not use the tck tests for this, as those tests are meant to test the CESQL spec and are mirrored from the cloudevents spec repo. Since the spec only says An engine SHOULD also allow users to define their custom functions, I think it is better in our case to just have the test cases you added be in their own test file somewhere else.

I'll take a closer look at the implementation next Monday!

@dgeorgievski
Copy link
Contributor Author

dgeorgievski commented May 3, 2024

I think it is better in our case to just have the test cases you added be in their own test file somewhere else.

I agree. Let's decide first on the new location of the tests. My first impulse was to place them under runtime/ considering I am testing runtime.AddFunction in the same dir as well.

@Cali0707
Copy link
Contributor

Cali0707 commented May 3, 2024

Yeah putting them into runtime sounds reasonable to me!

- Initial implementation of a user defined function.
- TCK tests for user defined functions.
- Instructions on using user defined functions in README file.

Signed-off-by: Dimitar Georgievski <dgeorgievski@gmail.com>
…v2/runtime

Signed-off-by: Dimitar Georgievski <dgeorgievski@gmail.com>
@dgeorgievski dgeorgievski force-pushed the 1047-expose-addfunction-api-cesql branch from dd245e6 to 31e1907 Compare May 9, 2024 18:17
@dgeorgievski
Copy link
Contributor Author

dgeorgievski commented May 9, 2024

  • Moved user defined functions tests from sql/v2/test to sql/v2/runtime
  • Created runtime_test package to avoid circular import runtime package errors.
  • Using the same TCK mechanism for running user defined functions test to simplify the users validation of new functions. For example, if I'd like to test a new function I plan to use in my app, I'd be able to quickly validate it by adding both the function definition and all the required tests cases in these two files without the overhead of creating the required events for testing.
    1. runtime/user_defined_functions_test.go.
    2. runtime/tck/user_defined_functions.yaml`.

Running user defined functions tests

$ go test -v ./runtime
...
--- PASS: Test_functionTable_AddFunction (0.00s)
    --- PASS: Test_functionTable_AddFunction/Add_user_functions_to_global_table (0.00s)
    --- PASS: Test_functionTable_AddFunction/Fail_add_user_functions_to_global_table (0.00s)
...
--- PASS: Test_UserFunctions (0.01s)
    --- PASS: Test_UserFunctions/User_defined_functions (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/KONKAT_(2) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/KONKAT_(3) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/HASPREFIX_(1) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/HASPREFIX_(3) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/HASPREFIX_(5) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/HASPREFIX_(4) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/HASPREFIX_(2) (0.00s)
        --- PASS: Test_UserFunctions/User_defined_functions/KONKAT_(1) (0.00s)
PASS
ok      github.com/cloudevents/sdk-go/sql/v2/runtime    0.022s

Copy link
Contributor

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

Just one small question about where files go, otherwise LGTM from me!

SPDX-License-Identifier: Apache-2.0
*/

package runtime_test
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is in a separate package for import purposes, do you think it would make sense to move it into a new (nested) directory like /runtime/test (which would also then have all the tck files in the same directory)>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I believe creating a dedicated test directory would provide more flexibility for future customizations. Will be right back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests assets moved to runtime/test dir.

Signed-off-by: Dimitar Georgievski <dgeorgievski@gmail.com>
Copy link
Contributor

@Cali0707 Cali0707 left a comment

Choose a reason for hiding this comment

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

LGTM from me

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

2 participants