Reference
The dataset transform spec
One small YAML or JSON document that says how a stream of JSON records becomes exactly one columnar table: which fields to select, what type each becomes, which transform runs on the way, what to do when the source drifts, and where the table lands. You write it once per source shape; the engine shapes unbounded rows under it.
Follows docs/SPEC.md
and the spec model in shapeshift-core/src/spec.rs and drift.rs at 0.4.0.
0.5 adds a where: row filter, which is not on this page yet: see the
changelog.
Format and loading
- YAML or JSON. A document whose first non-whitespace byte is
{is read as JSON, anything else as YAML. YAML is the canonical form;inferwrites YAML. - Unknown keys are refused. A misspelled key (
colums:) fails the load, naming the key and the valid names, rather than running on inference and reporting success. - Validated before any input is read (see Validation errors).
shape -s spec.yamlconsumes a spec;shapewithout-sinfers one on the fly;inferprints one to edit.
Skeleton
dataset: <name> # required, non-empty source: format: jsonl | json-array # default jsonl path: <input path> # optional; -i overrides; - is stdin output: # required format: parquet | iceberg # required path: <file, directory, table or URL> # required compression: snappy | zstd | uncompressed # default snappy partition_by: [<col> | <transform(col)>, ...] # default []; Iceberg merge_on: [<col>, ...] # default []; Iceberg upsert keys schema: infer | strict # default infer columns: # default [] - name: <col> from: <path> # default = name type: <logical type> # required transform: <named transform> # optional required: <bool> # default false drift: policy: ignore | warn | rescue | quarantine | error # default warn rescue_column: <col> # default _rescued max_examples: <int> # default 3 options: flatten: <bool> # default true row_group_rows: <int> # default 50000 infer_sample: <int> # default 1000; 0 = whole input
Top level
| key | type | default | meaning |
|---|---|---|---|
dataset | string | required | Table name. Must not be empty. The Parquet file stem when output.path is a directory; the Iceberg table's name. |
source | map | {format: jsonl} | How to read the input (below). |
output | map | required | How and where to write (below). |
schema | infer | strict | infer | infer lets undeclared fields ride along; strict writes only declared columns (Schema modes). |
columns | list | [] | Column declarations (below). In infer mode they refine the inferred schema; in strict mode they are the schema. |
drift | map | {policy: warn} | What a run does when the source outgrows the schema (Schema drift). |
options | map | defaults | Dataset-wide options (below). |
source
| key | type | default | meaning |
|---|---|---|---|
format | jsonl | json-array | jsonl | jsonl: one object per line, streamed a line at a time; blank lines skipped. json-array: one top-level array, streamed an element at a time; a bad element is a per-record reject carrying its 1-based element index, and a structural problem (not an array, truncated, trailing garbage) is reported once. |
path | string | none | Input path. -i overrides it. - is standard input; the source is read once, so a pipe shapes exactly what a file would. |
output
| key | type | default | meaning |
|---|---|---|---|
format | parquet | iceberg | required | parquet: one file. iceberg: a self-contained Iceberg v2 table, one snapshot per run. |
path | string | required | Parquet: a file, or a directory (then <path>/<dataset>.parquet). Iceberg: the table root, created if absent. With the object_store feature, an s3://, gs://, az:// or file:// URL. |
compression | snappy | zstd | uncompressed | snappy | Parquet page codec, for data files of either format. zstd needs a build with the zstd feature; the default binary returns a clear error. |
partition_by | list of string | [] | Iceberg partition fields: a column (identity) or a hidden transform (Partitioning). Ignored for Parquet, which is always one file. |
merge_on | list of string | [] | Iceberg only. Upsert on these key columns instead of appending (Merge keys). |
columns[]
| key | type | default | meaning |
|---|---|---|---|
name | string | required | Output column name; unique within the spec. |
from | string | = name | Source path into each record (Path selection). |
type | logical type | required | One of bool, int64, float64, string, date, timestamp, json (Types). |
transform | name | none | A value rewrite applied before coercion (Transforms). |
required | bool | false | A missing or null value rejects the row (lenient) or aborts the run (strict); otherwise it is written as null. Also makes the Arrow field non-nullable. |
options
| key | type | default | meaning |
|---|---|---|---|
flatten | bool | true | Inference only. Nested objects become dotted columns and arrays become json leaves. Off: each top-level nested object becomes one json column. Declared columns are never affected. |
row_group_rows | int | 50000 | Rows buffered before a batch is flushed as one Parquet row group. This is what bounds memory: a run never holds more than this many rows. Values below 1 are read as 1. |
infer_sample | int | 1000 | Records sampled for inference; 0 scans the whole input. |
Logical types
A closed set. Each maps onto Arrow, and from there onto Parquet and the Iceberg type system.
type: | Arrow | Iceberg | notes |
|---|---|---|---|
bool | Boolean | boolean | JSON true/false only. |
int64 | Int64 | long | 64-bit signed. |
float64 | Float64 | double | IEEE-754 double. |
string | Utf8 | string | Scalars stringify; arrays and objects do not (use json). |
date | Date32 | date | Days since 1970-01-01, no zone. |
timestamp | Timestamp(µs, no zone) | timestamp | Microseconds since the epoch, zone-less: Iceberg timestamp, not timestamptz. |
json | Utf8 | string | Any value kept as compact JSON text. Never fails coercion. |
Coercion
Coercion runs after the transform, on the selected value, toward the column's type. A missing
path or a JSON null is null and never reaches coercion; what happens to it
is the reject policy. A value that is present but cannot be represented is
a coercion failure.
| target | accepts | result, or failure |
|---|---|---|
bool | JSON bool | Anything else fails. |
int64 | number; numeric string | An integer, or an integral finite float (10.0). 10.5 fails. "42" parses; a non-integer string fails. |
float64 | number; numeric string | "3.14" parses; a non-numeric string fails. |
string | string, bool, number | Strings as-is; true → "true"; a number → its JSON text. Arrays and objects fail. |
date | date string; integer | YYYY-MM-DD, or the date part of an RFC3339 string. A bare integer is epoch days. |
timestamp | timestamp string; integer | RFC3339 with an offset (applied to reach UTC, then dropped), or zone-less YYYY-MM-DDThh:mm:ss[.fff] read as UTC. A bare integer is epoch milliseconds. |
json | anything | A string as-is; any other value as compact JSON. Never fails. |
Integer dates are days and integer timestamps are milliseconds, deliberately: those are the units common JSON uses for each.
Transforms
A pure value-to-value rewrite applied before coercion. Every transform is total: a value of a type it does not apply to passes through unchanged, and a genuine mismatch surfaces later, in coercion. Parsing dates and times is not a transform; the target type drives it.
transform: | effect | example |
|---|---|---|
lowercase | Lowercase a string. | "PRO" → "pro"; 42 → 42 |
uppercase | Uppercase a string. | "pro" → "PRO" |
trim | Trim surrounding whitespace. | " ada " → "ada" |
json_encode | A composite value to compact JSON text; a string is left as-is. | {"a":1} → "{\"a\":1}" |
to_string | Stringify a scalar; null stays null; composites to JSON text. | 42 → "42"; true → "true" |
dollars_to_cents | Multiply by 100 and round to the nearest integer. | 12.50 → 1250; -4.2 → -420 |
abs | Absolute value; ints stay ints, floats stay floats. | -3.5 → 3.5 |
empty_to_null | An empty string becomes null, so required can fire. | "" → null |
Path selection (from)
- Dotted descent into objects:
user.name,geo.region. - An optional leading
$or$.:$.user.nameisuser.name. $alone selects the whole record; withtype: jsonit keeps the entire object as one column.- A numeric segment indexes an array:
tags.0,items.2.sku. - A path that does not resolve (a missing key, an index out of range, a segment applied to a scalar) is null, never an error.
Schema modes
infer (the default) infers columns from a sample and lets undeclared fields
ride along. Declared columns win over inferred ones of the same name and keep their position;
the rest follow in first-seen order. Coercion is lenient.
strict writes only the declared columns, run after run: the contract mode.
It needs at least one column. Coercion is strict.
Reject policy
Every cell of a row is computed and checked before any of it is appended, so a rejected row never leaves the columns misaligned.
| column | lenient: missing / null | lenient: uncoercible | strict: missing / null | strict: uncoercible |
|---|---|---|---|---|
| optional | null | null | null | run aborts |
required: true | row rejected | row rejected | run aborts | run aborts |
A source line that is not JSON never aborts a run, in either mode. It is counted as a
parse_error and written to <output>.rejects.jsonl as
{"line", "error", "raw"}. Rows rejected by the lenient policy are counted as
rejected.
Schema drift
Sources move after the spec is written. Two movements used to pass silently: a field the spec
has no column for (its values are never selected) and a value that stopped coercing in an
optional column (written as null). Neither shows in rows_in, rows_out
or rejected. shapeshift detects both per record and reports them.
drift.policy | what the run writes | when |
|---|---|---|
ignore | Exactly the 0.1 behaviour: no detection, no per-record work. | You measured that you need the last few percent. |
warn (default) | Every row, unchanged, plus the report. | You want to know, and keep loading. |
rescue | Every row, plus a json column (rescue_column, default _rescued) holding what the schema would have dropped; null on rows that did not drift. Appended after every declared column, so enabling it is an additive Iceberg schema change. | You cannot lose data while the spec catches up. |
quarantine | Only rows exactly on the schema; drifted rows go to the reject sidecar. | Downstream must never see a partial row. |
error | Nothing: the run fails at the first drift and never finalizes its output. | A contract table: no new data beats quietly different data. |
max_examples(default 3) bounds the example values kept per drifted path; counts are exact regardless.- The report goes to
<output>.drift.jsonwhen something drifted, with every path, its count, the record it first appeared in, examples, and the type inference would give it, so the suggestedcolumns:block is paste-ready. - Detection tracks at most 1,000 distinct paths per run, then marks the report
truncated. - A column merely absent from a record is not drift: that loss is already visible as a null.
- A run that fails under
errorleaves no half-written output: the Parquet file has no footer, and an Iceberg table keeps its previous metadata. Bytes flushed before the failure remain on disk, unreferenced. --on-driftand--rescue-columnoverride the spec for one run.
Measured cost of the default (BENCHMARKS.md §7, glibc release build, 1M rows,
median of 6): about 6% of wall time on a run that has not drifted, with peak RSS unchanged;
1.47× when every row drifts, and 2.44× under rescue.
Partitioning
partition_by entries are a column name (identity) or one of the Iceberg hidden
transforms. Rows fan out to one data file per transformed value, under Hive-style directories.
Temporal values are written readably: data/event_at_day=2026-07-11/.
| entry | source types | partition value |
|---|---|---|
col | any | The value itself (identity). |
bucket(N, col) | int64, string, date, timestamp | Murmur3 bucket per the Iceberg spec, 0..N-1. |
truncate(W, col) | int64, string | Integers floored to a multiple of W; strings cut to W code points. |
year(col), month(col), day(col) | date, timestamp | Years, months or days since 1970. |
hour(col) | timestamp | Hours since 1970-01-01T00. |
- When columns are declared, every partition source column must be among them, so it has a stable field-id. In
infermode it is resolved against the inferred schema at write time. - A partitioned table needs at least one row: a zero-row input has no partition to write and is refused.
- An
--appendor merge must use the table's existing partition spec, transform included.
Merge keys (merge_on)
- Each written row replaces any live row with the same key (every key column equal). A key the input carries twice keeps its last occurrence.
- A row with a null in any key column is appended and matches nothing, as in SQL
MERGE. - Key columns may be
int64,string,json,date,timestamporbool.float64is refused: a float is not a reliable key. - The merge creates the table if there is none, and accepts the same additive schema changes as an append.
- Iceberg only, local or object-store.
--merge-onoverrides it; how it works is on Iceberg tables.
Validation errors
Checked on load, after the document's shape (a missing dataset,
output, output.format, output.path or column
type fails first).
| condition | message |
|---|---|
empty dataset | `dataset` must not be empty |
strict with no columns | strict schema mode requires at least one declared column |
| two columns share a name | duplicate column name `<name>` |
| partition column not declared | partition column `<name>` is not a declared column (declare it to partition by it) |
merge_on with Parquet | `output.merge_on` applies only to Iceberg tables (`format: iceberg`) |
| a key named twice | `output.merge_on` names `<name>` twice |
| key not declared (strict) | merge key `<name>` is not a declared column (declare it to merge on it) |
Inference
Inference samples the first infer_sample records and proposes one optional column
per path, with no transform. It only ever widens, so a strict spec derived from an inferred one
is safe. Per path, ignoring nulls:
- Any array or object seen →
json. - Two or more scalar kinds (bool, number, string) →
string. - All strings, every one RFC3339 with a time →
timestamp; every one exactlyYYYY-MM-DD→date; otherwisestring. - Numbers with any float →
float64; all integers →int64. - All bools →
bool. Only nulls seen →string.
Column order is first-seen. A sample that yields no columns (all scalar lines, or empty) with nothing declared is an error.
Spec and command-line flags
The spec is the durable artifact; shape's flags override it for one run without
editing the file.
| flag | overrides |
|---|---|
-i, --input | source.path |
-o, --output | output.path |
--to | output.format |
--compression | output.compression |
--partition-by | output.partition_by |
--merge-on | output.merge_on |
--on-drift, --rescue-column | drift.policy, drift.rescue_column |
--format and --dataset apply when there is no spec. Flags that change
only how a run reports (--summary-json) have no spec field.
Examples
dataset: events output: format: parquet path: ./out/events.parquet
dataset: orders output: format: iceberg path: ./warehouse/orders partition_by: [region] schema: infer # the pinned columns win; other fields ride along columns: - { name: order_id, from: id, type: int64, required: true } - { name: region, from: geo.region, type: string, transform: lowercase } - { name: total_cents, from: total, type: int64, transform: dollars_to_cents } - { name: payload, from: $, type: json }
dataset: orders output: format: iceberg path: s3://warehouse/db/orders # needs the object_store feature merge_on: [id] drift: policy: rescue
The strict billing spec is walked through in the Quickstart.