简体   繁体   English

Google BigQuery - 将字符串解析为 JSON object 获取字段并评估为字符串

[英]Google BigQuery - parsing string to JSON object fetching field and evalaute as string

I'm parsing a Google BigQuery table patents-public-data.uspto_peds.backfile and the fields are JSON formatted strings.我正在解析 Google BigQuery 表patents-public-data.uspto_peds.backfile并且字段是 JSON 格式的字符串。

I can parse the field to SELECT only one of the values like so:我可以将该字段解析为SELECT只有一个值,如下所示:

PARSE_JSON(json_strong)['attribute'][0]['attribute2'] as aliasName

But in the WHERE clauses I want to also limit the returns to only values that have a date after a certain value.但是在 WHERE 子句中,我还想将返回值限制为仅具有特定值之后的日期的值。 When I try was seems reasonable with that:当我尝试时,这似乎是合理的:

WHERE
EXTRACT(YEAR FROM DATE(PARSE_JSON(priorityClaimBag)['priorityClaim'][0]['filingDate'])) > 2018

I get the error:我收到错误:

No matching signature for function DATE for argument types: JSON. Supported signatures: DATE(TIMESTAMP, [STRING]); DATE(DATETIME); DATE(INT64, INT64, INT64); DATE(DATE); DATE(STRING) at [28:23] 

This is in fact a string field with a valid datetime.这实际上是一个具有有效日期时间的字符串字段。 Using the alias does not seem to work either.使用别名似乎也不起作用。

Is it infact possible to evaluate this string as JSON, parse the object and then cast to DATE in this way?实际上是否可以将此字符串评估为 JSON,解析 object,然后以这种方式转换为 DATE?

Use JSON_EXTRACT_SCALAR instead as in below example使用 JSON_EXTRACT_SCALAR 代替,如下例所示

WHERE 
  EXTRACT(YEAR FROM DATE(JSON_EXTRACT_SCALAR(priorityClaimBag, '$.priorityClaim[0].filingDate'))) > 2018

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM