diff --git a/.zed/rules b/.zed/rules index a1858c50f..b7066de3a 100644 --- a/.zed/rules +++ b/.zed/rules @@ -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`). diff --git a/CLAUDE.md b/CLAUDE.md index 33273dd7e..45f17444d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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`). diff --git a/changelog.d/ITL-980.md b/changelog.d/ITL-980.md index cf63d7a32..7e25a2062 100644 --- a/changelog.d/ITL-980.md +++ b/changelog.d/ITL-980.md @@ -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`. diff --git a/docs/concepts/arrays.md b/docs/concepts/arrays.md index a68afe7fb..744d1c201 100644 --- a/docs/concepts/arrays.md +++ b/docs/concepts/arrays.md @@ -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 diff --git a/docs/concepts/logical-type-identifiers.md b/docs/concepts/logical-type-identifiers.md index cb67ca7c9..33601e880 100644 --- a/docs/concepts/logical-type-identifiers.md +++ b/docs/concepts/logical-type-identifiers.md @@ -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 diff --git a/docs/concepts/your-own-data-types.md b/docs/concepts/your-own-data-types.md index 4c928155e..1685122e3 100644 --- a/docs/concepts/your-own-data-types.md +++ b/docs/concepts/your-own-data-types.md @@ -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"]) diff --git a/docs/dev/design_issues/ITL-1152-BH1.md b/docs/dev/design_issues/ITL-1152-BH1.md index 6ef76082d..40f965390 100644 --- a/docs/dev/design_issues/ITL-1152-BH1.md +++ b/docs/dev/design_issues/ITL-1152-BH1.md @@ -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 diff --git a/docs/dev/design_issues/ITL-980-BL26.md b/docs/dev/design_issues/ITL-980-BL26.md index 34370b4e1..3d7b4bbc7 100644 --- a/docs/dev/design_issues/ITL-980-BL26.md +++ b/docs/dev/design_issues/ITL-980-BL26.md @@ -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 @@ -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. diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 1b268d1c2..f392ec680 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -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_` (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 `:`, like a folded source id. A source-info token is `::::`. 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. | @@ -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..` | | 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 `;` | `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 | `::