【问题标题】:Parquet file load into snowflake table IssueParquet 文件加载到雪花表中问题
【发布时间】:2021-09-03 03:20:46
【问题描述】:

我正在尝试将 AWS S3 中 parquet 文件中的数据加载到雪花表中。但得到以下错误。你能帮忙吗?

SQL 编译错误:PARQUET 文件格式只能生成一列类型变量或对象或数组。如果要加载多列,请使用 CSV 文件格式。

Parquet 文件架构

 |-- uuid: string (nullable = true)
 |-- event_timestamp: timestamp (nullable = true)
 |-- params: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- id: string (nullable = true)
 |    |    |-- name: string (nullable = true)
 |    |    |-- type: string (nullable = true)
 |    |    |-- value: string (nullable = true)

这是示例数据。 uuid,事件时间戳,参数 3f230ea5-dd52-4cf9-bdde-b79201eb1001,2020-05-10 17:06:21.524,[{id=501, type=custom, name=filtering, value=true}, {id=502, type=custom, name =select, value=false}]

雪花桌

create or replace table temp_log (
      uuid string, 
      event_timestamp timestamp, 
      params array);

我正在使用下面的复制命令来加载数据

 copy into temp_log
 from '<<s3 path>>'
 pattern = '*.parquet'
 storage_integration = <<integration object>
 file_format = (
     type = parquet
     compression = snappy
 )
 ;

【问题讨论】:

    标签: snowflake-cloud-data-platform parquet


    【解决方案1】:

    本文档说明了如何将 parquet 数据加载到多个列中: Loading Parquet

    更新

    我不确定下面的评论是否是对我的回答的回应,如果是,它的相关性是什么?您是否阅读过文档,如果阅读过,您对文档的哪一部分仍有疑问?

    您需要将数据放在一个阶段(在您的情况下可能是一个外部阶段),或者可能在一个外部表中,然后使用“COPY INTO table FROM (SELECT...” $1:.. 表示法允许您从镶木地板结构中选择适当的元素。

    来自文档:

    /* Load the Parquet data into the relational table.                                                           */
    /*                                                                                                            */
    /* A SELECT query in the COPY statement identifies a numbered set of columns in the data files you are        */
    /* loading from. Note that all Parquet data is stored in a single column ($1).                                */
    /*                                                                                                            */
    /* Cast element values to the target column data type.                                                        */
    
    copy into cities
      from (select
      $1:continent::varchar,
      $1:country:name::varchar,
      $1:country:city.bag::variant
      from @sf_tut_stage/cities.parquet);
    

    【讨论】:

    • 在 parquet 文件中,params 字段数据类型是结构元素数组。我在雪花中找不到相应的数据类型。在 AWS athena 中,我们可以使用以下参数 array>;
    • 创建表后,此问题已解决,如下创建或替换表 temp_log ( logcontent VARIANT);
    【解决方案2】:

    创建如下表后,此问题已解决

    create or replace table temp_log (
    
         logcontent VARIANT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2020-09-27
      • 2022-01-08
      • 2022-12-06
      • 2022-09-21
      • 2021-04-08
      • 1970-01-01
      相关资源
      最近更新 更多