Class DatastoreV1
- java.lang.Object
-
- org.apache.beam.sdk.io.gcp.datastore.DatastoreV1
-
public class DatastoreV1 extends java.lang.ObjectDatastoreV1provides an API to Read, Write and DeletePCollectionsof Google Cloud Datastore version v1Entityobjects. Read is only supported for Bounded PCollections while Write and Delete are supported for both Bounded and Unbounded PCollections.This API currently requires an authentication workaround. To use
DatastoreV1, users must use thegcloudcommand line tool to get credentials for Cloud Datastore:$ gcloud auth login
To read a
PCollectionfrom 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.withDatabaseId(java.lang.String)orDatastoreV1.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 databaseId = "..."; String projectId = "..."; Pipeline p = Pipeline.create(options); PCollection<Entity> entities = p.apply( DatastoreIO.v1().read() .withProjectId(projectId) .withDatabaseId(databaseId) .withQuery(query));Note: A runner may read from Cloud Datastore in parallel across many workers. However, when the
Queryis configured with a limit usingQuery.Builder.setLimit(Int32Value)or if the Query contains inequality filters likeGREATER_THAN, LESS_THANetc., then all returned results will be read by a single worker in order to ensure correct data. Since data is read from a single worker, this could have a significant impact on the performance of the job.To write a
PCollectionto a Cloud Datastore, usewrite(), specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().write().withProjectId(projectId).withDatabaseId(databaseId)); p.run();To delete a
PCollectionofEntitiesfrom Cloud Datastore, usedeleteEntity(), specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().deleteEntity().withProjectId(projectId).withDatabaseId(databaseId)); p.run();To delete entities associated with a
PCollectionofKeysfrom Cloud Datastore, usedeleteKey(), specifying the Cloud Datastore project to write to:PCollection<Entity> entities = ...; entities.apply(DatastoreIO.v1().deleteKey().withProjectId(projectId).withDatabaseId(databaseId)); p.run();Write and delete operations will follow a gradual ramp-up by default in order to protect Cloud Datastore from potential overload. This rate limit follows a heuristic based on the expected number of workers. To optimize throughput in this initial stage, you can provide a hint to the relevant
PTransformby callingwithHintNumWorkers, e.g.,DatastoreIO.v1().deleteKey().withHintNumWorkers(numWorkers). While not recommended, you can also turn this off via.withRampupThrottlingDisabled().Entitiesin thePCollectionto be written or deleted must have completeKeys. CompleteKeysspecify thenameandidof theEntity, where incompleteKeysdo not. Anamespaceother thanprojectIddefault may be used by specifying it in theEntityKeys.Key.Builder keyBuilder = DatastoreHelper.makeKey(...); keyBuilder.getPartitionIdBuilder().setNamespace(namespace);Entitieswill be committed as upsert (update or insert) or delete mutations. Please read Entities, Properties, and Keys for more information aboutEntitykeys.Permissions
Permission requirements depend on thePipelineRunnerthat is used to execute the pipeline. Please refer to the documentation of correspondingPipelineRunners for more details.Please see Cloud Datastore Sign Up for security and permission related information specific to Cloud Datastore.
Optionally, Cloud Datastore V1 Emulator, running locally, could be used for testing purposes by providing the host port information through
withLocalhost("host:port"for all the above transforms. In such a case, all the Cloud Datastore API calls are directed to the Emulator.- See Also:
Updates to the connector code For any updates to this connector, please consider involving corresponding code reviewers mentioned here.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDatastoreV1.DeleteEntityAPTransformthat deletesEntitiesfrom Cloud Datastore.static classDatastoreV1.DeleteEntityWithSummaryAPTransformthat deletesEntitiesfrom Cloud Datastore and returnsDatastoreV1.WriteSuccessSummaryfor each successful write.static classDatastoreV1.DeleteKeyAPTransformthat deletesEntitiesassociated with the givenKeysfrom Cloud Datastore.static classDatastoreV1.DeleteKeyWithSummaryAPTransformthat deletesEntitiesassociated with the givenKeysfrom Cloud Datastore and returnsDatastoreV1.WriteSuccessSummaryfor each successful delete.static classDatastoreV1.ReadAPTransformthat reads the result rows of a Cloud Datastore query asEntityobjects.static classDatastoreV1.WriteAPTransformthat writesEntityobjects to Cloud Datastore.static classDatastoreV1.WriteSuccessSummarySummary object produced when a number of writes are successfully written to Datastore in a single Mutation.static classDatastoreV1.WriteWithSummaryAPTransformthat writesEntityobjects to Cloud Datastore and returnsDatastoreV1.WriteSuccessSummaryfor each successful write.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatastoreV1.DeleteEntitydeleteEntity()Returns an emptyDatastoreV1.DeleteEntitybuilder.DatastoreV1.DeleteKeydeleteKey()Returns an emptyDatastoreV1.DeleteKeybuilder.DatastoreV1.Readread()Returns an emptyDatastoreV1.Readbuilder.DatastoreV1.Writewrite()Returns an emptyDatastoreV1.Writebuilder.
-
-
-
Method Detail
-
read
public DatastoreV1.Read read()
Returns an emptyDatastoreV1.Readbuilder. Configure the sourceprojectId,query, and optionallynamespaceandnumQuerySplitsusingDatastoreV1.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.Writebuilder. Configure the destinationprojectIdusingDatastoreV1.Write.withProjectId(java.lang.String).
-
deleteEntity
public DatastoreV1.DeleteEntity deleteEntity()
Returns an emptyDatastoreV1.DeleteEntitybuilder. Configure the destinationprojectIdusingDatastoreV1.DeleteEntity.withProjectId(java.lang.String).
-
deleteKey
public DatastoreV1.DeleteKey deleteKey()
Returns an emptyDatastoreV1.DeleteKeybuilder. Configure the destinationprojectIdusingDatastoreV1.DeleteKey.withProjectId(java.lang.String).
-
-