Module 05 · Lesson 8 of 15Detailed study · about 20 min

Choose a file format and compression contract

A file format describes how bytes become records. File structure and compression are different choices: CSV can be compressed, and a .gz suffix alone does not tell you the record layout.

Understand the idea

Choose from the actual source contract, not the filename alone. A JSON document and a CSV file both contain data, but splitting the JSON at commas is not a valid substitute for a JSON parser. Parquet and ORC are not text files to open and edit by hand.

Key ideas in simple English
ConceptWhat it means
CSVDelimited text; separators, quotes and NULL markers must match the producer.
JSON / XMLNested documents with their own parsing rules.
Parquet / ORCColumn-oriented binary formats for analytical data.
AvroA binary record format carrying schema information.
CompressionReduces file size; supported codecs and detection rules depend on the format.

A concrete example

With the intended schema selected, six empty reader definitions are created. No data is loaded and no existing file is converted.

Remember: The format is a parsing definition, not a conversion job.

Explain it step by step · full theory

Understand the idea

Choose from the actual source contract, not the filename alone. A JSON document and a CSV file both contain data, but splitting the JSON at commas is not a valid substitute for a JSON parser. Parquet and ORC are not text files to open and edit by hand.

Compression wraps or encodes the bytes. AUTO can detect supported compression in many cases, but is not a promise to recognize every codec. For example, Brotli requires an explicit setting where supported. A ZIP archive is not interchangeable with a gzip-compressed data file.

Follow the workflow

The commands define separate format objects; they do not convert a CSV into Parquet or generate test files. Only use a format to read a compatible source file. JSON, Avro, ORC and XML query examples can expose a parsed value through $1; nested transformations are taught in Module 07.

For the shared CSV, AUTO_COMPRESS = FALSE on PUT keeps the staged sample filename easy to follow. Real pipelines should choose file sizing and compression together, then measure transfer and parsing behavior. Do not enable aggressive settings without checking producer compatibility.

Words used in this lesson
CSV
Delimited text; separators, quotes and NULL markers must match the producer.
JSON / XML
Nested documents with their own parsing rules.
Parquet / ORC
Column-oriented binary formats for analytical data.
Avro
A binary record format carrying schema information.
Compression
Reduces file size; supported codecs and detection rules depend on the format.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Choose a file format and compression contract

Source files
Storage location

Locate the data

A file format describes how bytes become records. File structure and compression are different choices: CSV can be compressed, and a .gz suffix alone does not tell you the record layout.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Locate the data

    A file format describes how bytes become records. File structure and compression are different choices: CSV can be compressed, and a .gz suffix alone does not tell you the record layout.

  2. Configure the boundary

    Choose from the actual source contract, not the filename alone. A JSON document and a CSV file both contain data, but splitting the JSON at commas is not a valid substitute for a JSON parser. Parquet and ORC are not text files to open and edit by hand.

  3. Observe the outcome

    The format is a parsing definition, not a conversion job.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Shared orders.csv and internal-stage setup
Our shared source file

Four orders, one CSV contract

Every CSV lesson uses this fictional orders.csv. One data record represents one order. The first line is a header; the four remaining lines are data. All amounts use the same fictional currency.

order_id,customer_name,amount,order_date
101,"Asha, Rao",120.50,2025-01-01
102,Ben,,2025-01-02
103,Cara,NULL,2025-01-03
104,Dev,0,2025-01-04

Notice the comma inside Asha’s quoted name, Ben’s empty amount, Cara’s literal NULL marker and Dev’s zero. We will follow these exact values from file bytes to parsed fields.

Setup order for optional manual practice
  1. Select an authorized sandbox database and schema. Keep this context consistent across your client sessions.
  2. Create orders_csv_v1 using lesson 3, then orders_stage using lesson 5. Use fresh sandbox names; do not replace existing shared objects.
  3. Save the text above as a UTF-8 file named orders.csv. Upload it with a supported local client or the named-stage upload interface.
  4. Keep only this sample file under the incoming/ prefix when following the four-row expected results.
  5. Select an authorized warehouse for the staged SELECT examples. File previews use compute; this website runs no SQL.

The examples assume the required role privileges described in the lessons. The external-stage and JSON examples have their own additional setup and are clearly marked.

Before running this lesson

Manual learning examples, not executed here. Use L2_OBJECTS_LAB.SALES from Module 03 and an authorized warehouse for previews. Run shared format/stage setup once. Cloud examples are templates: replace every <placeholder>, use approved cloud resources, and follow the provider setup before running SQL. No credentials belong in this website.

Define format-specific readers

SQL · example
CREATE FILE FORMAT m5_json TYPE=JSON;
CREATE FILE FORMAT m5_parquet TYPE=PARQUET;
CREATE FILE FORMAT m5_avro TYPE=AVRO;
CREATE FILE FORMAT m5_orc TYPE=ORC;
CREATE FILE FORMAT m5_xml TYPE=XML;
CREATE FILE FORMAT m5_csv_gzip TYPE=CSV COMPRESSION=GZIP
 SKIP_HEADER=1 FIELD_OPTIONALLY_ENCLOSED_BY='"';
SHOW FILE FORMATS IN SCHEMA L2_OBJECTS_LAB.SALES;

What to expect and why

With the intended schema selected, six empty reader definitions are created. No data is loaded and no existing file is converted.

Parse a small document without a staged file

SQL · example
SELECT PARSE_JSON('{"order_id":101,"amount":120.50}'):order_id::NUMBER AS ORDER_ID;
SELECT PARSE_XML('<order><id>101</id></order>') AS DOCUMENT;

What to expect and why

The first statement returns 101. The second returns Snowflake’s parsed XML representation; its display depends on the client. These examples distinguish parsing a document from reading CSV fields.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Does CREATE FILE FORMAT TYPE=PARQUET turn your CSV into Parquet?

Try it yourself

Why keep compression separate from the CSV delimiter rule?

Compare your reasoning

Compression concerns encoded bytes; delimiters concern fields after decompression. A correct decompressor cannot fix a wrong field separator.

Official sources and curriculum

Module 05 · See module scope