使用 Google Cloud Dataflow 的 Java API for Datastore 将 属性 设置为 null?
Set a property to null with Google Cloud Dataflow's Java API for Datastore?
大多数 Google 的 Java Datastore 文档中提到的 com.google.cloud.datastore
包提供了一个 Builder class 和一个 setNull
方法用于设置null
的任何 属性 值,例如
FullEntity.Builder<IncompleteKey> builder = FullEntity.newBuilder();
builder.setNull("propertyName");
Google Cloud Dataflow/Apache Beam 的 DatastoreIO class 需要包 com.google.datastore.v1
中的实体,构建器方法不包含类似的 setNull
方法。如何使用 V1 Java API 将 属性 设置为 null
?
如果使用 com.google.datastore.v1
包实体和值,这是设置空值的方法(使用 Apache Beam/Google 数据流):
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);
(回答我自己的问题,因为我花了很长时间才弄明白!)
大多数 Google 的 Java Datastore 文档中提到的 com.google.cloud.datastore
包提供了一个 Builder class 和一个 setNull
方法用于设置null
的任何 属性 值,例如
FullEntity.Builder<IncompleteKey> builder = FullEntity.newBuilder();
builder.setNull("propertyName");
Google Cloud Dataflow/Apache Beam 的 DatastoreIO class 需要包 com.google.datastore.v1
中的实体,构建器方法不包含类似的 setNull
方法。如何使用 V1 Java API 将 属性 设置为 null
?
如果使用 com.google.datastore.v1
包实体和值,这是设置空值的方法(使用 Apache Beam/Google 数据流):
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);
(回答我自己的问题,因为我花了很长时间才弄明白!)