【问题标题】:Loading nested array into bigquery from public google cloud dataset从公共谷歌云数据集中将嵌套数组加载到 bigquery
【发布时间】:2020-09-24 01:59:54
【问题描述】:

我正在尝试将公共数据集从 Google Cloud 加载到 BigQuery (quickdraw_dataset)。数据为JSON格式,如下:

 { 
    "key_id":"5891796615823360",
    "word":"nose",
    "countrycode":"AE",
    "timestamp":"2017-03-01 20:41:36.70725 UTC",
    "recognized":true,
    "drawing":[[[129,128,129,129,130,130,131,132,132,133,133,133,133,...]]]
  }

我遇到的问题是“绘图”字段是一个嵌套数组。我从阅读其他帖子中收集到您无法将数组读入 BigQuery? This post 建议解决此问题的一种方法是将数组作为字符串读取。但是,当我使用以下架构时,我收到此错误: `

 [
    {
        "name": "key_id",
        "type": "STRING"
    },
    {
        "name": "word",
        "type": "STRING"
    },
    {
        "name": "countrycode",
        "type": "STRING"
    },
    {
        "name": "timestamp",
        "type": "STRING"
    },
    {
        "name": "recognized",
        "type": "BOOLEAN"
    },
    {
        "name": "drawing",
        "type": "STRING"

    }
]

读取数据时出错,错误消息:从位置 0 开始的行中的 JSON 解析错误:为非重复字段指定的数组:绘图。

有没有办法将此数据集读入 BigQuery?

提前致谢!

【问题讨论】:

    标签: json google-cloud-platform google-bigquery quickdraw


    【解决方案1】:

    将整行加载为 CSV,然后在 BigQuery 中解析。

    加载:

    bq load --F \\t temp.eraser gs://quickdraw_dataset/full/simplified/eraser.ndjson row

    查询:

    SELECT JSON_EXTRACT_SCALAR(row, '$.countrycode') a
      , JSON_EXTRACT_SCALAR(row, '$.word') b
      , JSON_EXTRACT_ARRAY(row, '$.drawing')[OFFSET(0)] c
    FROM temp.eraser
    

    【讨论】:

      猜你喜欢
      • 2019-12-08
      • 2017-02-10
      • 2016-06-07
      • 2023-04-09
      • 2018-10-30
      • 2018-05-26
      • 2018-10-27
      • 2020-06-15
      • 2017-10-26
      相关资源
      最近更新 更多