Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a7ebd91
fix(databases): every database matches an appended table's columns by…
Nov 22, 2026
42843d4
wip(databases): canonical order for a new table (ITL-1370)
Nov 22, 2026
a4d3cc0
fix(databases): append-by-name keeps main's Delta commit choice and m…
Nov 22, 2026
88efe5b
Merge branch 'eywalker/itl-1367-databases-refuse-an-append-whose-colu…
Nov 22, 2026
0b268cb
wip(ITL-1370): readers present row order; canonical order tests
Nov 22, 2026
e8751e4
fix(databases): append-by-name trusts nothing stored across calls and…
Nov 22, 2026
dbb2d1c
wip(ITL-1370): rule text, docs, tests for readers, loaded jobs and ob…
Nov 22, 2026
50dc02e
refactor(databases): append-by-name does the minimum: Delta aligns to…
Nov 22, 2026
b8bf9dc
wip(ITL-1370): stored data-tags compared as sets; doc pages show the …
Nov 22, 2026
c17236c
fix(databases): a column is reordered only if every type in its tree …
Nov 22, 2026
e4c5b25
Merge commit 'c17236c8' into eywalker/itl-1370-a-new-stored-table-is-…
Nov 22, 2026
5ac28f2
fix(databases): a read combining stored and queued rows reconciles nu…
Nov 22, 2026
a69b471
wip(ITL-1370): Delta stats property in canonical order; commit-count …
Nov 22, 2026
4f45979
Merge commit '5ac28f2d' into eywalker/itl-1370-a-new-stored-table-is-…
Nov 22, 2026
fb9ddf0
docs(ITL-1370): Delta queues canonical with nothing pending; the merg…
Nov 22, 2026
f4011e2
test(ITL-1370): typed read of a tag column
Nov 22, 2026
f47067d
test(ITL-1370): result-table and PostgreSQL tests expect the canonica…
Nov 23, 2026
b885a6c
fix(ITL-1370): keep main's Delta commit for non-canonical tables, cac…
Nov 23, 2026
e50c514
Merge remote-tracking branch 'origin/main' into eywalker/itl-1370-a-n…
Nov 23, 2026
3d97690
fix(ITL-1370): import the database utils module directly (no import c…
Nov 23, 2026
c215a93
Merge remote-tracking branch 'origin/main' into eywalker/itl-1370-a-n…
Nov 23, 2026
b39b52b
test(ITL-1367, ITL-1370): every review finding has a regression test
Nov 23, 2026
ccfc3ef
fix(databases): an extension type's storage field metadata counts in …
Nov 23, 2026
45210a3
revert(databases): storage field metadata of an extension stays uncom…
Nov 23, 2026
455dd06
chore(databases): merge main into canonical column order PR
eywalker Nov 24, 2026
5ba91f9
fix(databases): report Delta user column collisions first
eywalker Nov 24, 2026
343fbc7
fix(databases): preserve reader layouts in fallback cases
eywalker Nov 24, 2026
529c3a6
Merge origin/main into the ITL-1370 branch
eywalker Nov 24, 2026
26e76af
chore(databases): merge main into canonical column order PR
eywalker Nov 26, 2026
317ff8b
docs(databases): clarify canonical stored order exceptions
eywalker Nov 27, 2026
3ec252e
chore(databases): merge main into canonical column order PR
eywalker Nov 27, 2026
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
30 changes: 26 additions & 4 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,27 @@ generation of hashing; rows of the current data context are the current entries.
Operator cache — odb_v2 (OPERATOR_DB_SCHEMA_VERSION)
Cached source — sdb_v1 (SOURCE_DB_SCHEMA_VERSION)

- Stored column order (ITL-1367 and ITL-1370). A new table is written with the record id
first and every other column in ascending code-point order through the shared
`databases/utils.canonical_column_order` helper. SpiralDB uses the same order.
An existing table keeps its order. A new table keeps its entire first-write order if
any column has a type at any depth that the append comparison cannot handle
(dictionary-encoded, view, list view, union, interval, or run-end-encoded), a column
name repeats, or the record id column is absent. Matching a later append by name
requires the comparison to confirm every field. Reordering even part of such a table
could leave the writer's own next append unmatched. ITL-1529 tracks the follow-up.
Delta normalizes view types before queueing, matches batches to the queued rows by
column name, and uses a conflict-safe MERGE with retry
for every commit to an existing table (ITL-1377). A connector database trusts nothing about a stored
table across calls: it aligns incoming rows only with its own pending batch and checks rows
against the table read at flush and at a read. No hash, record id, path or layout version follows a stored column order, and no
table is rewritten. Every reader of stored rows presents them in its own layout,
whatever order they are stored in, through one helper, `arrow_utils.in_presented_order`
(the reader's layout, then any other column by name): `CachedSource`, `DerivedSource`,
the function node's stored view (`_presented_layout`), the operator node's stored read
(`_in_row_order_on_read`), the result cache (`result_table_layout`), the status and log
observers and `ObservabilityReader`. A new reader of stored rows uses it too; never
present a stored table in its stored order.
- The layout version is the last component of a table path. Every layout marker started at v1
for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn).
The pipeline, side-effect log and operator cache layouts moved to v2 before that release,
Expand Down Expand Up @@ -1302,10 +1323,11 @@ data. The rules:
order, user tags, system tags, data, source info, stated once in
StaticOutputOperatorPod._in_row_order; a node that keeps a run with no rows keeps
_zero_rows_in_row_order, and an operator's own empty result built from its input
goes through _as_row_built_table. An operator node keeps and stores the row order on every
path (_kept_output: a job run, sync or async, and node.run() on its own; ITL-1133),
and reads a stored operator cache in row order (_in_row_order_on_read). Never change
the order of any other populated table: stored tables depend on it.
goes through _as_row_built_table. An operator node keeps the row order on every path
(_kept_output: a job run, sync or async, and node.run() on its own; ITL-1133); what it
stores is in its database's order and is presented in row order on read
(_in_row_order_on_read; "Stored column order"). Never change the order of any other
populated table a user sees: presentation follows it (no hash and no stored table does).
- Data-tags come first among the data columns (developer, November 17, 2026, ITL-1205):
a stream lists its data-tags first in its data keys and data schema, in tag order, then
its other data columns in table order. A table built from rows lays a data-tag out among
Expand Down
30 changes: 26 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,27 @@ current data context are the current entries.
| Operator cache | `odb_v2` | `OPERATOR_DB_SCHEMA_VERSION` |
| Cached source | `sdb_v1` | `SOURCE_DB_SCHEMA_VERSION` |

- Stored column order (ITL-1367 and ITL-1370). A new table is written with the record id
first and every other column in ascending code-point order through the shared
`databases/utils.canonical_column_order` helper. SpiralDB uses the same order.
An existing table keeps its order. A new table keeps its entire first-write order if
any column has a type at any depth that the append comparison cannot handle
(dictionary-encoded, view, list view, union, interval, or run-end-encoded), a column
name repeats, or the record id column is absent. Matching a later append by name
requires the comparison to confirm every field. Reordering even part of such a table
could leave the writer's own next append unmatched. ITL-1529 tracks the follow-up.
Delta normalizes view types before queueing, matches batches to the queued rows by
column name, and uses a conflict-safe MERGE with retry
for every commit to an existing table (ITL-1377). A connector database trusts nothing about a stored
table across calls: it aligns incoming rows only with its own pending batch and checks rows
against the table read at flush and at a read. No hash, record id, path or layout version follows a stored column order, and no
table is rewritten. Every reader of stored rows presents them in its own layout,
whatever order they are stored in, through one helper, `arrow_utils.in_presented_order`
(the reader's layout, then any other column by name): `CachedSource`, `DerivedSource`,
the function node's stored view (`_presented_layout`), the operator node's stored read
(`_in_row_order_on_read`), the result cache (`result_table_layout`), the status and log
observers and `ObservabilityReader`. A new reader of stored rows uses it too; never
present a stored table in its stored order.
- Every layout marker started at `v1` for the first release, 0.4.0 (developer, November 18,
2026, ITL-1259; 0.3.0 was withdrawn). The pipeline, side-effect log and operator cache
layouts moved to `v2` before that release, with the three row ids (developer, November 25,
Expand Down Expand Up @@ -1350,10 +1371,11 @@ data. The rules:
order, user tags, system tags, data, source info, stated once in
`StaticOutputOperatorPod._in_row_order`; a node that keeps a run with no rows keeps
`_zero_rows_in_row_order`, and an operator's own empty result built from its input
goes through `_as_row_built_table`. An operator node keeps and stores the row order on every
path (`_kept_output`: a job run, sync or async, and `node.run()` on its own; ITL-1133),
and reads a stored operator cache in row order (`_in_row_order_on_read`). Never change
the order of any other populated table: stored tables depend on it.
goes through `_as_row_built_table`. An operator node keeps the row order on every path
(`_kept_output`: a job run, sync or async, and `node.run()` on its own; ITL-1133); what it
stores is in its database's order and is presented in row order on read
(`_in_row_order_on_read`; "Stored column order"). Never change the order of any other
populated table a user sees: presentation follows it (no hash and no stored table does).
- **Data-tags come first among the data columns** (developer, November 17, 2026, ITL-1205):
a stream lists its data-tags first in its data keys and data schema, in tag order, then
its other data columns in table order. A table built from rows lays a data-tag out among
Expand Down
34 changes: 34 additions & 0 deletions changelog.d/ITL-1370.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Changed

- **New stored tables use a canonical column order by default.** Orcapod writes the
record id column first and sorts every other column by name in code-point order. This
applies to a function node's pipeline and result tables, a side-effect log, an operator
cache, a cached source, and an observer's status and log tables. Tables used to keep
the order of the first write, which depended on how it was built. The canonical order is the
order SpiralDB already uses for tables with a single record-id key. The change affects
databases Orcapod can write.
- Reading a database directly (`database.get_all_records(path)`, a Delta table opened with
Polars or `deltalake`, a SQL `SELECT *`) shows the table's stored column order.
- A table stored before this change keeps its order and takes new rows in any order; a
store may hold both kinds side by side.
- What Orcapod shows of stored rows no longer follows the stored order at all: a job
node's `get_all_records()`, its stored view after a load, `as_source()`, a
`CachedSource`, `get_all_cached_outputs()`, `StatusObserver.get_status()`,
`LoggingObserver.get_logs()` and `ObservabilityReader` each present the columns in their
own layout (for a node: tags, system tags, data, source info), then any other column by
name. Two changes are visible: in a function node's `get_all_records(all_info=True)` the
bookkeeping columns (`__…`) and the input's source-info columns now follow the outputs,
by name; in an observer's tables the tag columns follow the observer's own columns by
name.
- Delta now matches a batch to queued rows by column name. It previously refused a
batch in another column order. Delta commits to an existing table with a
conflict-safe MERGE with retry.
- A new table keeps its entire first-write order if any column at any depth has a
type the append comparison cannot handle (a dictionary-encoded type, a view type,
a list view, a union, an interval, or a run-end-encoded type), a column name repeats,
or the record id column is absent. Matching a later append by name requires the
comparison to confirm every field. Reordering even part of such a table could leave
the writer's own next append unmatched. Delta normalizes view types before checking
the schema. ITL-1529 tracks the follow-up.
- No hash, record id, stored path or layout version changes, and nothing stored is
rewritten. (ITL-1370)
4 changes: 2 additions & 2 deletions docs/concepts/data-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ pipeline_table = next(
for path in database.list_table_paths()
if "_result" not in path
)
print(stored_data_tags(pipeline_table.schema))
# ('unit', 'time')
print(sorted(stored_data_tags(pipeline_table.schema)))
# ['time', 'unit']
```

A node reads the binding back from its table, and refuses a table whose marker disagrees
Expand Down
5 changes: 2 additions & 3 deletions docs/dev/design_issues/ITL-1367-CO1.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ not over a Delta column with no identifier and no recorded Arrow type, such as o
from a dictionary of extension values, where the identity rule abstains; ITL-1372).

Not covered: the order of a struct's fields (a struct with its fields in another order is
another type here, and the fake keeps struct children as written): ITL-1368. A canonical
order for a new table is a proposal awaiting the developer's decision:
`docs/dev/specs/itl-1367-stored-column-order.md`.
another type here, and the fake keeps struct children as written): ITL-1368. ITL-1370 (CO2)
sets the [default order for new tables and its exception](../specs/itl-1367-stored-column-order.md#the-approved-order).
29 changes: 29 additions & 0 deletions docs/dev/design_issues/ITL-1370-CO2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## `src/orcapod/databases/` — column order of appended tables

### CO2 — A stored table's column order followed whichever write created it
**Status:** resolved
**Severity:** low
**Issue:** ITL-1370

Each stored table kept the column order of its first write, and each writer built its rows
its own way: the five table kinds disagreed (a cached source put data before its system
tags, an operator cache after them), the user columns followed the declared tag order,
which the rule that order never counts allows only as presentation, and SpiralDB stored
none of these orders (it keeps the key columns, then the value columns by name). Readers
presented a stored table in its stored order, so what a user saw depended on how the
table's first write happened to be built.

**Fix:** by default, a new table is written in the canonical order: the record id, then every other
column by name (code point), by the shared step every database calls
(`databases/utils.canonical_column_order`, from `in_held_column_order` when nothing is
held). It is SpiralDB's own order. The [approved order and its exception](../specs/itl-1367-stored-column-order.md#the-approved-order)
are in the spec. A table that exists keeps its order and takes appends
by name (CO1, ITL-1367). Every reader of stored rows presents them in its own layout through
one helper, `arrow_utils.in_presented_order`: `CachedSource`, `DerivedSource`, the function
node's stored view (`_presented_layout`), the operator node's stored read, the result cache
(`result_table_layout`), the status and log observers and `ObservabilityReader`. No hash,
record id, stored path or layout version moves (golden check; and
`tests/test_databases/test_canonical_stored_order.py` runs one job writing every table
kind with the canonical order switched off and on and compares content and pipeline
hashes, paths, record ids and every reader). Decision and evidence:
`docs/dev/specs/itl-1367-stored-column-order.md`.
94 changes: 94 additions & 0 deletions docs/dev/scripts/itl_1370_delta_commits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"""ITL-1370: the Delta commits of a job, by table kind: operation kinds and counts.

One job writes every stored table kind (a function pipeline and result table, a
side-effect log, an operator cache, a cached source) on a new Delta store, three times:
the first run, a second run with new rows, and a run with ``commit_every_rows=2`` over
more rows. Each table's history is printed oldest first. Run it on main and on the
ITL-1370 branch: a job on new tables must commit the same kinds the same number of
times (condition (a) of the ITL-1370 review).

Run: ``PYTHONPATH=src uv run python docs/dev/scripts/itl_1370_delta_commits.py``
"""

from __future__ import annotations

import os
import sys
import tempfile
import warnings
from pathlib import Path
from typing import Any

import deltalake
import pyarrow as pa

from orcapod import PipelineJob, function_pod
from orcapod.core.operators import Join
from orcapod.core.sources import ArrowTableSource
from orcapod.core.sources.cached_source import CachedSource
from orcapod.databases import DeltaTableDatabase
from orcapod.side_effects import SideEffectPod
from orcapod.types import CacheMode

warnings.simplefilter("ignore")


def _source(name: str, data: list[str], rows: list[int]) -> ArrowTableSource:
fields = [
pa.field("z_tag", pa.large_string(), nullable=False),
pa.field("a_tag", pa.int64(), nullable=False),
*(pa.field(n, pa.float64(), nullable=False) for n in data),
]
arrays = [
pa.array([f"s{n}" for n in rows], pa.large_string()),
pa.array(rows, pa.int64()),
*(pa.array([float(n) for n in rows]) for _ in data),
]
return ArrowTableSource(
pa.Table.from_arrays(arrays, schema=pa.schema(fields)),
tag_columns=["z_tag", "a_tag"],
tag_only_columns=True,
record_id_columns=["a_tag"],
source_id=name,
)


@function_pod(output_keys=["w_out", "c_out"])
def compute(y: float, b: float) -> tuple[float, float]:
return y + b, y - b


def _notify(ctx: Any, y: float, b: float) -> None:
return None


def _run(database: Any, rows: list[int], **run: Any) -> None:
job = PipelineJob(name="commits", database=database)
cached = CachedSource(_source("left", ["y", "b"], rows), cache_database=database)
with job:
compute.pod(cached, label="fn")
Join()(cached, _source("right", ["x", "e"], rows), label="joined")
SideEffectPod(_notify)(cached, label="notify")
job.nodes["joined"].attach_databases(
pipeline_database=database, cache_mode=CacheMode.LOG
)
job.run(**run)


def main() -> None:
root = Path(tempfile.mkdtemp())
database = DeltaTableDatabase(root)
_run(database, [1, 2])
_run(database, [1, 2, 3, 4])
_run(database, list(range(1, 10)), commit_every_rows=2)
for log in sorted(root.rglob("_delta_log")):
table = log.parent
history = deltalake.DeltaTable(str(table)).history()
operations = [str(entry["operation"]) for entry in reversed(history)]
print(table.name, operations)


if __name__ == "__main__":
main()
sys.stdout.flush()
os._exit(0)
Loading
Loading