如何创建附加列并在 inferschma synatx 中使用分区子句

问题描述 投票:0回答:1

我正在从 s3 读取数据,以使用 inferschmea 在雪花中创建外部表。我从表达式列中获取所有列,但想要附加列日期以在分区依据中使用它。我如何使用 inferschmea 实现这一目标?

create or replace external table people_test1
  using template (
    select expression,filenames, substr(filenames,24,10) DATE_PART
 
      from table(
        infer_schema(
          location=>'@ITCHBOD.COMPANY_STAGE/cre/invets/',
          file_format=>'CRUPARQUET',
          partition by (DATE_PART)
        )
      ) 
  )
snowflake-cloud-data-platform snowflake-schema
1个回答
0
投票

有同样的问题。使用snowsql通过一种巧妙的解决方法解决了这个问题:

1:像您一样创建外部表

2:手动添加日期部分

alter table people_test1 add date_part date as some_extraction_logic(metadata$filename);

3:从表生成 DDL 并通过替换将分区语句放入

select replace(get_ddl('table', 'people_test1'),'location=','partition by (date_part)\nlocation=');

4:执行生成的ddl

我希望Snowflake有一天能提供更好的解决方案

© www.soinside.com 2019 - 2024. All rights reserved.