Proto optional fields

25 views
Skip to first unread message

James Thompson

unread,
Feb 1, 2024, 9:43:25 AMFeb 1
to CEL Go Discussion Forum
Hi everyone,

We are evaluating, no pun intended, CEL as a generic expression framework in a process execution engine here at Morf Health . We use protobufs (syntax=3) to represent all of our data that we would like to be passed into our programs for evaluation. We also make heavy use of the `optional` keyword within our stack (golang), to represent data that isn't specified - which is obviously different to the default case. e.g.

```proto
message Patient {
  string first_name = 1;
  optional last_name = 2;
  //...
}
```

What we want to achieve ideally is the removal of the `types.Optional` type that this `last_name` field is converted to during program evaluation - instead rendering this field as a nullable type, so that we can do things in a program like compare strings `last_name == "morf"`. As you may know, right now this gives a type error presently as it's impossible to compare `Optional(String)` and `String`, I think this is true of all binary operators and functions...

I found some references to a `CustomTypeAdapter` being able to essentially map over the input data to achieve this objective, but I can't make it work. 

Would anybody be able to kindly provide any pointers as to whether this is achievable and if so how? If we can't treat these optional fields as if they were just null values it would make our expression usage intolerably complicated for our users.

Any advice you could give us would be greatly appreciated! Thank you very much for your help in advance!

Tristan Swadell

unread,
Feb 1, 2024, 12:04:44 PMFeb 1
to James Thompson, CEL Go Discussion Forum
Hi James,

Happy to hear that you're exploring CEL. I believe that the type of the field is not actually a `types.Optional`, but rather a `string`. The notion of a proto optional field isn't quite the same as a CEL optional type. That said, the proto semantics for a scalar type (proto3) is that the value is a zero value on access, i.e. "".  The only thing the `optional` does within the proto is allow you to test whether the field was set on the original proto message.

If you have an example of the trouble you're running into, that would be helpful.

Cheers,

-Tristan 



--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/04ebc56e-9170-473c-9a90-2cdc8c844ecbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages