我运行一个简单的查询,返回如下输出:
[{
"polarity": "0.0",
"magnitude": "2.0",
"score": "0.5",
"entities": [{
"name": "Taubenkot",
"type": "OTHER",
"mid": "",
"wikipediaUrl": "",
"numMentions": "1",
"avgSalience": "0.150263"
}, {
"name": "Lösung",
"type": "OTHER",
"mid": "",
"wikipediaUrl": "",
"numMentions": "1",
"avgSalience": "0.145794"
}, {
"name": "Busbahnhof",
"type": "LOCATION",
"mid": "",
"wikipediaUrl": "",
"numMentions": "1",
"avgSalience": "0.108006"
}, {
"name": "Stadt",
"type": "LOCATION",
"mid": "",
"wikipediaUrl": "",
"numMentions": "3",
"avgSalience": "0.079928"
}, {
"name": "Taubenplage",
"type": "OTHER",
"mid": "",
"wikipediaUrl": "",
"numMentions": "2",
"avgSalience": "0.072326"
}, {
"name": "Rutschgefahr",
"type": "OTHER",
"mid": "",
"wikipediaUrl": "",
"numMentions": "1",
"avgSalience": "0.070839"
},
{
"name": "Meike Böschemeyer",
"type": "PERSON",
"mid": "/g/11btlnnjgf",
"wikipediaUrl": "",
"numMentions": "1",
"avgSalience": "0.00451"
}]
}]
BigQuery自动在单独的列中显示不同的实体键值。如何查询特定键值?
我在试这个:
select JSON_VALUE(entities, '$.type') AS type from gcnlapi limit 1
但它给了我一个错误
No matching signature for function JSON_VALUE for argument types: ARRAY<STRUCT<name STRING, type STRING, mid STRING, ...>>, STRING. Supported signatures: JSON_VALUE(STRING, [STRING]); JSON_VALUE(JSON, [STRING]) at [3:8]
还尝试了以下操作:
select entities.type AS type from gcnlapi limit 1
但那会给予我
Cannot access field type on a value with type ARRAY<STRUCT<name STRING, type STRING, mid STRING, ...>> at [5:17]
1条答案
按热度按时间lb3vh1jj1#
我希望这个例子能帮助你:
使用
UNNEST
,您可以flatten
您的数组,并获得表的root
级别的字段以及数组的字段(扁平化)。在本查询中,根级字段为
polarity
、magnitude
、score
,其余对应数组字段。