Sub topic 1
What Batch Ingestion Is and Where COPY INTO Fits
Prerequisites
You should know basic SQL, Delta tables, and common file formats such as CSV, JSON, and Parquet. You also need access to a Databricks workspace with a SQL warehouse or cluster.
What Batch Ingestion Is and Where COPY INTO Fits
Batch ingestion loads files in groups rather than processing each record immediately. For example, a daily job might load all order files uploaded during the previous day.
COPY INTO is a Databricks SQL command for loading files from cloud storage or a Unity Catalog volume into a Delta table. It records which files it has processed, so repeating the command normally does not load the same files twice.
Use COPY INTO for simple, repeatable batch loads. For continuously arriving files or very large file collections, Auto Loader is often a better fit.
Pointing COPY INTO at Your Data: Volumes, External Locations and Permissions
A Unity Catalog volume provides a governed path such as /Volumes/main/sales/landing/orders/. An external location connects Unity Catalog to a cloud storage path outside a volume.
The identity running the command needs permission to read the source. For a volume, this commonly includes USE CATALOG, USE SCHEMA, and READ VOLUME. For an external location, it generally needs permission to use the location and read files. It also needs permission to modify the destination schema and table.
Your First COPY INTO Statement
Create the target Delta table, then provide its source directory and file format:
CREATE TABLE IF NOT EXISTS main.sales.orders (
order_id BIGINT,
amount DECIMAL(10, 2),
order_ts TIMESTAMP
) USING DELTA;
COPY INTO main.sales.orders
FROM '/Volumes/main/sales/landing/orders/'
FILEFORMAT = CSV
FORMAT_OPTIONS (
'header' = 'true',
'delimiter' = ','
);The command reads matching files, parses their rows, and appends valid records to the target table.
File Formats and FORMAT_OPTIONS
FILEFORMAT tells Databricks how to parse each file. Use CSV, JSON, or PARQUET. FORMAT_OPTIONS controls parser behavior, including CSV headers, delimiters, quotes, and escape characters.
Exercise
What does FORMAT_OPTIONS ('header' = 'true') tell COPY INTO to do?
Show answer
It treats the first row of each CSV file as column names instead of data.