Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load parquet file into Snowflake database?

Is it possible to load parquet file directly into a snowflake? If yes - how?

Thanks.

like image 667
Joe Avatar asked Jan 02 '23 04:01

Joe


1 Answers

Yes it is possible, and best done via S3. Note, the following assumes you have a MY_PARQUET_LOADER table, a STAGE_SCHEMA schema and an S3STAGE defined, and that your parquet files are on the bucket under the /path/ key/folder.

  copy into STAGE_SCHEMA.MY_PARQUET_LOADER
     from ( 
       select
       $1
     ,metadata$filename as metadata_filename
     ,metadata$file_row_number as metadata_file_row_number  
     ,current_timestamp() as load_timestamp
       from
  @S3STAGE/path/)
   pattern = '.*.parquet'
  file_format = (
  TYPE = 'PARQUET' 
  SNAPPY_COMPRESSION = TRUE    )
  ON_ERROR = 'SKIP_FILE_1%'
  purge= TRUE;

where this exists:

create or replace TABLE MY_PARQUET_LOADER (
    RAW VARIANT,
    METADATA_FILENAME VARCHAR(16777216),
    METADATA_FILE_ROW_NUMBER NUMBER(38,0),
    LOAD_TIMESTAMP TIMESTAMP_LTZ(9)
) cluster by (METADATA_FILENAME);

Worthwhile to read the fine manual:
https://docs.snowflake.net/manuals/sql-reference/sql/copy-into-table.html

like image 69
Serban Tanasa Avatar answered Jan 10 '23 08:01

Serban Tanasa