gcp - 从数据存储中获取所有实体
gcp - get all entities from the datastore
我正在尝试从数据存储中获取所有数据实体。当我遇到 google 文档时,我发现了类似于 Query Projection (Link to the Docs) 的内容。这是我用来从数据存储中获取所有实体的代码。
def do_the_query_projection(self, kind_name):
query = self.client.query(kind=kind_name)
query.projection = ['attr_1', 'attr_2', 'attr_3']
#create a list to store
f, m, r = [], [], []
for task in query.fetch():
f.append(task['attr_1'])
m.append(task['attr_2'])
r.append(task['attr_3'])
return f, m, r
这是我现在面临的错误
> google.api_core.exceptions.FailedPrecondition: 400 no matching index
> found. recommended index is:
> - kind: <kind_name> properties:
> - name: attr_1
> - name: attr_2
> - name: attr_3
是否有任何其他方法可以从云数据存储中检索所有数据实体?我们是否需要创建复合索引来检索数据?我是 GCP 的新手。
尝试在没有投影的情况下进行查询。
当您在要检索的列上已有复合索引时,投影查询很有用,因为它允许您从索引中检索这些列,而无需从数据中检索任何内容 table。但是,如果您没有索引,数据存储将不得不以任何一种方式检索完整数据,因此在这种情况下它不允许您指定投影。
检索数据存储中的所有实体
def retrieve_all_entities(self):
query = self.client.query(kind=self.kind_name)
all_keys = query.fetch() #fetches all the entities from the datastore
kinds, r, m, f = [] , [], [], []
for keys in all_keys:
kinds.append(keys.key.id_or_name)
r.append(keys['attr_1'])
m.append(keys['attr_2'])
f.append(keys['attr_3'])
return kinds, r, m, f
我正在尝试从数据存储中获取所有数据实体。当我遇到 google 文档时,我发现了类似于 Query Projection (Link to the Docs) 的内容。这是我用来从数据存储中获取所有实体的代码。
def do_the_query_projection(self, kind_name):
query = self.client.query(kind=kind_name)
query.projection = ['attr_1', 'attr_2', 'attr_3']
#create a list to store
f, m, r = [], [], []
for task in query.fetch():
f.append(task['attr_1'])
m.append(task['attr_2'])
r.append(task['attr_3'])
return f, m, r
这是我现在面临的错误
> google.api_core.exceptions.FailedPrecondition: 400 no matching index
> found. recommended index is:
> - kind: <kind_name> properties:
> - name: attr_1
> - name: attr_2
> - name: attr_3
是否有任何其他方法可以从云数据存储中检索所有数据实体?我们是否需要创建复合索引来检索数据?我是 GCP 的新手。
尝试在没有投影的情况下进行查询。
当您在要检索的列上已有复合索引时,投影查询很有用,因为它允许您从索引中检索这些列,而无需从数据中检索任何内容 table。但是,如果您没有索引,数据存储将不得不以任何一种方式检索完整数据,因此在这种情况下它不允许您指定投影。
检索数据存储中的所有实体
def retrieve_all_entities(self):
query = self.client.query(kind=self.kind_name)
all_keys = query.fetch() #fetches all the entities from the datastore
kinds, r, m, f = [] , [], [], []
for keys in all_keys:
kinds.append(keys.key.id_or_name)
r.append(keys['attr_1'])
m.append(keys['attr_2'])
f.append(keys['attr_3'])
return kinds, r, m, f