首页 > 解决方案 > Parquet 文件加载到雪花表中问题

问题描述

我正在尝试将 AWS S3 中镶木地板文件中的数据加载到雪花表中。但得到以下错误。能否请你帮忙。

SQL compilation error: PARQUET file format can produce one and only one column of type variant or object or array. 
Use CSV file format if you want to load more than one column.

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,event_timestamp,params 3f230ea5-dd52-4cf9-bdde-b79201eb1001,2020-05-10 17:06:21.524,[{id=501, type=custom, name=filtering, value=true}, {id=502,类型=自定义,名称=选择,值=假}]

雪花桌

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-platformparquet

解决方案


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

更新

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

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

从文档中:

/* 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);

推荐阅读