Class DatastoreV1.Read
- All Implemented Interfaces:
Serializable
,HasDisplayData
- Enclosing class:
DatastoreV1
PTransform
that reads the result rows of a Cloud Datastore query as Entity
objects.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
An upper bound on the number of splits for a query.Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPCollection
<com.google.datastore.v1.Entity> Override this method to specify how thisPTransform
should be expanded on the givenInputT
.abstract @Nullable ValueProvider
<String> abstract @Nullable ValueProvider
<String> abstract @Nullable ValueProvider
<String> long
getNumEntities
(PipelineOptions options, String ourKind, @Nullable String namespace) Returns Number of entities available for reading.abstract int
abstract @Nullable ValueProvider
<String> abstract @Nullable com.google.datastore.v1.Query
getQuery()
void
populateDisplayData
(DisplayData.Builder builder) Register display data for the given transform or component.abstract String
toString()
withDatabaseId
(String databaseId) Returns a newDatastoreV1.Read
that reads from the Cloud Datastore for the specified database.withLiteralGqlQuery
(String gqlQuery) Returns a newDatastoreV1.Read
that reads the results of the specified GQL query.withLiteralGqlQuery
(ValueProvider<String> gqlQuery) Same aswithLiteralGqlQuery(String)
but with aValueProvider
.withLocalhost
(String localhost) Returns a newDatastoreV1.Read
that reads from a Datastore Emulator running at the given localhost address.withNamespace
(String namespace) Returns a newDatastoreV1.Read
that reads from the given namespace.withNamespace
(ValueProvider<String> namespace) Same aswithNamespace(String)
but with aValueProvider
.withNumQuerySplits
(int numQuerySplits) withProjectId
(String projectId) Returns a newDatastoreV1.Read
that reads from the Cloud Datastore for the specified project.withProjectId
(ValueProvider<String> projectId) Same aswithProjectId(String)
but with aValueProvider
.withQuery
(com.google.datastore.v1.Query query) Returns a newDatastoreV1.Read
that reads the results of the specified query.withReadTime
(Instant readTime) Returns a newDatastoreV1.Read
that reads at the specifiedreadTime
.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, setDisplayData, setResourceHints, validate, validate
-
Field Details
-
NUM_QUERY_SPLITS_MAX
public static final int NUM_QUERY_SPLITS_MAXAn upper bound on the number of splits for a query.- See Also:
-
-
Constructor Details
-
Read
public Read()
-
-
Method Details
-
getProjectId
-
getDatabaseId
-
getQuery
-
getLiteralGqlQuery
-
getNamespace
-
getNumQuerySplits
public abstract int getNumQuerySplits() -
getLocalhost
-
getReadTime
-
toString
- Overrides:
toString
in classPTransform<PBegin,
PCollection<com.google.datastore.v1.Entity>>
-
withDatabaseId
Returns a newDatastoreV1.Read
that reads from the Cloud Datastore for the specified database. -
withProjectId
Returns a newDatastoreV1.Read
that reads from the Cloud Datastore for the specified project. -
withProjectId
Same aswithProjectId(String)
but with aValueProvider
. -
withQuery
Returns a newDatastoreV1.Read
that reads the results of the specified query.Note: Normally,
DatastoreIO
will read from Cloud Datastore in parallel across many workers. However, when theQuery
is configured with a limit usingQuery.Builder.setLimit(com.google.protobuf.Int32Value)
, then all results will be read by a single worker in order to ensure correct results. -
withLiteralGqlQuery
Returns a newDatastoreV1.Read
that reads the results of the specified GQL query. See GQL Reference to know more about GQL grammar.Note: This query is executed with literals allowed, so the users should ensure that the query is originated from trusted sources to avoid any security vulnerabilities via SQL Injection.
Cloud Datastore does not a provide a clean way to translate a gql query string to
Query
, so we end up making a query to the service for translation but this may read the actual data, although it will be a small amount. It needs more validation through production use cases before marking it as stable. -
withLiteralGqlQuery
Same aswithLiteralGqlQuery(String)
but with aValueProvider
. -
withNamespace
Returns a newDatastoreV1.Read
that reads from the given namespace. -
withNamespace
Same aswithNamespace(String)
but with aValueProvider
. -
withNumQuerySplits
Returns a newDatastoreV1.Read
that reads by splitting the givenquery
intonumQuerySplits
.The semantics for the query splitting is defined below:
- Any value less than or equal to 0 will be ignored, and the number of splits will be chosen dynamically at runtime based on the query data size.
- Any value greater than
NUM_QUERY_SPLITS_MAX
will be capped atNUM_QUERY_SPLITS_MAX
. - If the
query
has a user limit set, or contains inequality filters, thennumQuerySplits
will be ignored and no split will be performed. - Under certain cases Cloud Datastore is unable to split query to the requested number of splits. In such cases we just use whatever the Cloud Datastore returns.
-
withLocalhost
Returns a newDatastoreV1.Read
that reads from a Datastore Emulator running at the given localhost address. -
withReadTime
Returns a newDatastoreV1.Read
that reads at the specifiedreadTime
. -
getNumEntities
Returns Number of entities available for reading. -
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
- Specified by:
expand
in classPTransform<PBegin,
PCollection<com.google.datastore.v1.Entity>>
-
populateDisplayData
Description copied from class:PTransform
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.populateDisplayData(builder)
to use the namespace of the subcomponent.By default, does not register any display data. Implementors may override this method to provide their own display data.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Overrides:
populateDisplayData
in classPTransform<PBegin,
PCollection<com.google.datastore.v1.Entity>> - Parameters:
builder
- The builder to populate with display data.- See Also:
-