Created
November 1, 2018 19:44
-
-
Save dound/832bfb5fe7cc520fe16315e8a1e68631 to your computer and use it in GitHub Desktop.
demo of how to make a query_pb2 that only fetches keys (use a projection)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apache_beam.io.gcp.datastore.v1 import helper | |
ds = helper.get_datastore('pgdragonsong-dev') | |
from google.cloud.proto.datastore.v1 import datastore_pb2, entity_pb2, query_pb2 | |
req = datastore_pb2.RunQueryRequest() | |
partition = entity_pb2.PartitionId() | |
partition.project_id = 'pgdragonsong-dev' | |
req.partition_id.CopyFrom(partition) | |
q = query_pb2.Query() | |
q.kind.add().name = 'TmpForDeletion' | |
# how to change entity_result_type from full to keys-only? | |
from googledatastore import helper as datastore_helper | |
datastore_helper.add_projection(q, '__key__') | |
req.query.CopyFrom(q) | |
ds.run_query(req) # returns datastore_pb2.RunQueryResponse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment