snowflake外部表从json列表



得到一个文件。s3桶中的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行的表,而是得到一行中有一个列表,什么好主意吗?

如果该值作为数组提供,则可以使用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);

最新更新