Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3840e1e
feat(logical-types)!: declare value hashes in extension metadata
eywalker Nov 29, 2026
245ffd8
docs(hashing): explain logical type value hash declarations
eywalker Nov 29, 2026
cf01448
test(logical-types): update identifier pins and label feeds
eywalker Nov 29, 2026
8445f4c
test(database): check complete logical identifiers on append
eywalker Nov 29, 2026
7c35ad1
feat(hashing): enforce logical type value hash declarations
eywalker Nov 29, 2026
a0de5dd
fix(logical-types): clarify value hash migration failures
eywalker Nov 29, 2026
3b16802
test(hashing): verify value hash enforcement through public streams
eywalker Nov 29, 2026
6c731f7
chore(hashing): merge updated part 1 into enforcement branch
eywalker Nov 29, 2026
709d27a
Merge remote-tracking branch 'origin/main' into eywalker/itl-980-part…
eywalker Nov 29, 2026
fac757d
fix(hashing): check stored-form fields for handler conflicts
eywalker Nov 29, 2026
04ace2f
test(contexts): declare the directory verification fixture label
eywalker Nov 29, 2026
c2930a0
test(delta): declare the nested output fixture value hash
eywalker Nov 29, 2026
1e0096b
fix(logical-types): validate hash labels before caching families
eywalker Nov 29, 2026
e297ba2
fix(logical-types): keep registration regression warning-free
eywalker Nov 29, 2026
ff45353
Merge commit 'e297ba25' into eywalker/itl-980-part-2-value-hash-enfor…
eywalker Nov 29, 2026
baaae21
Merge commit '1fb2a7f7' into eywalker/itl-980-logical-type-declares-v…
eywalker Nov 29, 2026
389e7c4
test(delta): declare the nested output fixture value hash
eywalker Nov 29, 2026
19f1172
Merge commit '389e7c4a' into eywalker/itl-980-part-2-value-hash-enfor…
eywalker Nov 29, 2026
f2be043
test(golden): regenerate the approved ITL-980 entries
eywalker Nov 29, 2026
e2147f4
fix(hashing): enforce logical value hash declarations on resolution
eywalker Nov 29, 2026
c172ef3
Merge remote-tracking branch 'origin/eywalker/itl-980-logical-type-de…
eywalker Nov 29, 2026
25dfc8b
fix(hashing): keep column names on nested value hash errors
eywalker Nov 29, 2026
2ecc564
fix(hashing): annotate nested error field paths
eywalker Nov 29, 2026
dcbbaa7
fix(logical-types): validate native container element declarations
eywalker Nov 29, 2026
8e4c978
fix(hashing): merge main and locate nested value hash mismatches
eywalker Nov 29, 2026
39c86f4
fix(hashing): type returned value hash label mismatches
eywalker Nov 29, 2026
7faa400
fix(contexts): validate inline logical type registries
eywalker Nov 29, 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
10 changes: 7 additions & 3 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,13 @@ algorithm produced it.**
identity needs a dedicated algorithm: external content (`File`, `Directory`) or a library
value's canonical form (arrays, tensors, pandas, Polars, Arrow tables, Polars
expressions). `frozenset` is its own type (`{"__type__": "frozenset", ...}`), never `set`.
- Column value handlers: a logical type's column is hashed through a value handler only when
its stored form is not its identity. A handler that hashes bare values only declares
`COLUMN_VALUE_HANDLER = False` (`UUIDHandler`: a UUID column is hashed as stored).
- Column value handlers: the column identifier's `value_hash` selects the algorithm.
`stored` hashes the stored representation, and native containers follow their innermost
element. A column handler exposes `HASH_LABEL` and returns a `ContentHash` with that label.
Configured handlers are checked when the context or deferred type loads, and runtime
registrations are checked when the column is hashed. A missing or mismatched handler,
a column handler registered for a `stored` type, or a labelled column in Arrow storage
form raises `ValueHashMismatchError`. The bare UUID handler has no column hash label.
- Grammar restrictions the encodings rest on: no label contains `:`; the registry refuses `;`
in an extension name; extension metadata enters the identifier text as hex
(`tests/test_hashing/test_hash_grammar.py`).
Expand Down
10 changes: 7 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,13 @@ algorithm produced it.**
identity needs a dedicated algorithm: external content (`File`, `Directory`) or a library
value's canonical form (arrays, tensors, pandas, Polars, Arrow tables, Polars
expressions). `frozenset` is its own type (`{"__type__": "frozenset", ...}`), never `set`.
- Column value handlers: a logical type's column is hashed through a value handler only when
its stored form is not its identity. A handler that hashes bare values only declares
`COLUMN_VALUE_HANDLER = False` (`UUIDHandler`: a UUID column is hashed as stored).
- Column value handlers: the column identifier's `value_hash` selects the algorithm.
`stored` hashes the stored representation, and native containers follow their innermost
element. A column handler exposes `HASH_LABEL` and returns a `ContentHash` with that label.
Configured handlers are checked when the context or deferred type loads, and runtime
registrations are checked when the column is hashed. A missing or mismatched handler,
a column handler registered for a `stored` type, or a labelled column in Arrow storage
form raises `ValueHashMismatchError`. The bare UUID handler has no column hash label.
- Grammar restrictions the encodings rest on: no label contains `:`; the registry refuses `;`
in an extension name; extension metadata enters the identifier text as hex
(`tests/test_hashing/test_hash_grammar.py`).
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/ITL-980.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
- Logical type identifiers now include the declared column value hash in Arrow extension metadata. Saved jobs and schemas from development builds fail to load if they reference identifiers with the previous versioned metadata. Open the original files with the Orcapod version that wrote them. To migrate, recreate the job or schema from the original pipeline using the current version, save it again, and recompute affected results. Native list and set types carry the declaration through their element identifier, and a set of a plain Arrow type keeps its identifier.
- Custom logical types now register with a JSON metadata object containing `value_hash`. Declare `stored` for columns hashed as stored, or use the hash algorithm's label constant.
- In an `IgnoreListLogicalType` subclass, set `VALUE_HASH` to the same algorithm label constant already used for `HASH_LABEL` in its `IgnoreListHandler` subclass. If you call the metadata helpers directly, pass the label as the third argument to `ignore_metadata(version, ignore, value_hash)` and unpack `parse_ignore_metadata(metadata)` as `(version, names, value_hash)`.
- Column hashes now follow the value hash declared in the logical type identifier.
Missing or incompatible column handlers, handlers returning a different label, and
labelled columns still in Arrow storage form raise `ValueHashMismatchError`.
6 changes: 4 additions & 2 deletions docs/concepts/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ object array, is not a complete `.npy` file of format 3.0, or does not hold exac
element bytes its header declares, raises a `ValueError` that names the column.

The extension metadata is `{"ignore":[],"value_hash":"ndarray_v1","version":1}`. It records the
ignore list, the value hash label and the stored layout version. A null array is a null cell, allowed when the column is annotated
`np.ndarray | None`.
ignore list, the value hash label and the stored layout version. The table hash uses
the column's declared label and ignore list. A context with a missing or incompatible
array handler raises `ValueHashMismatchError` when the configuration or column is checked.
A null array is a null cell, allowed when the column is annotated `np.ndarray | None`.

```python
import io
Expand Down
13 changes: 13 additions & 0 deletions docs/concepts/logical-type-identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ procedure. The type declares the procedure in its metadata as `value_hash`. The
is the value hash label or `stored` when the stored bytes are the value's identity.
Orcapod stores and hashes the whole identifier and compares its metadata byte for byte.

When hashing a column, Orcapod reads the declaration from the identifier. A labelled
column requires a registered handler that exposes that label as `HASH_LABEL` and returns
a `ContentHash` with the same label. A column declaring `stored` uses its stored values.
Registering a column handler for that type is a mismatch. A handler that only describes
bare values as tagged data, such as the UUID handler, can coexist with `stored`.

Configured handlers are checked at context construction or when a deferred type loads.
Runtime registrations are checked when a value-bearing table is hashed, including tables
with zero rows or all-null columns. A labelled field supplied as an Arrow storage type
with extension metadata must be loaded as a live extension type before it can be hashed.
These mismatches raise `ValueHashMismatchError`, a subclass of
`LogicalTypeIdentifierError`. Schema hashing uses the identifier directly in either form.

When you supply Arrow data to a source, logical columns must use their live Arrow
extension types. A plain storage field with an extension annotation is refused, including
inside a list, struct or map. Pass the column as its logical type, or remove the extension
Expand Down
5 changes: 3 additions & 2 deletions docs/concepts/your-own-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ field with `field(compare=False)` or `field(hash=...)` is refused with `TypeErro
You can see a type on any column that holds it. The part before `@` is the name; the
rest is a hash of the name, the kind and the fields. The extension metadata carries
that identity record and a top-level `value_hash` of `stored`. Orcapod hashes a user
class column as its stored struct. A logical type used as a field contributes its whole
identifier to the class's identity record.
class column as its stored struct. Registering a column value handler for that identifier
raises `ValueHashMismatchError` when the column is hashed. A logical type used as a field
contributes its whole identifier to the class's identity record.

```python
source = DictSource(data=[{"k": "a", "p": LabelledPoint(1.0, 2.0)}], tag_columns=["k"])
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/design_issues/ITL-1152-BH1.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ November 15, 2026. UUID columns were also routed through the value handler, alth
**Fix:** (ITL-1154, rules 2 and 3) a value handler describes its value as tagged data:
`BytesHandler` returns `Encoded("bytes", {"hex": ...})` and `UUIDHandler` returns
`Encoded("uuid", {"hex": ...})`, hashed by `semantic_v1`. `bytes` and `bytearray` of equal
content still hash equal. `UUIDHandler.COLUMN_VALUE_HANDLER = False`: a UUID column is hashed
content still hash equal. The UUID type declares `"value_hash": "stored"`, so a UUID column is hashed
as stored by starfix (extension identity plus the bytes), while a bare `uuid.UUID` keeps its
tagged value hash. `tests/test_hashing/test_hash_collisions.py` checks through the public
hasher that bytes, str and UUID never collide, at the top level or nested. The label stays
Expand Down
15 changes: 12 additions & 3 deletions docs/dev/design_issues/ITL-980-BL26.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Logical type identifiers

### BL26 — Declare the column value hash in the logical type identifier
**Status:** in progress
**Status:** resolved
**Severity:** high
**Issue:** ITL-980

Expand All @@ -14,5 +14,14 @@ metadata. Types hashed as stored declare `stored`, and other types use the hash
label constant. Native list and set identifiers carry their element's metadata.
Registration rejects an invalid or missing declaration.

**Part 2:** Make the table hasher honor the declaration and refuse a missing or mismatched
handler. The current table hasher still selects the handler through the registry.
**Fix:** The table hasher selects the value hash from the column identifier and refuses
incompatible handlers or a labelled field still in Arrow storage form. Configured handlers
are checked at context construction for referenced and inline logical type registries,
and again when their deferred types load. Runtime registrations are
checked when the column is hashed. Native containers resolve the handler from their
embedded element identifier in a fresh context, and registration checks that
identifier's declaration before binding the container. Live and storage-form mismatches
report the enclosing logical identifier, the path to the failing element, its identifier,
the declared label and what the data context has. A returned hash with a different
label raises the same typed error in bare value and column hashing, including paths
whose content and digest must also be verified.
21 changes: 17 additions & 4 deletions docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Orcapod computes (developer, November 15, 2026; ITL-1154, revising ITL-945):
| 8 | **Record ids.** A record id is the row identifier itself, as text: `row_<n>` (the position) or the canonical JSON of the key columns (`{"unit":"u1","time":1700000000}`). It is not a hash and holds no source id; the source id is the other system tag. A folded record id is `<operation label>:<hex>`, like a folded source id. A source-info token is `<source id>::<record id>::<column>`. A record id holds key values, which may contain `::`; a source id and a column name never do (both are refused), so a token is split at its first and its last `::` only. |
| 9 | A random identifier (`uuid7`, `uuid4`: datagram and result ids, run ids) is not a hash and carries no label. |
| 10 | **Handler routes.** A value handler describes its value as tagged data (`Encoded`), hashed by `semantic_v1`: `bytes` / `bytearray` as `{"__type__": "bytes", "hex": ...}`, `uuid.UUID` as `{"__type__": "uuid", "hex": ...}`. It returns a labelled hash of its own only when the identity needs a dedicated algorithm: external content (`File`, `Directory`) or a library value's canonical form (`numpy.ndarray`, torch, pandas, Polars, `pa.Table`, a Polars expression). |
| 11 | **Column value handlers.** A logical type's column is hashed through a value handler only when its stored form is not its identity. A UUID column's 16 stored bytes are its identity, so starfix hashes it as stored (`UUIDHandler.COLUMN_VALUE_HANDLER = False`); a bare `uuid.UUID` keeps its tagged value hash. |
| 11 | **Column value handlers.** The type identifier's `value_hash` selects the algorithm. A handler for a labelled column declares `HASH_LABEL` and returns a `ContentHash` with that label. A UUID column declares `stored`, and a bare `uuid.UUID` keeps its tagged value hash. |
| 12 | A logical type declares its value hash label in the `value_hash` key of its extension metadata. A type hashed as stored declares `stored`. Native containers carry the innermost element's declaration through its embedded identifier. |
| 13 | Each label is defined in exactly one place, in code beside its algorithm. The type imports the label constant when writing its metadata. The data context file names the hasher class. |

Expand Down Expand Up @@ -403,7 +403,7 @@ test session with `-p tests.test_hashing.hash_site_trace`.
| schema identity | the `arrow_schema_v1` hashes of a source's or slot's Arrow tag and data schemas, or of a function's output Arrow schema | a source's content and pipeline identity, system-tag column names, the function `uri` | the `ContentHash` objects, nested | `utils/schema_utils.py:arrow_schema_identity`, `utils/schema_utils.py:compute_schema_hash`, `core/data_function.py:DataFunctionBase.output_data_schema_hash` |
| union and generic alias arguments | argument type hashes, sorted by digest, then label (ordering only) | the type hash, via the nested form | as above | `hashing/semantic_hashing/builtin_handlers.py:_sorted_hashes`, `hashing/semantic_hashing/builtin_handlers.py:_sorted_hashes.<locals>.<lambda>` |
| logical type identifier | the type's extension name and metadata, including its declared `value_hash` | type, annotation, schema and table hashes | Arrow extension field metadata or `<extension name>;<metadata hex>` | `logical_types/identifier.py:LogicalTypeIdentifier.text`, `logical_types/canonical_form.py:storage_form_schema` |
| logical-type cell, scalar and container | a value-hashed cell's value hash | the Arrow table hash | `<identifier>::<label>:<digest>`; a container cell: count, then per element a marker, a u64 length and the element token | `hashing/visitors.py:SemanticHashingVisitor.visit_extension` |
| logical-type cell, scalar and container | a value-hashed cell's value hash | the Arrow table hash | `<identifier>::<label>:<digest>` with the label checked against the identifier; a container cell: count, then per element a marker, a u64 length and the element token | `hashing/visitors.py:SemanticHashingVisitor.visit_extension` |
| entry-id preimage | the input row's data hash | the entry id, and through it the instance id, the record id and the side-effect log key | `b"<label>:" + digest` | `core/row_ids.py:entry_id_preimage` |
| instance-id preimage | the row's entry id | the instance id | `b"<label>:" + digest` | `core/row_ids.py:instance_id_preimage` |
| record-id preimage | the recording node's content hash, the row's instance id | the pipeline record id | `b"<label>:" + digest` | `core/row_ids.py:record_id_preimage` |
Expand Down Expand Up @@ -2081,13 +2081,26 @@ values of logical types whose columns are hashed through a value handler (`File`
`Directory`, `numpy.ndarray`, ...) by their cell tokens, `<identifier>::<label>:<digest>`,
typed `large_binary`. A UUID or `Path` column is hashed as stored. Both routes keep the
identifier on the hashed field, so its `value_hash` declaration enters the table hash
even on an empty or all-null column. The visitor currently selects the handler through
the registry. The type each column is hashed under is
even on an empty or all-null column. The identifier selects the algorithm and the visitor
checks that the context can supply it. A native container follows its innermost element.
The type each column is hashed under is
derived from its declared type alone (`SemanticHashingVisitor.hashed_type`): every struct and
list field keeps its name, nullability and metadata. A column therefore hashes under one type
whether it has data, only nulls or no rows (ITL-942: before v0.3 the type was rebuilt from the
first non-null value, which dropped nested nullability for a column with data).

**Hash declaration errors.** A missing or mismatched column handler, a handler returning
a hash with a different label than the type declares, a column handler for a type declaring
`stored`, or a labelled column supplied in Arrow storage form raises
`ValueHashMismatchError`. The error names the column identifier, the failing element's
path and identifier, the declaration and what the context found. A path such as
`samples[*][*]` identifies the elements of a nested native container. Configured handlers
are validated at context construction or when a
deferred logical type first loads. Runtime registrations are checked when a column is
hashed. Bare value hashing also checks the returned label. An Arrow storage-form field
declaring `stored` has the same hash as the live type.
A missing optional package raises `MissingOptionalDependencyError`.

**What cannot be hashed.** starfix raises `ValueError`, naming the column path and type, for:
data of `null`, `map`, interval, `string_view` and `binary_view` columns (whatever the row
count; their schemas hash); union and run-end-encoded types; two schema nodes sharing a path
Expand Down
48 changes: 47 additions & 1 deletion src/orcapod/contexts/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,16 @@ def get_context(self, context_string: str | None = None) -> DataContext:
return context

except Exception as e:
if isinstance(e, (ContextResolutionError, ContextValidationError)):
from orcapod.logical_types.identifier import ValueHashMismatchError

if isinstance(
e,
(
ContextResolutionError,
ContextValidationError,
ValueHashMismatchError,
),
):
raise
else:
raise ContextResolutionError(
Expand Down Expand Up @@ -446,8 +455,22 @@ def _create_context_from_spec(self, spec: dict[str, Any]) -> DataContext:
"""
from orcapod.hashing.directory_hashers import require_directory_hash_algorithm
from orcapod.hashing.hash_utils import require_file_hash_algorithm
from orcapod.hashing.orcapod_table import OrcapodTable
from orcapod.hashing.semantic_hashing.builtin_handlers import (
ArrowTableHandler,
OrcapodTableHandler,
)
from orcapod.hashing.semantic_hashing.semantic_hasher import (
SemanticAwarePythonHasher,
)
from orcapod.hashing.semantic_hashing.type_handler_registry import (
PythonTypeHandlerRegistry,
)
from orcapod.logical_types.directory_type import Directory
from orcapod.logical_types.file_type import File
from orcapod.logical_types.identifier import ValueHashMismatchError
from orcapod.semantic_types.universal_converter import UniversalTypeConverter
import pyarrow as pa

try:
context_key = spec["context_key"]
Expand Down Expand Up @@ -545,6 +568,27 @@ def _create_context_from_spec(self, spec: dict[str, Any]) -> DataContext:
)
handler_registry.declare_provisional(ref_lut[self._PROVISIONAL_REF])

type_converter = ref_lut["type_converter"]
semantic_hasher = ref_lut["semantic_hasher"]
handler_registry = semantic_hasher.type_handler_registry
if isinstance(type_converter, UniversalTypeConverter) and isinstance(
handler_registry, PythonTypeHandlerRegistry
):
type_converter.validate_configured_value_handlers(handler_registry)
elif "logical_type_registry" in ref_lut:
ref_lut["logical_type_registry"].validate_configured_value_handlers(
ref_lut["python_type_handler_registry"]
)

# The semantic hasher is built before the Arrow hasher. Set the table
# handlers' default now so their column checks use this context's registry.
if isinstance(semantic_hasher, SemanticAwarePythonHasher):
semantic_hasher.bind_type_converter(ref_lut["type_converter"])
for table_type in (pa.Table, pa.RecordBatch, OrcapodTable):
handler = handler_registry.get_handler_for_type(table_type)
if isinstance(handler, (ArrowTableHandler, OrcapodTableHandler)):
handler.bind_arrow_hasher(ref_lut["arrow_hasher"])

return DataContext(
context_key=context_key,
version=version,
Expand All @@ -554,6 +598,8 @@ def _create_context_from_spec(self, spec: dict[str, Any]) -> DataContext:
semantic_hasher=ref_lut["semantic_hasher"],
)

except ValueHashMismatchError:
raise
except Exception as e:
raise ContextValidationError(
f"Failed to create context from spec: {e}"
Expand Down
Loading
Loading