Google Cloud Dataflow SDK for Java, version 1.9.1
Class DatastoreV1
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.io.datastore.DatastoreV1
-
@Experimental(value=SOURCE_SINK) public class DatastoreV1 extends Object
DatastoreV1
provides an API to Read, Write and DeletePCollections
of Google Cloud Datastore version v1Entity
objects.This API currently requires an authentication workaround. To use
DatastoreV1
, users must use thegcloud
command line tool to get credentials for Cloud Datastore:$ gcloud auth login
To read a
PCollection
from a query to Cloud Datastore, useread()
and its methodsDatastoreV1.Read.withProjectId(java.lang.String)
andDatastoreV1.Read.withQuery(com.google.datastore.v1.Query)
to specify the project to query and the query to read from. You can optionally provide a namespace to query within usingDatastoreV1.Read.withNamespace(java.lang.String)
. You could also optionally specify how many splits you want for the query usingDatastoreV1.Read.withNumQuerySplits(int)
.For example:
// Read a query from Datastore PipelineOptions options = PipelineOptionsFactory.fromArgs(args).create(); Query query = ...; String projectId = "..."; Pipeline p = Pipeline.create(options); PCollection<Entity> entities = p.apply( DatastoreIO.v1().read() .withProjectId(projectId) .withQuery(query));
Note: Normally, a Cloud Dataflow job will read from Cloud Datastore in parallel across many workers. However, when the
Query
is configured with a limit usingQuery.Builder.setLimit(Int32Value)
, then all returned results will be read by a single Dataflow worker in order to ensure correct data.To write a
PCollection
to a Cloud Datastore, usewrite()
, specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().write().withProjectId(projectId)); p.run();
To delete a
PCollection
ofEntities
from Cloud Datastore, usedeleteEntity()
, specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().deleteEntity().withProjectId(projectId)); p.run();
To delete entities associated with a
PCollection
ofKeys
from Cloud Datastore, usedeleteKey()
, specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().deleteKey().withProjectId(projectId)); p.run();
Entities
in thePCollection
to be written or deleted must have completeKeys
. CompleteKeys
specify thename
andid
of theEntity
, where incompleteKeys
do not. Anamespace
other thanprojectId
default may be used by specifying it in theEntity
Keys
.Key.Builder keyBuilder = DatastoreHelper.makeKey(...); keyBuilder.getPartitionIdBuilder().setNamespace(namespace);
Entities
will be committed as upsert (update or insert) or delete mutations. Please read Entities, Properties, and Keys for more information aboutEntity
keys.Permissions
Permission requirements depend on thePipelineRunner
that is used to execute the Dataflow job. Please refer to the documentation of correspondingPipelineRunner
s for more details.Please see Cloud Datastore Sign Up for security and permission related information specific to Cloud Datastore.
- See Also:
PipelineRunner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static class
DatastoreV1.DeleteEntity
APTransform
that deletesEntities
from Cloud Datastore.static class
DatastoreV1.DeleteKey
static class
DatastoreV1.Read
APTransform
that reads the result rows of a Cloud atastore query asEntity
objects.static class
DatastoreV1.Write
APTransform
that writesEntity
objects to Cloud Datastore.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description DatastoreV1.DeleteEntity
deleteEntity()
Returns an emptyDatastoreV1.DeleteEntity
builder.DatastoreV1.DeleteKey
deleteKey()
Returns an emptyDatastoreV1.DeleteKey
builder.DatastoreV1.Read
read()
Returns an emptyDatastoreV1.Read
builder.DatastoreV1.Write
write()
Returns an emptyDatastoreV1.Write
builder.
-
-
-
Method Detail
-
read
public DatastoreV1.Read read()
Returns an emptyDatastoreV1.Read
builder. Configure the sourceprojectId
,query
, and optionallynamespace
andnumQuerySplits
usingDatastoreV1.Read.withProjectId(java.lang.String)
,DatastoreV1.Read.withQuery(com.google.datastore.v1.Query)
,DatastoreV1.Read.withNamespace(java.lang.String)
,DatastoreV1.Read.withNumQuerySplits(int)
.
-
write
public DatastoreV1.Write write()
Returns an emptyDatastoreV1.Write
builder. Configure the destinationprojectId
usingDatastoreV1.Write.withProjectId(java.lang.String)
.
-
deleteEntity
public DatastoreV1.DeleteEntity deleteEntity()
Returns an emptyDatastoreV1.DeleteEntity
builder. Configure the destinationprojectId
usingDatastoreV1.DeleteEntity.withProjectId(java.lang.String)
.
-
deleteKey
public DatastoreV1.DeleteKey deleteKey()
Returns an emptyDatastoreV1.DeleteKey
builder. Configure the destinationprojectId
usingDatastoreV1.DeleteKey.withProjectId(java.lang.String)
.
-
-