mwebler
7/20/2018 - 4:49 AM

Apache Beam Python: Google Datastore Query with Property Filter

Apache Beam Python: Google Datastore Query with Property Filter

import apache_beam as beam

from apache_beam.io.gcp.datastore.v1.datastoreio import ReadFromDatastore
from google.cloud.proto.datastore.v1 import query_pb2

from googledatastore import helper as datastore_helper
from googledatastore import PropertyFilter


p = beam.Pipeline(options=pipeline_options)

# Create a query and filter by kind
query = query_pb2.Query()
query.kind.add().name = 'EntityKind'

# Read just the entry with a specific __key__ property
datastore_helper.set_property_filter(query.filter, '__key__', PropertyFilter.EQUALS, key)

result = p | ReadFromDatastore(project=PROJECT_ID, query=query)