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

Can't compile expression that return objects with mixed properties types #98

Open
sgendre opened this issue Oct 17, 2024 · 1 comment
Open
Labels
question Further information is requested

Comments

@sgendre
Copy link

sgendre commented Oct 17, 2024

Question

Hi,
I am playing with playground to scope what is achievable or not with CEL
and to spot what is valid CEL syntax or not.

Further Information

I try to implement an expression that return an object base on name
This example is for simplicity purpose only.
input: person: name: 'sam'

expression KO person.name == 'sam' ? { 'status': 'adult', 'age': 39} : { 'status': 'unknown', 'age': 0} is failing to compile

but as soon as I change "age" and "adult" properties to string
expression OKperson.name == 'sam' ? { "status": "adult", "age": "39"} : { "status": "adult", "age": "0"} it compiles and is evaluated

and even inconsistent object shape return is fine as long as all properties does have the same type
expression OK2 person.name == 'sam' ? { 'status': 'adult', 'age': '39'} : { 'status': 'unknown'}

Why is there such constraint?

You can play directly with
https://playcel.undistro.io/?content=H4sIAAAAAAAAA51TTUvDQBD9K2M8RKG2gicDRUQKflQrioiQy9hM08Xd2bAfrUX6351Ng6WHipgc8rIz897bmd2vbEo6K7LBAF5JT60hCBbCnOBqNIZHjava2cjVQcmSsrsGygMyKA7kcBrUgoTj%2FdJ7Mu96BY1dkqMKiBfKWTbEIXHTZ6OtI6msEian2shShflG1xpjGUafjSPvlcAxch2xJjgS%2FeN%2BctK6OYFXpwLBykbXWqNtzVyku6QXTy0xOkKQUMJeVQQz68R8EwNUGLAnGN4u78cgy7fPk4cUNxg6lsfEDPlT5LzdxQJ1xD3iWKNiH1qlrUBHNOr2n%2BqmVmuSzkmNnQkDmkaT74z5RjlMsbJ9pVjG0yjdrsHdpGRpnrfcZ5SpDYeQezQ5XMCXoIAh%2BryAHKuoQ94TUJP8n52vodjNiPzBdsnbnFNYd4KTu%2FT5u8xe7v8S%2FnjKz85%2FYc96WerwTeq1HOZDuJbxp%2BO5O4E9E%2B4ncxtPRckgT3JWbHyVLOTGViS86aqsvwHRXEQqMgMAAA%3D%3D

Screenshots

image

System Information

  • OS: MacOS
  • OS Version: Latest

Additional Context

I dont know if the issue is specific to cel-playground or to the underlying used implementation

Thank for your time or for that online tool, it is so helpful to ramp-up 👍

@sgendre sgendre added the question Further information is requested label Oct 17, 2024
@sgendre sgendre changed the title Can't compile expression return structure with number but structure with string is ok Can't compile expression that return objects with mixed properties types Oct 18, 2024
@matheusfm
Copy link
Contributor

matheusfm commented Oct 21, 2024

Hi @sgendre, thank you for opening this issue!

This expression is failing because CEL Playground disables mixed types for lists and maps.
It's being explicitly disabled by setting cel.HomogeneousAggregateLiterals() and cel.ValidateHomogeneousAggregateLiterals() options.

These options are set to follow the same configuration as Kubernetes.

Note, it's still possible to have mixed types when provided as input variable (right text area).

You can also define your CEL environment without these options.
Here’s a version without them: https://heterogeneous-aggregates.cel-playground.pages.dev/
Available starting from this PR: #99.

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

No branches or pull requests

2 participants