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
, eg
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?
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!)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.