View queries on optional values


I’m currently trying out a few things with Akka Serverless with a simple service for user management. I want to be able to retrieve users by name.

Having used ScalaPB in other projects, I used a wrapper class of google/protobuf/wrappers.proto to generate an entity class where last_name is mandatory, and first_name is an optional field, and this all works fine and as expected

But given a UserView message like this:

message UserView {
  string id                               = 1;
  string last_name                        = 2;
  google.protobuf.StringValue first_name  = 3;

and a view query which returns a message with a repeated UserView field and a boolean value if there are more users as follows

rpc Search(SearchUsers) returns (UserResults) {
  option (akkaserverless.method).view.query = {
    query: "SELECT * AS users, has_more() AS more_users FROM users WHERE first_name = :name OR last_name = :name OFFSET :start_from LIMIT :page_size"

The call fails with a java.lang.RuntimeException: Unsupported key part class root cause.

If I remove the first_name = :name clause, or change the type of the first_name field to string it works fine though. Is there another way I could implement the same functionality, or is there no supported mechanism for something like this yet?

As a side note, I’ve seen a topic on the forums for this feature request, but a LIKE comparison operator would be greatly appreciated :slight_smile: (As would a lower case function for case insensitive searches, but I can work around that for now with an action controller and transforming the view properties to lower case)

Thanks for reporting. I’ll create an issue for supporting optional values (google.protobuf.StringValue and friends). It’s probably not something we will add right away.

Easiest workaround is probably to change to string and let the empty string represent the undefined value.

There is currently no specific support for any of the wrapper types.

I expect that means that to use the google.protobuf.StringValue which has the proto definition

message StringValue {
  // The string value.
  string value = 1;

as a field in a view you’ll have to explicitly reference that nested value in the query. So first_name.value = :name.

We might want to add specific support for those wrapper types in the future though.