0
votes

The com.google.cloud.datastore package mentioned in most of Google's Java documentation for Datastore provides a Builder class with a setNull method used to set any property value to null, e.g.

FullEntity.Builder<IncompleteKey> builder = FullEntity.newBuilder();
builder.setNull("propertyName");

Google Cloud Dataflow/Apache Beam's DatastoreIO class requires Entities in the package com.google.datastore.v1, and the builder methods do not include a similar setNull method. How do I set a property to null using the V1 Java APIs?

1

1 Answers

3
votes

If using the com.google.datastore.v1 package Entity and Value, this is how to set a null value (with Apache Beam/Google Dataflow):

import com.google.datastore.v1.Entity;
import com.google.datastore.v1.Entity.Builder;
import com.google.datastore.v1.Value;
import com.google.protobuf.NullValue;

Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
Entity.Builder builder = Entity.newBuilder();
builder.putProperties("propertyName", nullValue);

(Answering my own question since it took me quite a while to figure this out!)