Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions changelog.d/ITL-1334.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
### Added

- **Data types per database:** a new reference page,
`docs/reference/database-types.md`, lists every Arrow type
(integers of every width, floats, decimals, dates, times, timestamps of every unit and
zone, durations, text and binary, lists, fixed-size lists, structs, maps, nullability,
every Orcapod logical type and the library value types) for every database (in-memory,
Delta Lake, SQLite, PostgreSQL, SpiralDB): kept, kept through a recorded type, or
refused. It is generated from a test that writes and reads each type through each
database, and that fails if any database gives a column back other than exactly (type
with every nested field's name, nullability and metadata, and values bit for bit)
without an error. (ITL-1334)
- **`DeltaTableDatabase` keeps more types:** `float16` (written as `float32`, which holds
every `float16` exactly), fixed-size lists, also nested and with null rows (written as a
`large_list`; a fixed-size list used to read back as a `large_list`, and with a null row
could not be read back at all), fixed-size binary (read back as `large_binary` before)
every list (its item was renamed `element` and lost its metadata) and every map (it lost
`keys_sorted`), all through the recorded-type mechanism already used for unsigned
integers and nanosecond timestamps.
A restore never pads, cuts or rounds: stored rows that cannot be what was written raise,
naming the column. (ITL-1275, ITL-1283, ITL-1334)

### Changed

- **`DeltaTableDatabase` refuses what Delta cannot hold, naming the column:** a
`decimal256` or an interval column (as Delta's own writer decides), a map whose key or
item field is not named `key` / `value`, and a new column or nested field holding only
nulls with no type, raise `UnstorableColumnError` when added, before anything is
buffered, and a job refuses such a column up front (`require_storable`). They used to
fail the flush with an error that named no column. A `null`-typed value where the table
already stores a type is still kept. (ITL-1334)
- **The SQLite and PostgreSQL connectors read a non-null column back non-null:** the
column is created `NOT NULL`, and a read that projects the table's columns directly now
gives the field that flag; it read back nullable before. Any other query (a join, an
aggregate) reads every column nullable. (ITL-1276)
- **`SQLiteConnector` refuses a `double` column holding a NaN or `-0.0`:** SQLite reads a
NaN back as NULL and `-0.0` as `0.0`. (ITL-1334)
- **`SpiralDBConnector` refuses a logical (extension) type:** `File`, `Directory`,
`Path`, `UPath`, `UUID`, `list[T]` and `set[T]` of them, user classes and the library
value types read back from SpiralDB as their plain storage type (SpiralDB drops the
field metadata that names them). They are refused with `UnstorableColumnError` before
anything is written, as is a map whose key or item field is not named `key` / `value`.
(ITL-1334)

- **An append whose field attributes differ from the held column is refused, by every
database:** a table holds one type per column, so rows appended with other field
metadata (the column's own, or a struct child's, a list item's, a map key's or item's),
another nested field name or another `keys_sorted` than the stored rows or a pending
batch raise `InputValidationError` naming the column and the field, before anything is
buffered. `InMemoryArrowDatabase` used to give the appended rows the first batch's
metadata, the SpiralDB connector gave every row the latest batch's, and Delta kept the
stored metadata, whether or not the column's type was recorded. Nullability is left to
each database's own rule. (ITL-1334)
- **What a `DeltaTableDatabase` flush would refuse is refused when the rows are added:**
before anything is buffered, `add_records` checks the rows against the stored table and
raises `InputValidationError` naming the column and the field. The rows are refused
when they would:
- add a non-nullable struct field (the stored rows have no value for it, and Delta could
not read the table back), or add a struct field inside a map (Delta's merge cannot);
- omit a struct field or a column stored as non-nullable, or hold a null in a column
the stored table, a pending batch or the rows themselves declare non-nullable (with no
table stored yet, such rows used to fail the write of every row queued with them);
- give a column another type than the one the table holds, compared by the rows' own
type, not the form Delta's writer converts it to. So `float16` rows are refused by a
`float32` column, `timestamp[ms]` rows by a `timestamp[us]` one (they read back in
microseconds), and a map's keys are compared even beside `null` items (an `int64` key
was written as text).

The check runs on the rows that are queued: after duplicates are dropped, rows
`skip_duplicates` skips, and the requested `schema_handling`. These rows used to fail the
flush and stay queued, so every later flush failed again. The flush repeats the check
against the version it loads, since another writer may commit in between. Rows it
refuses are dropped from the queue; the error, the log and the note on another batch's
error raised instead all say how many rows of which table were not written. The handle
drops what it had cached of the table. Rows failing for any other reason stay queued. A nested field
an append makes nullable reads back nullable. (ITL-1334)
- **`DeltaTableDatabase` refuses a struct with no fields at any depth:** a Parquet file
stores values in leaf columns only, so the flush failed. (ITL-1334)
- **`SpiralDBConnector` refuses field metadata below a map, and Arrow's canonical extension
types:** its metadata record does not descend into a map, so metadata on a map's key or
item, or inside them, read back dropped. A `uuid` or `json` column (Arrow's own extension
types) read back as its storage type. (ITL-1334)
- **`UnstorableColumnError` suggests only `InMemoryArrowDatabase`:** it suggested
`DeltaTableDatabase` for types Delta refuses too (`decimal256`). The message now points
to `docs/reference/database-types.md` for what each database keeps. (ITL-1334)

### Fixed

- **A fixed-size list with non-null items and a null row can be appended to on Delta:**
the null row's hidden items reached Delta's writer, which panicked; a null row is now
written as an empty list. (ITL-1334)
- **An append to a Delta table that evolves a struct keeps every value under its name:**
Delta's MERGE matches struct fields by position, so rows appended with the fields in
another order stored each value under another field's name. The rows are now given the
stored layout by name first (an omitted field reads as null, an omitted non-nullable
field is refused), and a recorded column's record describes the merged column.
(ITL-1334)

- **A `null`-typed part of a Delta append is written as typed nulls:** a `null` child of a
struct that also gained a field made Delta's MERGE panic. A `null` part needs a type at
its path from either the stored table or a pending batch. (ITL-1334)
- **A Delta append of rows sliced from a larger table writes:** a null list or map row
at a nonzero slice offset failed the flush ("Null bitmap with offsets slice not
supported") and stayed pending; every list and map Delta rebuilds now rebases its
offsets. (ITL-1334)
- **An append that adds a column to a Delta table keeps the other columns' types:** the
MERGE it goes through wrote each list column's field metadata from the rows, without
the recorded type or a logical column's extension name, so afterwards a list read back
with its item named `element`, and a logical list (`set[int]`, `list[Path]`) as its
plain storage type. (ITL-1334)
- **`SpiralDBConnector` reads back a fixed-size list with non-null items and a null row:**
the read cast every column to the restored schema, and pyarrow refuses that cast when a
null row hides null item slots; only columns whose type changes are cast now.
(ITL-1334)
27 changes: 21 additions & 6 deletions docs/concepts/pipeline-job.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,16 @@ Any Orcapod database can hold a job's results. Two are used most:
- **`InMemoryArrowDatabase()`** keeps results for the lifetime of the Python process. Use it
for experiments and tests.
- **`DeltaTableDatabase("some/directory")`** writes [Delta Lake](https://delta.io/) tables
under a directory, and is what makes results survive between sessions.
under a directory, and is what makes results survive between sessions. It keeps every
type Orcapod uses: where Delta has no column type or would change it (an unsigned
integer, a nanosecond timestamp, `float16`, a fixed-size list, a list's item name), the
column's Arrow type is recorded and restored on read. It refuses, naming the column, the
few types Delta cannot hold at all (`decimal256`, an interval), a map whose key or item
field is not named `key` / `value`, and a new column holding only nulls with no type.

No database gives a column back as another type: each keeps a type exactly or refuses it
before anything of the table is written. [Data types per database](../reference/database-types.md)
lists every type for every database.

On disk the layout is `<directory>/<job name>/<function name>/...` for each function, plus
`<directory>/<job name>/_result/...`. The job's `name` is the top level, so jobs with
Expand All @@ -134,11 +143,17 @@ and binary columns come back as `large_string` and `large_binary`, the types Orc
| `SQLiteConnector` | `bool`, `int64`, `double`, `large_string`, `large_binary` |
| `PostgreSQLConnector` | `bool`, `int32`, `int64`, `float`, `double`, `large_string`, `large_binary`, `date32`, `timestamp[us]`, `timestamp[us, tz=UTC]` |

Any other type (lists, structs, dates or timestamps on SQLite, narrower integers and floats,
logical types) is refused. PostgreSQL also refuses a column name or a table name longer than
A non-null column is created `NOT NULL` and reads back non-null. SQLite refuses a
`double` column holding a NaN or `-0.0`, which it would read back as NULL and `0.0`. Any
other type (lists,
structs, dates or timestamps on SQLite, narrower integers and floats, logical types) is
refused. PostgreSQL also refuses a column name or a table name longer than
63 bytes, which it would truncate (`UnstorableTableNameError` for a table). `SpiralDBConnector` stores other types as written, except a
timestamp with a time zone (SpiralDB drops the zone), and SpiralDB reserves the `__` prefix on
value columns (the `__record_id` key is allowed) and `.` in any column name.
timestamp with a time zone (SpiralDB drops the zone), a logical (extension) type such as
`File`, `Path`, `UUID`, a user class or `set[int]` (SpiralDB drops the field metadata that
names it), and a null struct; SpiralDB reserves the `__` prefix on
value columns (the `__record_id` key is allowed) and `.` in any column name. The full list,
type by type, is [Data types per database](../reference/database-types.md).

Orcapod's own stored tables hold such columns. A function node's result table holds
list-valued executor columns and `__`-prefixed columns. A side-effect node's log holds a UTC
Expand Down Expand Up @@ -171,7 +186,7 @@ try:
compute_bmi.pod(mice(cohort_a), label="bmi")
except UnstorableColumnError as exc:
print(exc)
# node 'bmi': a SQLiteConnector database cannot store column '__pf_exec_executor_info' of Arrow type large_list<...>: SQLite has no column type for it. Use an InMemoryArrowDatabase or a DeltaTableDatabase instead.
# node 'bmi': a SQLiteConnector database cannot store column '__pf_exec_executor_info' of Arrow type large_list<...>: SQLite has no column type for it. Use an InMemoryArrowDatabase instead; docs/reference/database-types.md lists what each database keeps.
```

## What a re-run computes
Expand Down
Loading
Loading