无法使用 BigQuery 从 Google 数据存储中检索 JSON 实体
Fail to retrieve JSON entity from Google Datastore using BigQuery
我正在尝试将实体从 Google 数据存储导出到 Big Query(然后导出到 CSV)。
当我创建数据集时,一切都很好,除了一个缺失的变量应该是 JSON.(ndb.JsonProperty()
)
查看数据存储中的这个实体变量,它似乎是一个编码的 JSON(例如:...0NzIyMDUyODkiLCAidXNlcl9uYW1lIjogIlZpbmNlbnQgR
...)
我的唯一目的是使用 Big Query Python 或任何需要的方式从数据存储中导出该实体,以便探索数据。
ndb JsonProperty 值作为 blobs:
存储在数据存储中
JsonProperty Value is a Python object (such as a list or a dict or a string) that is serializable using Python's json module; Cloud Datastore stores the JSON serialization as a blob.
BigQuery discards blob data:
Blob BigQuery discards these values when loading the data.
一种可能的解决方法是在您的模型上创建 Computed Properties,以 BigQuery 接受的格式提取您感兴趣的数据。
例如,假设您在 JsonProperty
:
中存储这样的 dict
data = {'foo': 'bar', 'baz': 'quux'}
假设您对键 foo
对应的值感兴趣。您可以创建一个 returns 值的 ComputedProperty
,这将由您的 BigQuery 导出获取(请注意,您必须在添加 ComputedProperty
之后保存所有模型实例以填充新 属性).
class MyModel(ndb.Model):
blob = ndb.JsonProperty()
foo = ndb.ComputedProperty(lambda self: self.blob.get('bar'))
obj = MyModel(blob=data)
obj.put()
obj.foo
'bar'
我正在尝试将实体从 Google 数据存储导出到 Big Query(然后导出到 CSV)。
当我创建数据集时,一切都很好,除了一个缺失的变量应该是 JSON.(ndb.JsonProperty()
)
查看数据存储中的这个实体变量,它似乎是一个编码的 JSON(例如:...0NzIyMDUyODkiLCAidXNlcl9uYW1lIjogIlZpbmNlbnQgR
...)
我的唯一目的是使用 Big Query Python 或任何需要的方式从数据存储中导出该实体,以便探索数据。
ndb JsonProperty 值作为 blobs:
存储在数据存储中JsonProperty Value is a Python object (such as a list or a dict or a string) that is serializable using Python's json module; Cloud Datastore stores the JSON serialization as a blob.
BigQuery discards blob data:
Blob BigQuery discards these values when loading the data.
一种可能的解决方法是在您的模型上创建 Computed Properties,以 BigQuery 接受的格式提取您感兴趣的数据。
例如,假设您在 JsonProperty
:
dict
data = {'foo': 'bar', 'baz': 'quux'}
假设您对键 foo
对应的值感兴趣。您可以创建一个 returns 值的 ComputedProperty
,这将由您的 BigQuery 导出获取(请注意,您必须在添加 ComputedProperty
之后保存所有模型实例以填充新 属性).
class MyModel(ndb.Model):
blob = ndb.JsonProperty()
foo = ndb.ComputedProperty(lambda self: self.blob.get('bar'))
obj = MyModel(blob=data)
obj.put()
obj.foo
'bar'