Thanks to visit codestin.com
Credit goes to github.com

Skip to content

com.google.cloud.datastore.GqlQuery.Builder does not accept null values and results in an exception #6357

@codeconsole

Description

@codeconsole

Query.newGqlQueryBuilder(type, gql).setBinding('testparam', null)
results in an exception because there is no way to set a null value.

Looking at the source code, I supposed a temporary workaround might be to bind to an empty List as there is a check in the binding code to set that to NullValue.

Currently, I am doing a workaround by putting null in the query String and using setAllowLiteral(true), but this is subOptimal as setAllowLiteral defaults to false.

What needs to be added is a setBinding that accepts NullValue, similar to how
StructuredQuery.PropertyFilter.eq allows

This is a simple addition as the MARSHALLER code for NullValue already exist. The implementation can be

public Builder<V> setNullBinding(String name) {
  namedBindings.put(name, toBinding(NullValue.MARSHALLER, new ArrayList()));
  return this;
}

toBinding checks for an empty list, and will bind NullValue

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions