【问题标题】:snowflake external table from a list of jsonsjsons 列表中的雪花外部表
【发布时间】:2021-08-16 14:29:25
【问题描述】:

在我的 s3 存储桶中有一个 file.json,它包含一个 json 列表, 例如,当我下载它并使用 python json load 解析它时,我得到一个列表:

[{'k': 'calendar#event'}, {'k': 'calendar#event'}]\

将其加载到外部表中:

create external table if not exists TEST_111
with location = @TESt111
auto_refresh = true
file_format = (type = json);

但是我没有得到一个有 2 行的表,而是得到了一个包含列表的行, 有什么想法吗?

【问题讨论】:

  • 创建外部表时,数据存储在单个 VARIANT 列中,请参阅here。另外,请查看为半结构化数据here 提供的可选参数和示例。
  • 您是否尝试过在文件格式选项中使用 STRIP_OUTER_ARRAY = TRUE?

标签: python json amazon-web-services snowflake-cloud-data-platform external-tables


【解决方案1】:

如果值作为数组提供,则可以使用strip_outer_array

create external table if not exists TEST_111
with location = @TESt111
auto_refresh = true
file_format = (type = json, STRIP_OUTER_ARRAY=TRUE);

另外,如果预先知道 json 键,它们可以直接在外部表的定义中作为列公开:

create external table if not exists TEST_111
(
    filename    TEXT  metadata$filename
   ,k           TEXT  AS (value:"k"::TEXT)
)
with location = @TESt111
auto_refresh = true
file_format = (type = json, STRIP_OUTER_ARRAY=TRUE);

【讨论】:

    猜你喜欢
    • 2020-10-07
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    相关资源
    最近更新 更多