首页 > 解决方案 > 使用分区 ADLS 复制到

问题描述

我有一个带有分区镶木地板文件的容器,我想将其与 copy into 命令一起使用。我的目录如下所示。

ABC_PARTITIONED_ID=1 (directory)
1-snappy.parquet
2-snappy.parquet
3-snappy.parquet
4-snappy.parquet

ABC_PARTITIONED_ID=2 (directory)
1-snappy.parquet
2-snappy.parquet
3-snappy.parquet

ABC_PARTITIONED_ID=3 (directory)
1-snappy.parquet
2-snappy.parquet

……

每个分区目录可以包含多个 parquet 文件。我没有与目录模式(ID1、ID2 等)匹配的配置单元分区列。

如何正确使用 copy into 命令中的模式参数从我的 ADLS 写入 SF 表?我以https://www.snowflake.com/blog/how-to-load-terabytes-into-snowflake-speeds-feeds-and-techniques/为例。

标签: snowflake-cloud-data-platform

解决方案


如果目录/分区名称对您来说并不重要,那么您可以使用公共预览版中支持 Parquet 格式的一些较新的函数来创建表和摄取数据。您关于如何构建模式的问题将是 PATTERN='*.parquet' 因为所有子文件夹都将被读取。

    //create file format , only required to create one time
    create file format my_parquet_format
      type = parquet;
     
    //EXAMPLE CREATE AND COPY INTO FOR TABLE1
    //create an empty table using this file format and location. name the table table1
     create or replace table ABC
      using template (
        select array_agg(object_construct(*))
          from table(
            infer_schema(
              location=>'@mystage/ABC_PARTITIONED_ROOT',
              file_format=>'my_parquet_format'
            )
          ));
         //copy parquet files in folder /table1 into table TABLE1
        copy into ABC from @mystage/ABC_PARTITIONED_ROOT pattern = '*.parquet' file_format=my_parquet_format match_by_column_name=case_insensitive;

推荐阅读