【问题标题】:Problem loading JSON with comma into Snowflake将带逗号的 JSON 加载到雪花中时出现问题
【发布时间】:2021-03-25 09:06:03
【问题描述】:

我在加载一些 JSON 数据时遇到问题。

数据如下:

{"geometry":{"coordinates":[12.5263,55.7664],"type":"Point"},"properties":{"created":"2021-01-19T17:08:14.114216Z","observed":"2020-01-01T23:50:00Z","parameterId":"pressure_at_sea","stationId":"06181","value":1025.1},"type":"Feature","id":"00e3bc2b-9a55-03dc-3740-005fd752f840"}
{"geometry":{"coordinates":[10.6217,55.8315],"type":"Point"},"properties":{"created":"2021-01-19T23:26:37.906088Z","observed":"2020-01-01T23:50:00Z","parameterId":"radia_glob","stationId":"06132","value":1},"type":"Feature","id":"00f7c039-6096-e2c2-5063-594c1c3bc16e"}
{"geometry":{"coordinates":[-37.6367,65.6111],"type":"Point"},"properties":{"created":"2021-01-19T23:26:37.913180Z","observed":"2020-01-01T23:50:00Z","parameterId":"radia_glob","stationId":"04360","value":0},"type":"Feature","id":"0142e2d1-9c28-e884-8d88-4b8fac5cae5d"}

挑战似乎是,当我尝试查看 JSON 数据时:

select $1, metadata$filename from @my_bucket/2020/2020-01.json.gz limit 3;

它只返回 JSON 的一部分:

$1  METADATA$FILENAME
{"geometry":{"coordinates":[12.5263     2020/2020-01.json.gz
{"geometry":{"coordinates":[10.6217     2020/2020-01.json.gz
{"geometry":{"coordinates":[-37.6367    2020/2020-01.json.gz

似乎坐标中逗号后的所有内容都被截断了,但我不知道如何避免这种情况。

兄弟。

托马斯

【问题讨论】:

    标签: json snowflake-cloud-data-platform


    【解决方案1】:

    $1 是第一列,这有助于表明您的数据被视为 CSV。这是默认的文件格式。

    尝试添加 file format FILE_FORMAT => 'my_json_file' 将通过以下方式创建:

    CREATE OR REPLACE FILE FORMAT my_json_file TYPE = JSON;
    

    【讨论】:

    • 这是我的一个令人尴尬的错误,file_format 滑倒了,昨晚很晚,但仍然没有任何借口:select $1, metadata$filename from @dmi_bucket/2020/2020-01.json.gz (file_format => json) limit 3; 工作就像一个魅力
    猜你喜欢
    • 2022-08-11
    • 2021-11-24
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多