【问题标题】:How to load .jsonl into a snowflake table variant?如何将 .jsonl 加载到雪花表变体中?
【发布时间】:2020-06-27 04:10:16
【问题描述】:

如何将 .jsonl 作为雪花的 json 加载到表变体中

create or replace table sampleColors (v variant);

insert into
   sampleColors
   select
      parse_json(column1) as v
   from
   values
     ( '{r:255,g:12,b:0} {r:0,g:255,b:0} {r:0,g:0,b:255}')
    v;

select * from sampleColors;

Error parsing JSON: more than one document in the input

【问题讨论】:

    标签: snowflake-cloud-data-platform snowflake-schema snowflake-task


    【解决方案1】:

    如果您希望每个 RGB 值在其自己的行中,则需要使用如下表函数将 JSONL 拆分为每个 JSON 一行的表:

    insert into
        sampleColors
    select parse_json(VALUE) 
        from table(split_to_table( '{r:255,g:12,b:0} {r:0,g:255,b:0} {r:0,g:0,b:255} {c:0,m:1,y:1,k:0} {c:1,m:0,y:1,k:0} {c:1,m:1,y:0,k:0}', ' '));
    

    【讨论】:

    • 对不起,我没有正确解释我需要做什么。我正在尝试将.jsonl 文件加载到列类型变体的雪花表中。我需要将每个 json 行加载到一个新行中。 (它可能正在使用新的行分隔符)。但我无法找到正确的解决方案。对此非常感谢任何帮助。非常感谢。
    • 为了清楚起见,我去掉了第二个选项。代码部分执行您所描述的操作。它通过它们之间的空间分割 JSONL,并将它们变成一个 JSON 变体表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2020-10-07
    • 2022-01-15
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多