Skip to content

Sources

Files

The files source: settings, which files load, columns, columns from paths, whole records, SFTP servers and the files a destination reads itself.

A files source is one table built from every file under a folder, in S3, Google Cloud Storage, a local folder or an SFTP server. To set one up, see Load files.

[connections.lake]
kind = "s3"
bucket = "example-bucket"
region = "eu-west-2"
[sources.events]
kind = "files"
connection = "lake"
path = "events/"
format = "parquet"
description = "Click events, partitioned by day."
partition_columns = { dt = "date" }
write_strategy = "delete_insert"
cursor_column = "dt"
Setting Meaning
connection An s3, gcs, filesystem or sftp connection.
path The folder, relative to the connection.
format parquet (default), ndjson, json (objects in sequence, or an array), csv, xlsx or xml.
compression auto (default, by .gz or .zst name), none, gzip, zstd, or zip for archives.
csv Default { delimiter = ",", header = true, quote = '"', null_values = [""] }; also escape, encoding, encoding_check, skip_rows. Headerless columns are column_1, column_2, …
xlsx { sheet = "...", header = true, skip_rows = 0 } (the first sheet by default), or range and header_row.
xml { record_path = "orders/order", lists = [] }; record_path is required.
column_names Names for the columns of headerless CSV or Excel files.
members With compression = "zip", a glob member names must match.
pattern A glob over paths below path, in place of the format’s suffix.
order modified (default) or path.
after_load "keep" (default), "delete" or { move_to = "<folder>" }.
on_empty fail (default) or skip.
shape columns (default) or record, into record_column (record by default).
partition_columns Hive key=value folders as typed columns, such as { dt = "date" }.
path_columns A template capturing columns from paths; unmatched_paths is fail (default) or skip.
constant_columns The same value in every row, such as { region = "eu" }.
transform A Python function run on each file.
copy_to_internal_stage Snowflake only: upload files no external stage covers (Load methods).

Without pattern, a source reads files ending in its format’s suffix: .csv, .csv.gz and .csv.zst for csv, and so on; a folder of other files fails plan, suggesting pattern. pattern is a glob over each path below path, so files of any name load as format:

[sources.exports]
kind = "files"
connection = "drop"
path = "erp/"
pattern = "file_*.txt"
format = "csv"
csv = { delimiter = "|" }
write_strategy = "merge"
unique_key = ["id"]

* matches within one name and ** across folders: "file_*.txt" reads file_1.txt but not old/file_2.txt; "**/file_*.txt" reads both. Compression still follows the name. With zip, pattern picks the archives and members their members. Files that don’t match are never read, moved or deleted, and a folder holding only those counts as empty.

├── files 2 new of 2 matching file_*.txt, 1 other file ignored
Strategy Reads
append Files not loaded yet, by _sqlload_source_file. A file rewritten in place since, or loaded without a version (an empty _sqlload_source_version), fails the table; --reload fixes it.
delete_insert with a partition cursor_column (from partition_columns or path_columns) The newest loaded partition and everything after it, each replaced whole.
delete_insert with a replace_key New or changed files. See Replacing rows by a key.
replace Every file, swapped in as a new table.
merge with a unique_key New or changed files. See Merging files.

A files source needs a write_strategy, and a merge its unique_key. plan refuses an append table that excludes _sqlload_source_file or _sqlload_source_version. Loads commit every 1,000 files or about 1 GB; delete_insert never splits a partition across commits.

$ sqlload plan -v
…
└── raw.events_log append
├── source files lake/events/ parquet
├── files 1 new of 3 listed
├── route DuckDB reads directly from lake/events/ (nothing through the loader)
…

With a partition cursor, a file below the range the load reads fails the table if it changed since it loaded (a monthly file corrected after the next month loaded), if it’s new in a partition the table holds (a part file added to a loaded month), or if the table holds it without a version. Skipping it would keep its old rows or never load it:

$ sqlload plan
…
Errors (1)
└── raw.le
├── reason /data/drop/le_LE-FY27-P01.csv changed since it was loaded (version e3c0-3b9aca00-47
│ is now e3c0-b2d05e00-3b), but its file_version LE-FY27-P01 is below this load's
│ range, which starts at LE-FY27-P02, so delete_insert would skip it and keep its old
│ rows
└── fix set replace_key to replace rows by a column the files hold (and drop
cursor_column), load from it with --start-cursor LE-FY27-P01, or rebuild the table
with --reload

To find them, each plan reads the table’s file and version columns (billed on BigQuery), unless the load has --start-cursor or --reload.

delete_insert with a replace_key and no cursor_column loads each new or changed file in order. Each file replaces the rows holding the key values it holds, so a corrected file replaces its version whole, dropped lines included, and leaves other versions alone.

[sources.le]
kind = "files"
connection = "lake"
path = "finance/le/"
format = "csv"
description = "Latest Estimate, one file per version, with its le_version."
write_strategy = "delete_insert"
replace_key = ["le_version"]
$ sqlload plan -v
…
└── raw.le delete_insert (replace_key: le_version; NULLs in keys match)
…
└── batch 1 file, 1 commit, oldest modified first (ties by path), each recorded in the run log

One file must hold all of a value’s rows. If a value’s rows came from another file still in the folder, or loaded earlier in the run, the table fails, naming both files, and that commit rolls back. Put each value in one file, set on_overlapping_files = "last_wins" (below), remove the older file, or set after_load so loaded files leave the folder.

It loads into DuckDB and Postgres targets only. --reload, state = "logged", a cursor_column and excluding _sqlload_source_file are refused.

on_overlapping_files = "last_wins" (default "fail") lets the file last in order replace the values it holds while an earlier file holding them is still in the folder. The earlier file’s other values stay:

sales/
sales_2026-11-07.csv business_date Nov 1 .. Nov 7
sales_2026-11-14.csv business_date Nov 5 .. Nov 14 <- Nov 5 to 7 come from this file
[sources.sales]
kind = "files"
connection = "lake"
path = "sales/"
pattern = "sales_*.csv"
format = "csv"
description = "Daily sales, each delivery restating the days before it."
write_strategy = "delete_insert"
replace_key = ["business_date"]
order = "path"
on_overlapping_files = "last_wins"
  • Set order = "path" when names sort by date. By default the file modified last wins.
  • A file that sorts before one already loaded, such as an older file sent late, still fails, as does, under order = "path", a file rewritten while a later one isn’t. By modified time a rewritten file sorts last and replaces the values.
  • Keep "fail" when files may be parts of one export: "last_wins" keeps only the last part.
  • A table that excludes _sqlload_source_row loads each file in its own commit.

merge upserts each new or changed file on its unique_key, oldest modified first, so the file modified last wins a repeated key. Each commit records its files in the table’s run log, _sqlload_runs, and later loads skip them. A failed commit rolls back with its files, and the next load continues from there.

[sources.prices]
kind = "files"
connection = "lake"
path = "prices/"
format = "csv"
description = "Price lists, each file updating the prices it names."
write_strategy = "merge"
unique_key = ["sku"]
  • A file that arrives late, or changes, merges after the others, as the newest. With newest_by, its rows still replace only older rows.
  • order = "path" orders by path below path (a ZIP member as <archive>.zip/<member>), in code point order. Use it when names carry an ISO date, such as export_2026-11-09.csv, as unzipping, cp, gsutil and sync tools rewrite modified times.
  • Files with the same modified time, such as one archive’s members or SFTP files from one second, go in path order.
  • A key repeated in one file merges its last row, or the newest by newest_by; see Repeated keys. on_duplicate_keys = "fail" fails such a file instead, and commits each file alone.
  • It loads into DuckDB and Postgres targets only (MotherDuck through its DuckDB connection, not tested live). state = "logged" and a cursor_column are refused.

after_load deletes or moves each file once the table’s load succeeds:

[sources.orders]
kind = "files"
connection = "lake"
path = "drop/"
format = "csv"
description = "Orders dropped by the nightly export."
write_strategy = "append"
after_load = { move_to = "loaded" }
  • It needs append, merge, or delete_insert with a replace_key. Not for SFTP or files targets.
  • A failed load touches no file, even files committed before the failure. Later loads skip those, so move them yourself.
  • move_to is a folder on the same connection, not inside path or holding it. Files keep their key: drop/2026/a.csv moves to loaded/2026/a.csv.
  • A move never replaces a file at the destination. On S3, a file written to the same key at that moment could be replaced, and a file over 5 GB stays. A file that changed since it was read stays.
  • A failed delete or move warns but doesn’t fail the load; load --json gives after_load status "failed", listing the files.
  • A ZIP archive is handled once every member read from it has committed. plan refuses this while another source reads ZIP archives in that folder, or one inside or around it.

An existing folder with no files (hidden ones aside) fails the load, in case of a broken mount or wrong path: no .csv, .csv.gz, .csv.zst files found; ... where an empty folder is normal, set on_empty = "skip".

[sources.orders]
kind = "files"
connection = "landing"
path = "orders/"
format = "csv"
description = "Orders unzipped into the landing folder by the download step."
write_strategy = "merge"
unique_key = ["order_id"]
order = "path"
on_empty = "skip"

With on_empty = "skip", or once after_load has emptied the folder of a table that has loaded, the table is skipped and the load exits 0, with the reason in plan and load --json’s plan.skipped: no files to load in orders/ (on_empty = "skip").

  • A missing or unreadable folder, or one holding files of another format or that don’t match path_columns, still fails.
  • S3, GCS and SFTP list a missing folder as empty, so there a skip needs the table to exist. Watch the skipped reason.
  • An empty folder whose table another source also loads fails; run the others with --exclude.

sqlload load <table> --reload reads every listed file into a new table, swapped in at the end. Postgres targets refuse it.

Table --reload
append, replace, delete_insert on a partition cursor Reads the files in batches, as a first load.
merge Under order = "path", every file by path. Otherwise the files merged before, in the order they merged, then the others, oldest modified first. Refused with unnest: drop the table and its child tables and load again.
delete_insert with a replace_key, or after_load = "delete" Refused.

With move_to, the reload also reads the moved files, through SQLLoad rather than the destination, and _sqlload_source_file still names them under path. A failed reload moves nothing and leaves the old table.

├── files 3 to read of 3 listed: 1 in ./drop/, 2 in ./done/

Parquet columns come from the files’ footers. CSV and JSON columns are inferred from a sample unless pinned in columns, or loaded as text with infer_types = false. Each row also gets the _sqlload_source_* columns.

  • Parquet lists, structs and maps load as json, with decimals and times inside as strings such as "1.50", and their files go through SQLLoad. Snowflake loading from a stage fails plan on such a column: leave it out with exclude_columns.
  • Pin a list column, or a JSON array, as array(T) to load an array.
  • flatten loads a JSON object’s keys as columns, and parse reads text as times.

path_columns is a template over each file’s path below path:

[sources.orders]
kind = "files"
connection = "lake"
path = "orders/"
path_columns = "{region}/{channel}/{order_date:date}/*.parquet"
constant_columns = { shop = "main", schema_version = 2 }
write_strategy = "delete_insert"
cursor_column = "order_date"

A file at orders/eu/web/2026-11-08/part-0.parquet loads with region = 'eu', channel = 'web', order_date = 2026-11-08, shop = 'main' and schema_version = 2.

In a template Matches
{name} or {name:type} A value inside one name, loaded as column name; any partition_columns type, text by default.
* Any text inside one name.
** Any number of folders, as a whole segment: **/{day:date}.json.
Anything else Itself.
  • The template matches the whole path. A date capture matches 2026-11-08 or 20261108, and an integer capture digits only. A text capture takes the shortest match, so keep a literal between two captures.
  • A path that doesn’t match fails plan unless unmatched_paths = "skip". A value that doesn’t convert always fails.
  • constant_columns types TOML values: a string as text, an integer int, a float float, a boolean bool, a date date, and a date-time timestamp_tz with an offset or timestamp_ntz without. Otherwise write { value = "12.50", type = "decimal(10,2)" }.
  • Both work like Hive partition columns. A captured date can be the cursor_column of delete_insert; a constant can’t. A same-named column in the files is replaced. Each column comes from only one of partition_columns, path_columns and constant_columns, ignoring case.

shape = "record" loads each record whole into one json column, to parse in the destination:

[sources.events]
kind = "files"
connection = "lake"
path = "events/"
format = "ndjson"
shape = "record"
record_column = "payload"
partition_columns = { dt = "date" }
write_strategy = "append"
  • JSON and NDJSON: each object. A record that isn’t an object fails, naming its file and line.
  • CSV: each line as a JSON array of strings, such as ["1", "a,b", null]. With header = true, each file’s first line is skipped unchecked. Every line needs as many fields as the file’s first.
  • Nothing is sampled, so tables pin no other columns; partition, path, constant and _sqlload_source_* columns load beside it. The column is json (VARIANT in Snowflake). Parquet, Excel and XML can’t use it.

A field starting with quote (") may hold the delimiter and line breaks, with a quote inside doubled ("say ""hi"""). A quote inside an unquoted field (12" pipe) is plain text.

Setting Effect
csv = { escape = "\\" } A backslash in a quoted field escapes the next character: "said \"hi\"" reads as said "hi". None by default, so "C:\exports\" reads as written.
csv = { quote = false } Quotes are plain characters; fields split on the delimiter only.

Text after a closing quote, or a file ending inside a quoted field, fails the file: a.csv: line 2: text after a closing quote or unterminated quoted field. The error suggests these settings, which SQLLoad never guesses.

csv.encoding is utf-8 (default), cp1252, latin-1, ascii, utf-16le, utf-16be, or any Encoding Standard label, such as iso-8859-15 or shift_jis; an unknown name fails plan. csv.skip_rows skips lines before the header, such as a title:

csv = { encoding = "cp1252", skip_rows = 2 }

A byte the encoding doesn’t define fails the table with the file, line and byte: a.csv: line 3, byte 15: 0x81 is not valid windows-1252. Invalid UTF-8 suggests setting csv.encoding. Error line numbers count skipped lines; a file whose lines end in a bare \r fails.

A file read as latin-1, cp1252 or iso-8859-15 also fails when its bytes say otherwise, naming the encoding to set: 0x80 to 0x9F in latin-1 or iso-8859-15 suggest cp1252, and mostly valid UTF-8 (Société) suggests utf-8. encoding_check = false turns this off.

A file labelled ISO-8859-1 holding € or Œ is usually iso-8859-15 or cp1252. For Œ in BŒUF, grep -a 'B.UF' a.csv | xxd shows BC for iso-8859-15, 8C for cp1252 and C5 92 for UTF-8.

Snowflake reading CSV itself supports utf-8, latin-1, windows-1250 to -1256, iso-8859-2, -5, -6, -7 and -15, koi8-r, utf-16le and utf-16be; any other fails plan for that route. It loads undefined bytes as control characters. With encoding_check on, SQLLoad reads latin-1, cp1252 and iso-8859-15 files itself.

SQLLoad reads these itself, each workbook, XML document or ZIP member whole, up to 1 GiB.

Excel (format = "xlsx") loads one sheet: xlsx.sheet, or the first. .xls isn’t read.

  • skip_rows skips rows at the top; the next names the columns unless header = false, when they are column_1, column_2, … or column_names. Empty rows are left out.
  • Cells keep their type: whole numbers int, others float, TRUE/FALSE bool, date-formatted cells date, timestamp_ntz or time. Empty cells and errors such as #N/A are NULL; formulas load cached values. A value that doesn’t fit its sampled type fails with its row unless columns pins one.
  • A sheet over 20 million values fails.

xlsx.range reads an A1 range, as Google Sheets does: 'Q4 Report'!B3:H, or A3:C to the last row of the first sheet. It replaces sheet and skip_rows; setting either with it fails plan. Its first row with a value names the columns, or header_row, counted from the range’s first row:

# sheet, first row and columns in one place
xlsx = { range = "Prices!A3:C" }
# first sheet, columns A to C, no header row
xlsx = { range = "A:C", header = false }
column_names = ["metric", "category", "value"]

XML (format = "xml") loads each element at xml.record_path as a row, its attributes and children as columns, without namespace prefixes:

[sources.customers]
kind = "files"
connection = "lake"
path = "drop/"
format = "xml"
xml = { record_path = "customers/customer", lists = ["phone"] }
description = "Customers from the nightly XML export."
write_strategy = "replace"
  • A repeated child, or one in lists, loads as a JSON array; a child with its own attributes or children as a JSON object.
  • Text is trimmed and typed as CSV fields are; xsi:nil="true" is NULL.
  • Malformed XML, two attributes (or an attribute and a child) of one name, a UTF-16 document, or a record_path the document doesn’t have fails, with the line.

ZIP archives (compression = "zip"): each member matching the format’s suffix and members loads as a file, recorded as <archive>.zip/<member>. Define one source per format:

[sources.orders]
kind = "files"
connection = "lake"
path = "drop/"
format = "csv"
compression = "zip"
members = "*.csv"
description = "Orders from the nightly ZIP export."
write_strategy = "replace"
[sources.lines]
kind = "files"
connection = "lake"
path = "drop/"
format = "xlsx"
compression = "zip"
xlsx = { sheet = "Lines" }
description = "Order lines from the workbook in the nightly ZIP export."
write_strategy = "replace"

A member’s version is its archive’s, so under append a rewritten archive fails the table. An archive naming two members alike fails.

column_names names the columns of CSV or Excel files with header = false, in order:

[sources.metrics]
kind = "files"
connection = "inbox"
format = "xlsx"
xlsx = { range = "A:C", header = false }
column_names = ["metric", "category", "value"]
write_strategy = "merge"
unique_key = ["metric", "category"]
[sources.metrics.tables.metrics]
columns = { value = "decimal(12,2)" }

The count must match each file’s columns, or the range’s width, exactly; otherwise plan or the load fails, naming both counts. With a header row, use rename.

A transform is a Python function that makes each file loadable: fixing headers, dropping totals rows or unpivoting a sheet; keep business logic in SQL. Register it with @sl.transform (or @sl.transform("name")) in a module under python_paths, and name it in transform. It needs the sqlload Python package and pyarrow, not the standalone sqlload-cli. The same functions reshape Google Sheets ranges and sl.http pages.

python_paths = ["transforms"]
[sources.metrics]
kind = "files"
connection = "lake"
path = "drop/metrics/"
format = "csv"
description = "Monthly metrics, one file a month."
write_strategy = "append"
transform = "metric_rows"
transforms/metrics.py
import pyarrow as pa
import sqlload as sl
@sl.transform
def metric_rows(rows: pa.Table, ctx: sl.TransformContext):
for row in rows.to_pylist():
if row["metric"] in (None, "Total"):
continue
for month, value in row.items():
if month != "metric" and value is not None:
yield {"metric": row["metric"], "month": month,
"value": float(value)}

It’s called once per file (and ZIP member) as f(rows, ctx): rows is a pyarrow.Table, and ctx an sl.TransformContext with unit ("file"), path (as in _sqlload_source_file), modified_at, sheet, range, skip_rows and table. It returns or yields what a Python table may: dicts, a pyarrow.Table, or a polars or pandas DataFrame. For large files, return Arrow or a DataFrame:

transforms/metrics.py
import polars as pl
import pyarrow as pa
import sqlload as sl
@sl.transform
def metric_rows(rows: pa.Table, ctx: sl.TransformContext):
metric = pl.col("metric")
frame = pl.from_arrow(rows).filter(metric.is_not_null()
& (metric != "Total"))
tidy = frame.unpivot(index="metric", variable_name="month",
value_name="value")
return tidy.drop_nulls("value")
  • Values arrive so none fails the read: CSV, XML and JSON as text (nested JSON as JSON), Parquet and Excel as stored. Dicts are typed as JSON values are; pin exact types in columns.

  • exclude_columns and allow_columns apply before the function; columns and mask after.

  • plan runs it on the newest file by name and takes the table’s columns from the result, so keep it free of side effects. Later files may return fewer columns (loaded as NULL); a new column fails, naming it, until columns pins it.

  • A name no function is registered under fails plan, listing the registered ones, as does a name registered twice, naming both files:

    $ sqlload plan
    Errors (1)
    └── raw.metrics
    └── reason transform metrics_rows: no function is registered as metrics_rows with @sl.transform; the registered ones are metric_rows
    ✗ Plan failed 1 error
  • A transform that raises, or returns something else, fails that file and stops the table; earlier commits stay.

  • SQLLoad always reads the files itself. _sqlload_source_row numbers the rows returned.

  • Each file is held in memory while the function runs. After filtering a pandas DataFrame, call reset_index(drop=True).

Each commit records the transform’s version, a hash of the function’s file, in the table’s run log _sqlload_runs. apply or the first load creates it; then a load only inserts, so a role without CREATE can load. After a change, plan warns while the table holds files an earlier version loaded:

$ sqlload plan -v
…
└── transform changed: 2 files loaded under an earlier version (--reload transforms every file again)
…

sqlload load <table> --reload transforms every file again. Changes in imported modules aren’t noticed. A function without a source file, such as one in a notebook, is versioned by its bytecode, so upgrading Python reports it changed.

An sftp connection reads from an SFTP server; see Load files from an SFTP server.

  • path is below the login folder, or absolute when it starts with /. Hidden folders and symbolic links are skipped.
  • The host key must be in known_hosts; otherwise the load fails with the key’s fingerprint and the command that adds it.
  • A file’s version is <size>-<mtime in milliseconds>. SFTP gives times to the second, so a same-size rewrite within one second isn’t noticed.
  • _sqlload_source_file is sftp://host/path, or sftp://user@host/~/path below the login folder. Changing host or user makes append load every file again. The port isn’t part of it, so two SFTP sources loading one table must not name the same host and path from /.
  • Rows always pass through SQLLoad; copy_to_internal_stage is refused. SQLLoad never writes, moves or deletes files on the server.
  • Each table being read uses one SFTP channel. OpenSSH allows 10 per connection (MaxSessions), so keep concurrency at 10 or less for one server.

Where the destination can load the files exactly, it reads them itself and no row passes through SQLLoad: Parquet into DuckDB (S3, a local folder, or GCS with an HMAC key), MotherDuck (S3, or GCS with an HMAC key), ClickHouse (S3) and BigQuery (GCS, when the table excludes _sqlload_source_row), and Parquet, JSON, NDJSON and CSV into Snowflake through an external stage. plan shows each table’s route. See Let the warehouse read the files and Load methods.