diff --git a/.zed/rules b/.zed/rules index 0131133c6..5b47978d4 100644 --- a/.zed/rules +++ b/.zed/rules @@ -976,15 +976,16 @@ Every row Orcapod stores carries __data_context (constants.DATA_CONTEXT_COL, lar the key of the data context that wrote it (std:v1:default since v0.3). The key names one generation of hashing; rows of the current data context are the current entries. - Function pipeline — pdb_v1 (PIPELINE_DB_SCHEMA_VERSION) + Function pipeline — pdb_v2 (PIPELINE_DB_SCHEMA_VERSION) Function result — rdb_v1, after the type's revision rev1 (RESULT_DB_SCHEMA_VERSION) - Side-effect log — tdb_v1 (TRACKING_DB_SCHEMA_VERSION) - Operator cache — odb_v1 (OPERATOR_DB_SCHEMA_VERSION) + Side-effect log — tdb_v2 (TRACKING_DB_SCHEMA_VERSION) + Operator cache — odb_v2 (OPERATOR_DB_SCHEMA_VERSION) Cached source — sdb_v1 (SOURCE_DB_SCHEMA_VERSION) -- The layout version is the last component of a table path. Every layout marker starts at v1 - for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn, - so nothing released uses v2). A change to the common bookkeeping columns of a table kind +- 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, + with the three row ids (developer, November 25, 2026, ITL-1471; below, "Row ids"). A change to the common bookkeeping columns of a table kind moves its layout version, so the table gets a new path. Never add, rename or retype a stored column without it. - A function result table is at @@ -1001,7 +1002,7 @@ generation of hashing; rows of the current data context are the current entries. correct result for the same input? No: a new major. Yes: a new revision (the type's columns) or a new rdb version (the common columns). Components are delimited, never parsed out of one string; the major is not repeated. - - Pipeline tables carry no revision (.../python.function.v1/schema:/pdb_v1). A + - Pipeline tables carry no revision (.../python.function.v1/schema:/pdb_v2). A saved job names the type and major only (data_function_type_id); the revision comes from the installed library's declaration (declaration_for(type id)). - A data function type's declaration (PYTHON_FUNCTION, beside its class in core/data_function.py; @@ -1057,6 +1058,99 @@ generation of hashing; rows of the current data context are the current entries. contexts/logical_types.json, never in a data context manifest: a logical type is versioned by its own identifier, and that file is not frozen. +Row ids: entry, instance, record (developer, November 25, 2026, ITL-1466, ITL-1471) + +A row that passes through a node has three nested ids (docs/reference/hashing.md section 3). +All three, with their preimages, are defined in one module, core/row_ids.py; never build one of +these preimages anywhere else. + + entry id — hash of user tags, system tags, the labelled input data hash (__pipeline_entry_id) + instance id — hash of the entry id (labelled) and the input's source-info tokens in name + order (__pipeline_instance_id) + record id — hash of the node's content hash (labelled), the instance id (labelled) and + the result id, __data_id (__pipeline_record_id) + +- A function node identifies a row by its instance id (tokens included): it is the plain lookup + column of the pipeline table and the key of the node's in-memory cache. A new instance of a + known entry (same values, other tokens) writes a new row; its result normally comes from the + result store (same input hash), so nothing is computed. +- A pipeline row stores its record id (__pipeline_record_id). It is the table's key, and it + covers the content hash of the node that records the row (developer, November 26, 2026): + with the default pipeline-hash scope one table holds the rows of several nodes, told apart by + __node_content_hash, and two of them can record one instance with one cached result, each + under its own record id. Never take the node's content hash out of the record id: the second + node's row would be dropped as a duplicate. The row stores __node_content_hash, so it gives + its record id again from its own columns. A write skips only a row this node already stored under that record id; a recompute has a new + result id, so it writes a new row. There is no recomputation index: among the rows of one + instance, __recorded_at says which is the latest. +- Only side effects and functions that take the invocation context are keyed by the entry id: + the side-effect log's row key and its entry_id column, and + InvocationContext._entry_id_hash_ch (invocation_hash is pipeline_hash :: entry id). A token + never reaches that key, so a token-only change upstream delivers nothing again. +- The operator cache keeps its whole-row key (_record_hash) and stores, outside that key, the + row's entry id (__pipeline_entry_id) and its insertion time (__recorded_at); a row passed + again is skipped and keeps its first time. Every read of the cache drops both + (_STORED_ONLY_COLUMNS). +- The column names inside a preimage are part of its recipe: renaming one moves the ids made + from it (the golden cases pin a pipeline table's instance ids; a record id holds a random + result id and cannot be pinned). +- The placeholder of an ephemeral result that is gone (EmptyData) carries the source-info + tokens a real output would, with the sentinel row_ids.EPHEMERAL_RESULT_GONE in place of the + result id (one constant; built by data_function.output_source_info, as a real output's tokens + are). A node given a placeholder computes its instance id from those tokens, finds its result + in the result store by the input hash, calls nothing and writes no pipeline row (developer, + November 26, 2026; FunctionJobNode._empty_data_cache_hit is the one place that holds that + choice, to be reconsidered in ITL-1475). +- The instance id reads a row's tokens through `DataProtocol.source_info_table()`: one column + per data column, a data column with no token having a null token. THE INTENDED RULE + (developer, November 27, 2026): the type of every source-info token column is fixed by the + pipeline, like every other column type, never taken from values. Each source and operator + determines its output token columns' types from its inputs' types, by its own rule, defined + in its own module; there is no one shape rule for all operators (`Batch` makes a list of + every token column; `GroupBy` makes lists of its members' token columns and folds a data-tag + key's tokens into one token; `MergeJoin` makes a list only for a colliding data column and + folds a merged data-tag key's tokens, as `Join` does; `Index` takes one list level off; + `Pick` writes a string token). A data-tag that falls through a function pod keeps its + source-info token with its type unchanged; a column a function returns is never a + pass-through, even with an input's name and value (its token points to the function). + TODAY (ITL-1471): a null token is a `large_string` null whatever type its column declares; + a non-null token of a row read from an Arrow table (a stream's row) keeps the type that + table declares, with a nullable field, not typed again from the value (a nested token + column would not survive it), also after a change of the row that keeps the token (a + selection, a drop, a rename, added columns); a token given as a Python value is typed from + its value (`arrow_utils.source_info_arrow_type`). STOPGAP, not the proper solution + (ITL-1491 will remove it): a type is still taken from values where a data-tag falls through + a function pod (`with_columns_of` types the copied tokens again) and at the sync edge + between two nodes (the row-built form, `_type_source_info_by_values`, and the rows' own + tables in `_rows_to_table`). That step can narrow a type an operator declared (`Batch` over + a nullable list-token column declares two list levels for `[None]`, whose value infers one) + and refuses a column whose rows infer different types; the async route passes rows on + without it. So a row built from values and the same row read from a table have one + instance id only when the table declares the types the values infer, and the two routes + are not guaranteed to give one token one type: the stopgap removed the case found (a + hand-built fixed-size-list token of a data-tag had two instance ids), not the difference. + Never build on the re-typing, and never write "a function passes a column through". A + rename moves a column's token with it; a token held for the destination name before is + dropped. An id is a function of the row (its values and the token column types it holds), + never of the order sessions ran in. A pipeline table keeps one type per token column: a row whose token column + has another type than the rows recorded (a list token beside a string or null token) is + refused, naming the column and both types (_require_one_type_per_token_column), and the write + fails as a database write error. A lookup must never fail on a row its stream holds as valid Arrow. The pipeline row + stores that same table (_add_pipeline_record), never the columns of + as_table(columns={"source": True}): every stored row gives its instance and record id again + from its own columns. +- A trace resolves a held row by its instance id, on every branch of a function step (over a + source and over another node): a function node says which instance it holds each row under + (FunctionJobNode.held_instance_ids), and provenance._entries_for keeps the stored records of + that instance. Never select by comparing token values. Another run's record of the same + entry, with other tokens, is not that row's; several records of one instance stay an + inconsistency. +- On the async path as on the sync path, a placeholder input goes to _empty_data_cache_hit, + never to the function or the pipeline writer, and under the same row failure policy and + events: the row starts before the lookup, and a placeholder with no stored result is one + failed row (continue) or stops the run (fail_fast). +- PostRunPayload.result_id is the result's id (a UUID, not a hash). + ### System tag evolution rules 1. Name-preserving — single-stream ops. Column name/value pass through unchanged. @@ -1068,8 +1162,8 @@ generation of hashing; rows of the current data context are the current entries. user tag list[T] and keeps it a tag, while GroupBy keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info columns become list[str] with one element per member. System tag columns must - stay scalar, because _build_record_id_preimage (core/nodes/function_node.py) hashes them - directly to derive record identity. They fold to a deterministic digest via + stay scalar, because entry_id_preimage (core/row_ids.py) hashes them directly to derive + a row's entry id. They fold to a deterministic digest via arrow_utils.fold_system_tag_values and their column name gains ::{pipeline_hash}. The fold is SHA-based (one helper for both system tags: the SHA-256 of the canonical JSON member list after the @@ -1717,11 +1811,15 @@ data. The rules: (`arrow_keys.polars_key_frame`, `arrow_keys.sort_key`) and the rows are taken from the table, so no value passes through Polars. A tag type with no rule (a map, an interval, a union, a list view) raises `TypeError` naming the column. -- Data source-info values may be str, None, or list[...], nested to any depth; Arrow/Python - types are derived from the value, with None mapping to large_string. That rule has one - definition, arrow_utils.source_info_arrow_type, and applies only to tokens supplied as - Python values: ArrowTableStream.iter_data hands each row's source info to Data as Arrow - columns, so a type the stream already has is never re-inferred. A many→one operator must +- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; for a + token supplied as a Python value the Arrow and Python types are derived from the value, with + `None` mapping to `large_string`. That rule has one definition, + `arrow_utils.source_info_arrow_type`. `ArrowTableStream.iter_data` hands each row's source + info to `Data` as Arrow columns, and `source_info_table()` keeps the type the stream + declares. Today a declared type is still inferred again from values in three places, a + stopgap ITL-1491 will remove (above, "Row ids"): a row's `as_table(columns={"source": True})` + (so `_rows_to_table`), the row-built form (`_type_source_info_by_values`) and + `with_columns_of`. A many→one operator must emit a list for EVERY row of a list-valued column — mixing in a bare None makes per-row as_table() schemas diverge and pa.concat_tables fail on the barrier path. - Operators that build lists (Batch, GroupBy, MergeJoin) build every list-valued column diff --git a/CLAUDE.md b/CLAUDE.md index 053e2539b..66010dfd3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1005,14 +1005,16 @@ current data context are the current entries. | Table | Layout (last path component) | Constant | |---|---|---| -| Function pipeline | `pdb_v1` | `PIPELINE_DB_SCHEMA_VERSION` | +| Function pipeline | `pdb_v2` | `PIPELINE_DB_SCHEMA_VERSION` | | Function result | `rdb_v1` (after the type's revision, `rev1`) | `RESULT_DB_SCHEMA_VERSION` | -| Side-effect log | `tdb_v1` | `TRACKING_DB_SCHEMA_VERSION` | -| Operator cache | `odb_v1` | `OPERATOR_DB_SCHEMA_VERSION` | +| Side-effect log | `tdb_v2` | `TRACKING_DB_SCHEMA_VERSION` | +| Operator cache | `odb_v2` | `OPERATOR_DB_SCHEMA_VERSION` | | Cached source | `sdb_v1` | `SOURCE_DB_SCHEMA_VERSION` | -- Every layout marker starts at `v1` for the first release, 0.4.0 (developer, November 18, - 2026, ITL-1259; 0.3.0 was withdrawn, so nothing released uses `v2`). A change to the common +- 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, + 2026, ITL-1471; below, "Row ids"). A change to the common bookkeeping columns of a table kind moves its layout version, so the table gets a new path. Never add, rename or retype a stored column without it. - A function result table is at @@ -1031,7 +1033,7 @@ current data context are the current entries. correct result for the same input? No: a new major. Yes: a new revision (the type's columns) or a new `rdb` version (the common columns). Components are delimited, never parsed out of one string; the major is not repeated. - - Pipeline tables carry no revision (`.../python.function.v1/schema:/pdb_v1`). + - Pipeline tables carry no revision (`.../python.function.v1/schema:/pdb_v2`). A saved job names the type and major only (`data_function_type_id`); the revision comes from the installed library's declaration (`declaration_for(type id)`). - A data function type's declaration (`PYTHON_FUNCTION`, beside its class in @@ -1087,6 +1089,99 @@ current data context are the current entries. `contexts/logical_types.json`, never in a data context manifest: a logical type is versioned by its own identifier, and that file is not frozen. +### Row ids: entry, instance, record + +A row that passes through a node has three nested ids (developer, November 25, 2026, +ITL-1466, ITL-1471; `docs/reference/hashing.md` section 3). All three, with their preimages, +are defined in one module, `core/row_ids.py`; never build one of these preimages anywhere else. + +| Id | Hash of | Column | +|---|---|---| +| entry id | user tags, system tags, the labelled input data hash | `__pipeline_entry_id` | +| instance id | the entry id (labelled), the input's source-info tokens in name order | `__pipeline_instance_id` | +| record id | the node's content hash (labelled), the instance id (labelled), the result id (`__data_id`) | `__pipeline_record_id` | + +- A function node identifies a row by its **instance id** (tokens included): it is the plain + lookup column of the pipeline table and the key of the node's in-memory cache. A new instance + of a known entry (same values, other tokens) writes a new row; its result normally comes from + the result store (same input hash), so nothing is computed. +- A pipeline row stores its **record id** (`__pipeline_record_id`). It is the table's key, + and it covers the content hash of the node that records the row (developer, November 26, + 2026): with the default pipeline-hash scope one table holds the rows of several nodes, told + apart by `__node_content_hash`, and two of them can record one instance with one cached + result, each under its own record id. Never take the node's content hash out of the record + id: the second node's row would be dropped as a duplicate. The row stores + `__node_content_hash`, so it gives its record id again from its own columns. A write skips only a row this node already stored under that record id; a + recompute has a new result id, so it writes a new row. There is no recomputation index: + among the rows of one instance, `__recorded_at` says which is the latest. +- Only side effects and functions that take the invocation context are keyed by the **entry + id**: the side-effect log's row key and its `entry_id` column, and + `InvocationContext._entry_id_hash_ch` (`invocation_hash` is `pipeline_hash :: entry id`). A + token never reaches that key, so a token-only change upstream delivers nothing again. +- The operator cache keeps its whole-row key (`_record_hash`) and stores, outside that key, + the row's entry id (`__pipeline_entry_id`) and its insertion time (`__recorded_at`); a row + passed again is skipped and keeps its first time. Every read of the cache drops both + (`_STORED_ONLY_COLUMNS`). +- The column names inside a preimage are part of its recipe: renaming one moves the ids made + from it (the golden cases pin a pipeline table's instance ids; a record id holds a random + result id and cannot be pinned). +- The placeholder of an ephemeral result that is gone (`EmptyData`) carries the source-info + tokens a real output would, with the sentinel `row_ids.EPHEMERAL_RESULT_GONE` in place of + the result id (one constant; built by `data_function.output_source_info`, as a real output's + tokens are). A node given a placeholder computes its instance id from those tokens, finds its + result in the result store by the input hash, calls nothing and writes no pipeline row + (developer, November 26, 2026; `FunctionJobNode._empty_data_cache_hit` is the one place + that holds that choice, to be reconsidered in ITL-1475). +- The instance id reads a row's tokens through `DataProtocol.source_info_table()`: one column + per data column, a data column with no token having a null token. THE INTENDED RULE + (developer, November 27, 2026): the type of every source-info token column is fixed by the + pipeline, like every other column type, never taken from values. Each source and operator + determines its output token columns' types from its inputs' types, by its own rule, defined + in its own module; there is no one shape rule for all operators (`Batch` makes a list of + every token column; `GroupBy` makes lists of its members' token columns and folds a data-tag + key's tokens into one token; `MergeJoin` makes a list only for a colliding data column and + folds a merged data-tag key's tokens, as `Join` does; `Index` takes one list level off; + `Pick` writes a string token). A data-tag that falls through a function pod keeps its + source-info token with its type unchanged; a column a function returns is never a + pass-through, even with an input's name and value (its token points to the function). + TODAY (ITL-1471): a null token is a `large_string` null whatever type its column declares; + a non-null token of a row read from an Arrow table (a stream's row) keeps the type that + table declares, with a nullable field, not typed again from the value (a nested token + column would not survive it), also after a change of the row that keeps the token (a + selection, a drop, a rename, added columns); a token given as a Python value is typed from + its value (`arrow_utils.source_info_arrow_type`). STOPGAP, not the proper solution + (ITL-1491 will remove it): a type is still taken from values where a data-tag falls through + a function pod (`with_columns_of` types the copied tokens again) and at the sync edge + between two nodes (the row-built form, `_type_source_info_by_values`, and the rows' own + tables in `_rows_to_table`). That step can narrow a type an operator declared (`Batch` over + a nullable list-token column declares two list levels for `[None]`, whose value infers one) + and refuses a column whose rows infer different types; the async route passes rows on + without it. So a row built from values and the same row read from a table have one + instance id only when the table declares the types the values infer, and the two routes + are not guaranteed to give one token one type: the stopgap removed the case found (a + hand-built fixed-size-list token of a data-tag had two instance ids), not the difference. + Never build on the re-typing, and never write "a function passes a column through". A + rename moves a column's token with it; a token held for the destination name before is + dropped. An id is a function of the row (its values and the token column types it holds), + never of the order sessions ran in. A pipeline table keeps one type per token + column: a row whose token column has another type than the rows recorded (a list token + beside a string or null token) is refused, naming the column and both types + (`_require_one_type_per_token_column`), and the write fails as a database write error. A lookup must never fail on a row its stream holds as valid Arrow. The + pipeline row stores that same table (`_add_pipeline_record`), never the columns of + `as_table(columns={"source": True})`: every stored row gives its instance and record id + again from its own columns. +- A trace resolves a held row by its **instance id**, on every branch of a function step + (over a source and over another node): a function node says which instance it holds each + row under (`FunctionJobNode.held_instance_ids`), and `provenance._entries_for` keeps the + stored records of that instance. Never select by comparing token values. Another run's + record of the same entry, with other tokens, is not that row's; several records of one + instance stay an inconsistency. +- On the async path as on the sync path, a placeholder input goes to + `_empty_data_cache_hit`, never to the function or the pipeline writer, and under the same + row failure policy and events: the row starts before the lookup, and a placeholder with no + stored result is one failed row (`continue`) or stops the run (`fail_fast`). +- `PostRunPayload.result_id` is the result's id (a UUID, not a hash). + ### System tag evolution rules 1. **Name-preserving** — single-stream ops (filter, select, map). Column name and value pass @@ -1099,8 +1194,8 @@ current data context are the current entries. makes every user tag `list[T]` and keeps it a tag, while `GroupBy` keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info columns become `list[str]` with one element per member. System - tag columns must stay **scalar**, because `_build_record_id_preimage` - (`core/nodes/function_node.py`) hashes them directly to derive record identity. They fold + tag columns must stay **scalar**, because `entry_id_preimage` + (`core/row_ids.py`) hashes them directly to derive a row's entry id. They fold to a deterministic digest via `arrow_utils.fold_system_tag_values` and their column name gains `::{pipeline_hash}` — a blend of rules 2 and 3. @@ -1768,11 +1863,15 @@ data. The rules: (`arrow_keys.polars_key_frame`, `arrow_keys.sort_key`) and the rows are taken from the table, so no value passes through Polars. A tag type with no rule (a map, an interval, a union, a list view) raises `TypeError` naming the column. -- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; the - Arrow and Python types are derived from the value, with `None` mapping to `large_string`. - That rule has one definition, `arrow_utils.source_info_arrow_type`, and applies only to - tokens supplied as Python values: `ArrowTableStream.iter_data` hands each row's source info - to `Data` as Arrow columns, so a type the stream already has is never re-inferred. A +- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; for a + token supplied as a Python value the Arrow and Python types are derived from the value, with + `None` mapping to `large_string`. That rule has one definition, + `arrow_utils.source_info_arrow_type`. `ArrowTableStream.iter_data` hands each row's source + info to `Data` as Arrow columns, and `source_info_table()` keeps the type the stream + declares. Today a declared type is still inferred again from values in three places, a + stopgap ITL-1491 will remove (above, "Row ids"): a row's `as_table(columns={"source": True})` + (so `_rows_to_table`), the row-built form (`_type_source_info_by_values`) and + `with_columns_of`. A many→one operator must emit a list for **every** row of a list-valued column — mixing a bare `None` into some rows makes per-row `as_table()` schemas diverge and `pa.concat_tables` fail on the barrier path. diff --git a/changelog.d/ITL-1471.md b/changelog.d/ITL-1471.md new file mode 100644 index 000000000..e6f0525d0 --- /dev/null +++ b/changelog.d/ITL-1471.md @@ -0,0 +1,81 @@ +### Breaking changes and migration + +- **Stored tables move to new layouts: `pdb_v2`, `odb_v2` and `tdb_v2`.** The function + pipeline table, the operator cache and the side-effect invocation log are written at a new + last path component. A table a release candidate wrote at `pdb_v1`, `odb_v1` or `tdb_v1` is + reported as a table of another layout and is not read; a node that delivers side effects (a + `SideEffectPod` node, or a function that takes the invocation context) refuses to run beside + one, before anything is delivered. Function results (`rdb_v1`) do not move, so a job run + again over a store of an earlier candidate records its rows again without calling a + function. (ITL-1471) +- **An operator cache can no longer be kept in a SQLite database.** Every row of an operator + cache is now stored with the time it was first stored (`__recorded_at`, a UTC timestamp), + and the SQLite connector has no column type for a timestamp. An operator node with caching + on (`CacheMode.LOG` or `REPLAY`) refuses a `SQLiteConnector` database when it is attached, + with `UnstorableColumnError` naming the node and the column, before anything runs. A + function node's pipeline table was already refused there. In-memory, Delta and PostgreSQL + databases are not affected by this. Timestamp support for the SQLite connector is + ITL-1482. (ITL-1471) +- **Every `invocation_hash` and every side-effect log key changes once.** A side effect and a + function that takes the invocation context are keyed by the row's entry id: the hash of its + tags, its system tags and its input data hash, with no other column. The side-effect log's + column `record_id_hash` is renamed `entry_id`. (ITL-1471) +- **`PostRunPayload.record_id_hash` is renamed `result_id`.** It holds the id of the result + (a UUID), not a hash. (ITL-1471) +- **`FunctionRun.entry_id` is renamed `record_id`** (the provenance record of + `explain()`): it holds the id of the pipeline table's row. (ITL-1471) +- **`FunctionJobNode.compute_base_entry_id` is renamed `compute_instance_id`, and + `compute_pipeline_entry_id` is removed.** The ids are computed by `orcapod.core.row_ids`. + (ITL-1471) +- **`DataProtocol` has a new required method, `source_info_table()`**, the one-row table of a + row's source-info columns; `Data` and `EmptyData` implement it. `EmptyData`'s unused + `empty_source_info` argument is replaced by `source_info`, the tokens it carries. + (ITL-1471) + +### Changed + +- **A row has three nested ids: entry, instance, record.** The entry id names what arrived + (tags, system tags, input data hash). The instance id names one arrival of it with its + provenance (the entry id and the input's source-info tokens), stored in + `__pipeline_instance_id`; a function node looks a row up by it. The record id names one + stored row (the content hash of the node that records it, the instance id and the result + id), stored in `__pipeline_record_id`; it is the table's key, so nodes that share a table + each keep their rows. See [Hashing](docs/reference/hashing.md), section 3. (ITL-1471) +- **The function pipeline table keeps every distinct record; the recomputation index is + gone.** The columns `__pipeline_base_entry_id` and `__pipeline_recomputation_index` are + removed, and nothing is read before a row is written. The same instance recorded again + with the same result is one row; a recompute writes a new row, and the row recorded last + (`__recorded_at`) is the current one. An input that arrives with other source-info tokens, + because its upstream result was computed again, is recorded as a new instance: the + function is not called (its result comes from the result store) and no side effect is + delivered again. (ITL-1471) +- **The operator cache records when a row was first stored, and its entry id.** Two columns + are stored beside the row key and are part of no key: `__recorded_at` and + `__pipeline_entry_id`. A row passed again keeps its first time. No read of the node shows + either column. (ITL-1471) +- **The placeholder of an ephemeral result that is gone carries source-info tokens.** Each is + the token the result's column would have, with `EPHEMERAL_RESULT_GONE` in place of the + result id. A node given a placeholder still calls nothing and writes no pipeline row; its + result comes from the result store. (ITL-1471) + +### Known limitations + +- **The type of a source-info token column is still taken from its values in two places. + This is a stopgap, not the intended behaviour.** The intended rule: the type of every + source-info token column is fixed by the pipeline, like every other column type, never + taken from values. Each source and operator determines the types of its output token + columns from its inputs' types, by its own rule (there is no one shape rule for all + operators), and a data-tag that falls through a function pod keeps its source-info token + with its type unchanged. (A column a function returns is never a pass-through, even with an + input's name and value: its token points to the function.) Today a token's type is worked + out again from its value where a data-tag falls through a function pod, and where the sync + route builds one table from a node's rows before the next node; the async route passes rows + on without that step. The re-typing where a data-tag falls through was added because a + hand-built token of another type (a fixed-size list) had two instance ids, one per route; + it removes that case, not the difference between the routes. Known limits of the stopgap: + a `fixed_size_list` token of a data-tag becomes a `large_list` after the function pod; a + nested token that cannot be typed from its value fails there; and tokens operators build + are affected too: `Batch` over a nullable list-valued token column declares two list levels + for a batch whose tokens are all null (`[None]`), the value infers one level, and the sync + route then narrows the column, or refuses the table when its rows infer different types. + ITL-1491 will remove the route difference and the re-typing. (ITL-1471) diff --git a/docs/concepts/function-pods.md b/docs/concepts/function-pods.md index 8aebfb95f..2541100ca 100644 --- a/docs/concepts/function-pods.md +++ b/docs/concepts/function-pods.md @@ -1079,7 +1079,7 @@ from that database, and no rows under that key is an empty result, not an error. over the same sources, not only the saved run's inputs. Rows come in the order the database returns them; sort them if order matters. The node itself (`as_table()`, `iter_data()`, `head()`) is empty: it has not run in this process. -- Operators (a join, a filter) store outputs only when caching is enabled, under `odb_v1`. +- Operators (a join, a filter) store outputs only when caching is enabled, under `odb_v2`. The saved file does not record an operator's cache mode (follow-up ITL-977), so attach a loaded operator node in `CacheMode.REPLAY` to read the rows its run stored: `loaded.nodes["joined"].attach_databases(pipeline_database=store.at(""), diff --git a/docs/concepts/pipeline-job.md b/docs/concepts/pipeline-job.md index 41a19df1b..fcb669197 100644 --- a/docs/concepts/pipeline-job.md +++ b/docs/concepts/pipeline-job.md @@ -243,15 +243,19 @@ 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 -timestamp and `__data_context`, and an operator cache and a cached source hold -`__data_context` too. So a job refuses these nodes when it is built, before anything runs: +timestamp and `__data_context`. An operator cache holds `__data_context`, the row's entry id +and a UTC timestamp, the time the row was first stored (`__recorded_at`). A cached source +holds `__data_context` too. So a job refuses these nodes when it is built, or when a database +is attached to them, before anything runs: - every function node, on SQLite and PostgreSQL; - every side-effect node, on SQLite; +- every operator node with caching on (`CacheMode.LOG` or `REPLAY`), on SQLite: the SQLite + connector has no column type for a timestamp (adding one is ITL-1482); - every node that stores anything, on SpiralDB. -An operator cache or cached source on a SQL connector is refused when it is written, before -anything is stored, if one of its columns has a type or name the connector does not store. On +An operator cache or cached source on a SQL connector is also refused when it is written, before +anything is stored, if one of its own columns has a type or name the connector does not store. On PostgreSQL that is every operator cache with caching on: its system-tag column names (`_tag_source_id::` and a 64-character hash) are longer than 63 bytes. A table's name is its Orcapod path joined by `__`, and every node table and cached source path diff --git a/docs/dev/plans/itl-1471-plan.md b/docs/dev/plans/itl-1471-plan.md new file mode 100644 index 000000000..c93fe2eaa --- /dev/null +++ b/docs/dev/plans/itl-1471-plan.md @@ -0,0 +1,145 @@ +# ITL-1471 plan: three nested row ids, v2 layouts (ITL-1466 stage 1) + +Stage 1 of ITL-1466. The design is `docs/dev/specs/itl-1466-as-source.md` (sections 13 and 14) +and the stage list is `docs/dev/plans/itl-1466-plan.md`, both on the ITL-1466 pull request. This +plan covers stage 1 only, with the decisions made after that plan was written (listed below). +Nothing of stages 2 to 5 is touched: `DerivedSource` serving, `as_source()` on other objects and +plain streams stay as they are. + +## Decisions this plan follows + +Developer, November 25 and 26, 2026: + +- Three nested ids: entry id, instance id, record id. Columns `__pipeline_entry_id`, + `__pipeline_instance_id`, `__pipeline_record_id`. +- Layouts `pdb_v2`, `odb_v2`, `tdb_v2`. +- The side-effect log column `record_id_hash` becomes `entry_id`; + `InvocationContext._record_id_hash_ch` becomes `_entry_id_hash_ch`. +- `PostRunPayload.record_id_hash` becomes `result_id` (it holds the result's id). +- The operator cache stores an entry-id column beside its row key, outside the key. +- An empty-data placeholder carries source-info tokens with a sentinel in place of the result id. +- A function node identifies a row by its instance id. Only side effects and functions that take + the invocation context key by the entry id. +- The 18 golden changes of `docs/dev/specs/itl-1466/golden-changes.md`, and no other. + +## The id module + +`src/orcapod/core/row_ids.py`, a leaf module (it imports the constants, `EmptyData` and pyarrow, +no node or pod module), so `function_pod.py`, `side_effects.py`, `function_node.py` and +`operator_node.py` import it at module level. It holds every preimage; no other place builds one. + +| Name | What it is | +|---|---| +| `ENTRY_ID_COL`, `INSTANCE_ID_COL`, `RECORD_ID_COL` | the three column names | +| `entry_id_preimage(tag, data)`, `entry_id(hasher, tag, data)` | user tags and system tags (`tag.as_table(columns={"system_tags": True})`), then `__input_data_hash` (`large_binary`, the labelled digest of `data.content_hash()`). Today's `_build_record_id_preimage`, moved; no index column | +| `instance_id_preimage(entry, data)`, `instance_id(hasher, tag, data)` | `__pipeline_entry_id` (`large_binary`, the entry id's labelled digest), then the input's `_source_*` columns in name order | +| `record_id_preimage(node_content_hash, instance, result_id)`, `record_id(hasher, node_content_hash, instance, result_id)` | `__node_content_hash` (`large_binary`, the labelled digest of the recording node's content hash), then `__pipeline_instance_id` (`large_binary`), then `__data_id` (`large_binary`, the result UUID's bytes). The node's content hash is in the record id by the developer's decision of November 26, 2026: the record id alone is the table's key, and two nodes sharing a table each keep their rows | + +Each id is a `ContentHash` of the data context's Arrow hasher (`arrow_v1`); it is fed onward as +`to_prefixed_digest()` and stored the same way. No new hash label. + +## Proposals to confirm + +1. **Operator cache entry-id column:** `__pipeline_entry_id` (`large_binary`, not null), the + coordinator's suggestion. It is `entry_id(hasher, tag, data)` of the output row: its tags, + system tags and the content hash of its data. It is computed in the loop that computes the row + key, and appended after the key with `__recorded_at`, so neither enters the key. +2. **Sentinel:** the text `EPHEMERAL_RESULT_GONE`, one constant in `core/row_ids.py` + (`EPHEMERAL_RESULT_GONE`). A placeholder's token for output column `c` is + `::EPHEMERAL_RESULT_GONE::`: a real output's token with the + sentinel where the result id (32 hex characters) stands. It is not hexadecimal, so it names no + result row, and it holds no `::`. The token is built by the function that builds a real + output's tokens (taken out of `PythonDataFunction` into one helper both call). +3. **Where the placeholder keeps its tokens:** `EmptyData` takes a one-row Arrow table of + `_source_*` columns and returns it from a new method; `source_info()` returns the same tokens. + Its unused field `empty_source_info` ("write logic deferred") is replaced by it. The emitting + node gives a token for each function output, and for a data-tag that falls through, the input's + stored token of that column (a real output keeps it too). +4. **A downstream node given a placeholder** computes its instance id the normal way from those + tokens. It still writes no pipeline row for a placeholder input, as today (the result comes + from the result store by input hash). Without tokens (an `EmptyData` built with none) the + instance id is the hash of the entry id alone. +5. **`FunctionRun.entry_id`** (`types/provenance.py`, public) holds the row key: renamed + `record_id`. No hash moves. + +## Files + +Library: + +- `core/row_ids.py` (new). +- `system_constants.py`: the three layout constants. `contexts/stored.py` follows through + `CURRENT_LAYOUTS`; its texts that name a layout are updated. +- `core/nodes/function_node.py`: + - `_pipeline_meta_schema`: `__pipeline_instance_id` in place of `__pipeline_base_entry_id`; no + `__pipeline_recomputation_index`. + - `compute_base_entry_id` becomes `compute_instance_id`; `compute_pipeline_entry_id`, + `_build_entry_id_preimage` and `_build_record_id_preimage` go. + - `_add_pipeline_record`: no query before the write; the row key is the record id. + - `__recorded_at` chooses among the rows of one instance (held rows, placeholders, + cross-session misses), where the index did. + - Every `base_entry_id` name becomes `instance_id`. + - The placeholder gets its tokens. +- `side_effects.py`, `core/function_pod.py`, `invocation.py`: the entry id from the module; + `_SIDE_EFFECT_RECOMPUTATION_INDEX_COL` goes; the log column and the context field are renamed. +- `hooks.py`, `core/function_pod.py`: `PostRunPayload.result_id`. +- `core/nodes/operator_node.py`: `__recorded_at` and `__pipeline_entry_id`, added after the row + key; one list of the bookkeeping columns every serving read drops. +- `core/data_function.py`: the token helper. `core/datagrams/tag_data.py`: `EmptyData`. +- `pipeline/provenance.py`, `types/provenance.py`: the row key read as `__pipeline_record_id`. +- `scripts/hash_audit_example.py`: the entry, instance and record ids in place of sites 7 and 8. + +Documents: + +- `docs/reference/hashing.md`: sites 7 to 10, the label table, the hash site inventory, the + worked example values. +- `docs/concepts/function-pods.md`, `docs/reference/data-function-types.md`, and every page under + `docs/` outside `docs/dev/` that names an old column, layout or `record_id_hash`. +- `CLAUDE.md` and `.zed/rules` together: the stored-tables table, the + `_build_record_id_preimage` mention. +- `changelog.d/ITL-1471.md`. +- The design issues log: an entry is edited only if one covers the recomputation index. + +Golden: `tests/test_hashing/golden/cases.py`, the five places that pin a table; then the commands +of `golden-changes.md`, exactly. + +## Tests + +New (`tests/test_core/test_row_ids.py`, `tests/test_core/nodes/`, the side-effect and operator +node directories), each with several rows, two or more tags and two or more data columns, token +columns in two orders, sync and async: + +- each id recomputed from a stored row (instance and record id of every pipeline row); +- the side-effect log's keys and its `entry_id` column equal the entry ids; +- a token-only change upstream records new instances, with 0 calls and 0 deliveries; +- `tdb_v1` and `pdb_v1` beside a side-effecting node are refused before any delivery; +- a recompute writes a new row; an identical repeat is skipped; +- the operator cache's `__pipeline_entry_id` equals the recomputed entry id, a re-passed row + keeps its first `__recorded_at`, and no serving read shows either column; +- the placeholder's tokens hold the sentinel, and a downstream instance id is computed from them; +- `PostRunPayload.result_id` equals the output's result id. + +Updated, counted by class in the pull request: tests that read the old columns, tests that name a +layout, tests that inject into the removed index query (removed), tests that compare stored +operator tables (compared without the time and the entry id), and the two behaviour changes by +design (one row for a repeated input; a corrected token recorded as a new instance). + +Locally: targeted tests only, one pytest process at a time. CI runs the full suite. + +## Order of commits + +1. `docs(plans)`: this plan. +2. `feat(nodes)`: `core/row_ids.py` with its unit tests. +3. `feat(nodes)!`: the function node on instance and record ids, `pdb_v2`. +4. `feat(side-effects)!`: the entry key, `tdb_v2`, the `entry_id` and `result_id` renames. +5. `feat(nodes)!`: the operator cache's `__recorded_at` and entry id, `odb_v2`. +6. `feat(nodes)`: the placeholder's sentinel tokens. +7. `test`: the existing tests updated. +8. `test(golden)`: the cases pin instance ids; the approved golden changes. +9. `docs`: the reference and concept pages, `CLAUDE.md`, `.zed/rules`, the changelog fragment. + +## Stop conditions + +- `generate_golden_hashes.py --check` shows an entry outside the approved list moving, or an + approved value differing from the listed one: no golden file is changed, and the entries and + values go to the coordinator. +- A design point this plan does not settle: asked before it is implemented. diff --git a/docs/dev/specs/itl-1518-drops-extra-columns.md b/docs/dev/specs/itl-1518-drops-extra-columns.md new file mode 100644 index 000000000..4b0cb5ace --- /dev/null +++ b/docs/dev/specs/itl-1518-drops-extra-columns.md @@ -0,0 +1,297 @@ +# ITL-1518: a function pod reads only its own columns (`drops_extra_columns`) + +Status: **measurement and plan only. The implementation is deferred** (developer, November 27, 2026). +Nothing in the library, the tests, the golden files or the agent rules changes with this document: +`pod(a)` still places the automatic `SelectDataColumns` step (ITL-807). The accepted limitation +meanwhile: two functions that take the same columns of one stream share that automatic selection +node, so they cannot take function-specific restrictions on its edge (a filter still works). + +No golden file was written or edited (`--check` and `--stdout` on a local prototype only). + +## 1. The design measured + +Developer, November 26, 2026 (ITL-1472, "stage 3a"): there is no separate selection node. A function +pod's node takes its input stream as given and reads only the data columns that are parameters of its +function. In the default mode, on an input with data columns the function does not take, the node's +identity gets one extra element, the label `drops_extra_columns`. In every other case (`strict=True`, +`process`, no extra column) the identity is exactly today's. The dropped names are not in the identity. +The input data hash covers only the columns the function takes, so stored results stay shared. + +Developer, November 27, 2026: the behaviour of the automatic-drop mode and the golden values that +pertain to it are provisional. + +## 2. How it was measured + +- Base: commit `3298bf5c`, the head of PR 583 (ITL-1471: three row ids, `pdb_v2`, the record id + covering the node's content hash). On this base `generate_golden_hashes.py --check` reports that + every group matches. +- Prototype: `itl-1518/prototype.patch`, the prototype of PR 580 unchanged (7 library files). It + applies cleanly to the base. `O34_MARK=label` selects the developer's variant. It is a measuring + tool, not the implementation (section 6). +- Commands, on a tree with the patch applied and not committed: + + ``` + O34_MARK=label uv run python tests/test_hashing/golden/generate_golden_hashes.py --check + O34_MARK=label uv run python tests/test_hashing/golden/generate_golden_hashes.py --stdout > computed.json + uv run python docs/dev/specs/itl-1518/compare_golden.py computed.json + ``` + +- Evidence beside this file, in `itl-1518/`: `golden_check.out` (the check's own list), + `golden_differences.out` (every pinned entry of every golden file against the computed value, with + both values), `compare_golden.py`. + +## 3. (a) The golden entries that move + +**34 entries differ, all in one provisional file, in two cases. No frozen file has an entry that moves.** +The count and the entries are those of the earlier measurement; what PR 583 changed is the name and +value of one kind of entry (the pipeline table now pins `instance_ids` at a `pdb_v2` path, where it +pinned `record_ids` at `pdb_v1`) and the size of the cases (75 entries each, 88 before). + +| File | Kind | Entries that move | +|---|---|---| +| `provisional/pipeline.json` | provisional | 34 | +| `pipeline-01.json`, `pipeline-02.json` | frozen at 0.4.0 | 0 | +| every other file (`arrow`, `datagram`, `schema`, `semantic`, `torch`; frozen and provisional) | | 0 | + +2480 entries were computed (arrow 222, datagram 329, pipeline 1372, schema 335, semantic 190, torch +32). `compare_golden.py` also lists three entries pinned as `null` in a frozen file that `--stdout` +does not print; they are not differences (the base's own `--check` passes with them, and the +prototype's `--check` reports 34). + +The cases are `rejoin_job` and `rejoin_job_async` (both declare `Rejoin`), the only golden cases in +which a pod is called on a stream with a data column its function does not take: +`golden_ratio(age, weight)` over the rejoined stream, whose data columns are `age`, `score`, `weight`, +`height`. The two cases pin equal values, sync and async. Per case, 17 of 75 entries: + +| Mark | Entries per case | Why | +|---|---|---| +| S | 12 | There is no select node between the rejoined stream and `ratio` | +| H | 2 | `ratio`'s node is the pod over the rejoined stream (it was the pod over a select of it), and its identity tuple ends with `drops_extra_columns` | +| P-old, P-new | 2 | A pipeline table is at `.../schema:/pdb_v2`; the pipeline hash moved. The two entries hold equal instance ids | +| L | 1 | `table_paths` names the new pipeline-table path; the result table path is in the list unchanged | + +The list for `rejoin_job`; `rejoin_job_async` has the same 17 entries with the same values, under +`pipeline:rejoin_job_async.` (its tables are under `golden_rejoin_job/` too). `` is +`b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4`, `` is +`golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1`. + +| # | Entry (`pipeline:rejoin_job.`...) | Pinned today | New | Why | +|---|---|---|---|---| +| 1 | `node[SelectDataColumns].content_hash` | `semantic_v1:96904fb283607c88e95e96842137d3683aea92ddb26978b2cd1c075eb5f8ebf7` | (none) | S | +| 2 | `node[SelectDataColumns].pipeline_hash` | `semantic_v1:646655f033644fd96e1c1ea0fd56af969e3afe16c76b1cb176aa343a3d2ebbe5` | (none) | S | +| 3 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_record_id::` | `row_0` | (none) | S | +| 4 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_source_id::` | `dict_v1:rejoin_origin` | (none) | S | +| 5 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}].data_hash` | `arrow_v1:000002d1c5b49de38ef6efc552c2a47b8ab59dd267f8eb55d91814edee99b1b52acc65` | (none) | S | +| 6 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_record_id::` | `row_1` | (none) | S | +| 7 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_source_id::` | `dict_v1:rejoin_origin` | (none) | S | +| 8 | `node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}].data_hash` | `arrow_v1:000002338ce8710f5ecb156a72c8446651adb7b0c21635d0aa92d298f09da56faed0f8` | (none) | S | +| 9 | `node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_record_id::` | `row_2` | (none) | S | +| 10 | `node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_source_id::` | `dict_v1:rejoin_origin` | (none) | S | +| 11 | `node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}].data_hash` | `arrow_v1:0000023401f1ce40c8cfdd6e4f343d7ffdcd51c1f0521f44cf6030e27e1ca0da154616` | (none) | S | +| 12 | `node[SelectDataColumns].system_tag_columns` | `_tag_source_id::`, `_tag_record_id::` | (none) | S | +| 13 | `node[ratio].content_hash` | `semantic_v1:84f5f8ce9de0dac0e361d0b0d69f186075974bd359ccbee04ca58f2cc6fefbac` | `semantic_v1:511d3c57512025445c23773ce648ee29b277882027ddf8a1e5080b1e2adc06a3` | H | +| 14 | `node[ratio].pipeline_hash` | `semantic_v1:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba` | `semantic_v1:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87` | H | +| 15 | `table[golden_rejoin_job//schema:2940d188...e7ba/pdb_v2].instance_ids` | `arrow_v1:00000264d51dd01edfbb777f7047d25e7cdb50e4f52e6b01454ffc56b70aa5b166b920`, `arrow_v1:0000029b103c78b5c06ac0fe36d793fe576563a8609b835d662cf78a5828436f9b8aa3`, `arrow_v1:000002b71bb228680318fe2cc0fc599241136f0fedc28658bda79e2a90915b87c82ef0` | (none) | P-old: the path is no longer produced | +| 16 | `table[golden_rejoin_job//schema:64b6c04f...6b87/pdb_v2].instance_ids` | (not pinned) | the same three instance ids as entry 15 | P-new: the same rows at the new path | +| 17 | `table_paths` | `golden_rejoin_job/_result//rev1/rdb_v1`, `golden_rejoin_job//schema:2940d188...e7ba/pdb_v2` | `golden_rejoin_job/_result//rev1/rdb_v1`, `golden_rejoin_job//schema:64b6c04f...6b87/pdb_v2` | L | + +The full keys and values are in `itl-1518/golden_differences.out`. + +Unchanged in the two cases: the result table path and its `input_data_hashes` entry (the input data +hash covers `age` and `weight` only, as after today's select), the pipeline table's instance ids, +every row's record-id and source-id system tag and data hash, every system-tag column name, and every +other node of the job. + +A record id (`__pipeline_record_id`) covers the node's content hash since PR 583, so the record ids +of the moved node's rows change with entry 13. No golden entry pins a record id (it holds a random +result id), so this adds no entry to the list. + +The new values of entries 13, 14, 16 and 17 are those of the prototype. They are the final values +only if the implementation hashes the same structure: `(pod, inputs, "drops_extra_columns")`. Measure +again before the golden step. + +## 4. (b) How the mode is declared provisional + +Modelled on the provisional operators (ITL-1266) and sources (ITL-1314). The mode is neither an +operator nor a source, so it needs a list of its own. Proposal: + +- **One list**, `PROVISIONAL_MODES` in a new leaf module `core/provisional_modes.py`: name to the + issue that decides it, today `{"drops_extra_columns": "ITL-1518"}`. A test checks the list against + the one place that uses each name, as the operator test checks `PROVISIONAL = True`. +- **Warning**: `ProvisionalHashWarning`, once per process, through the existing helper + `utils/provisional.warn_provisional_use("drops_extra_columns", ...)`. It is issued where the mode + is entered: a pod call in the default mode that drops at least one column, and the load of a saved + job whose function node carries the mark. A pod call that drops nothing, `strict=True` and + `process` never warn. +- **Use record**: the marked node notes its use again where its identity is read (`content_hash`, + `pipeline_hash`, the identity structures), with `note_provisional_use`, as an operator and a source + do. That is what lets the golden guard see a use behind an object built inside the case. +- **The mark is not the label.** The list's key is the mode's name and never enters a hash, an + identifier, a config or a stored path. The identity label is a separate constant + (`DROPS_EXTRA_COLUMNS`), defined once beside the node's identity code. They happen to have the + same text. +- **Golden cases**: a case in which a pod drops columns declares + `@case(..., provisional=("drops_extra_columns",))`; the name joins the names a case may declare + (as `DECLARABLE_PROVISIONAL_SOURCES` does for `DerivedSource`). `compute_group_kinds` refuses a case + that uses the mode undeclared. Its entries live in `data/v1/provisional/.json`, outside the + history; no release freezes them; they change only with the developer's approval of the exact list. +- **Everything downstream is provisional**, as for an operator: a node fed by a marked node has + hashes that hold the label. + +What must be declared, and what is relocated: + +- `rejoin_job` and `rejoin_job_async` become `provisional=("Rejoin", "drops_extra_columns")`. Their + entries are already in the provisional file. +- **No frozen case has to be relocated.** A node in the mode has other hashes than today, so a frozen + case using it would show in section 3; none does. +- New cases for the mode (section 6) are provisional from the start. + +Two consequences to decide knowingly: + +1. Calling a pod on a table wider than its parameters is the common call. With this proposal most + user pipelines issue the warning once per process and have provisional hashes below that node, + until ITL-1518 is decided. A user avoids it with a hand-written `select_data_columns`, `process` or + `strict=True`. +2. When `Rejoin` leaves the provisional list, the two rejoin cases stay provisional for as long as + the mode is. A frozen golden case can never call a pod on a wider stream; it writes the select by + hand. + +## 5. (c) What a user with an existing store sees + +Measured with `itl-1518/store_run.py` (functions in `store_functions.py`; each call appends a line to +a file, so calls are counted across processes): one job on a Delta store with five function nodes, +run on the base code, run on the base code again (control), then run with the prototype on the same +store. Outputs: `store_run_before.out`, `store_run_before_again.out`, `store_run_after.out`. + +| Node | Input | Before | After | +|---|---|---|---| +| `double_wide` | 3 data columns, 1 taken | select node + pod | no select node; content and pipeline hash move; pipeline table at a new path | +| `triple_down` | the output of `double_wide` (no extra column) | pod | hashes move (downstream of a moved node); pipeline table at a new path | +| `add_two` | two sources, each with an extra column | `Join` + select node + pod | `Join` unchanged; no select node; hashes move; pipeline table at a new path | +| `scale_datatags` | 2 data columns, 1 taken, 2 data-tags | select node + fall-through pod | no select node; hashes move; pipeline table at a new path | +| `halve_narrow` | 1 data column, taken | pod | unchanged: same hashes, same pipeline table | + +- **No function is called again.** Calls in the first run: 3 per function (15). In the control run: 0. + In the run with the prototype: **0**. Every node returns its 3 rows. +- **Result tables do not move and get no new row**: the five `_result/.../rev1/rdb_v1` tables hold 3 + rows before and after. The input data hash of a row is the one today's select gives. +- **Four pipeline tables move** (`.../schema:/pdb_v2`): the three nodes whose pod drops + columns, and the node downstream of one. Each new table gets 3 rows on the first run. The four old + tables stay where they are, with their rows, unread and unchanged. They are at the current layout, + so nothing reports them as stale tables. +- **The select node had no table.** An operator job node stores nothing unless it has a cache mode; + the store of the run holds no table for the three select nodes. With `LOG` or `REPLAY` on such a + node its operator cache table would be left unused. That case was not run. +- The source nodes and the `Join` keep their hashes. +- Not measured: a saved job written before the change and loaded after it (its file names the select + node, so it would load as the old graph: section 6), `as_source()` over a moved node (it reads the + new pipeline table, which is empty until the first run), a side-effect pod downstream of a moved + node (its log is keyed by `pipeline_hash :: entry id`, so the pipeline hash moving would deliver + again: **to be measured before the implementation**, since a delivery is not a function result). + +Also on the prototype (`folded_confirm.py` of PR 580, run on this base): a job with the hand-written +select on the same store makes 0 function calls after the folded job computed, with another pipeline +hash and pipeline table; with no extra column the default call, `strict=True` and `process` have one +content hash and one pipeline hash; `strict=True` and `process` refuse an extra column; the input's +columns in another order give the same hashes. + +## 6. (d) Implementation plan (for when the work is taken up) + +The prototype narrows the input with a hidden select whose stream reports its input's identity. The +implementation does not keep that: the node reads the columns itself. + +Library: + +- `core/function_pod.py` + - `DROPS_EXTRA_COLUMNS = "drops_extra_columns"` and one function returning the identity tail + (`()` or `(DROPS_EXTRA_COLUMNS,)`); no other literal anywhere (a test greps). + - `_FunctionPodBase.__call__`: no `SelectDataColumns`. It joins as `process` does, computes the + dropped names (data columns that are neither parameters nor fall-through data-tags), validates + the kept columns, logs the dropped names once at info, and builds the stream or node with the + mark. Nothing dropped, `strict=True` or `accepts_arbitrary_keywords`: exactly `process`. + - The mark is a property of the invocation (the output stream and its node), not of the pod + object: the pod's own identity, its `uri` and the result table path are untouched. + - `FunctionPodStream`: identity tail; rows narrowed before the call. + - `FallThroughPod`: the kept columns are the parameters and its fall-through tags; a data-tag is + never counted as dropped and keeps its source-info token as today. +- `core/streams/base.py` (`StreamBase.identity_structure`) and `pipeline/pod_invocation.py` + (`PodInvocation.identity_structure`): the same tail, from the one function, so the invocation's + hash equals the compiled node's. +- `core/nodes/function_node.py` + - `FunctionNodeBase`: the input schema check ignores the dropped columns when the node has the mark, + and refuses them when it has not. + - One narrowing step for an input row, used by the sync path (`execute`, load-only), the async path + (`async_execute`, load-only) and the placeholder path, placed before the input data hash, the + entry id, the instance id and the call. The source-info table the instance id reads holds the + kept columns only, as after today's select, so instance ids are those of entries 15 and 16. + - The typed zero-row table (`function_zero_row_table`) and `head()` take the input's tags and the + declared outputs; check they never read a dropped column. +- `pipeline/graph.py`, `pipeline/serialization.py`: `"drops_extra_columns": true` in a function + node's descriptor, only when marked; the loader rebuilds the node with it. A job saved before the + change still names its select node and loads as that graph, with its old hashes: nothing is + rewritten. A descriptor with the key on a node with no extra column is refused. +- `pipeline/provenance.py` (`trace`, `why_missing`): narrow the input row as the node does before + comparing the stored input data hash; a trace no longer passes through a select node. +- `explain()`, `diagram()`: name the ignored columns on the pod, computed from the input's columns and + the function's parameters (the names are not stored). +- `core/provisional_modes.py` and the warning and use notes of section 4. +- Edge restrictions and probes (ITL-1472) then see one edge per function. + +Behaviour to hold, each with a test: + +| Case | Expected | +|---|---| +| `pod(a)`, no extra column | today's identity, no warning | +| `pod(a)`, extra columns | label appended; one info log; `ProvisionalHashWarning` once | +| `pod(a, strict=True)`, `pod.process(a)`, no extra column | equal to `pod(a)` in every hash | +| `pod(a, strict=True)`, `pod.process(a)`, extra columns | refused, as today | +| `pod(a, b)` | the automatic `Join` stays an ordinary step; the pod's node is over the join, marked when the joined stream has extra columns; a data column shared by two inputs fails at the join | +| data-tags | fall through with their token; never dropped; never counted as extra | +| missing required column, type mismatch | an error in every form, before any node is built | +| hand-written `select_data_columns` | a select node and today's pod: another pipeline hash, the same result table and entries | +| saved job, marked node | round trip keeps the mark and every hash; a load issues the warning | +| existing store | no function call; results served by input hash | + +Tests (targeted; public interface; CLAUDE.md "Testing conventions"): + +- Inputs with two or more tag columns and three or more data columns, two or more dropped, two or + more kept; from `tests/test_core/operators/several_items.py` where it fits. +- Orders: the input's data columns, tag columns and table layout in several arrangements, and the + function's parameters in another order than the columns: one content hash, one pipeline hash, one + set of instance ids, equal rows. A case in `tests/test_core/test_order_invariance.py`. +- Roles: plain tags, data-tags, data; a dropped column that is nullable, a list, a logical type. +- Sync and async: equal rows, hashes, stored tables and events + (`test_async_sync_equivalence.py` covers operators; the pod case goes beside the function node's + own sync and async tests). +- Two functions over one stream that take the same columns: two nodes on two edges, no shared node. +- The replacement of ITL-807's tests (`test_function_pod_auto_select.py`, + `test_fall_through_pod_wiring.py`): the equality with the hand-written select is withdrawn; the + equality of input data hashes and of results is kept. +- Tests that name `SelectDataColumns` in a node list, a diagram or printed output + (`test_node_staleness_after_run.py`, `test_source_display_names.py`, `test_diagram.py`, + `test_doc_samples.py`), provenance (`test_provenance_review.py`), and the paths the prototype does + not narrow (`test_result_database.py`, `test_saved_job_with_data_tag_operator_nodes.py`, + `test_function_commit_dependencies.py`). The earlier run on the prototype counted 74 failing tests + in these areas; **that run was not repeated on this base**. +- The provisional list test, the warning (once per process; none in the strict forms), the golden + guard refusing an undeclared use. + +Golden step, only with the developer's approval of the list measured again at that time: +`--remove` each entry of the list, then the generator writes the new values; the diff of the golden +folder is the list and nothing else. New provisional cases: a pod dropping two columns in both input +column orders (one identity), beside the hand-written select (another pipeline hash, equal input data +hashes), under a `ctx` pod and a fall-through pod. + +Documents: `CLAUDE.md` and `.zed/rules` ("Calling a function pod": the automatic step and its +equality with the hand-written select are withdrawn), `docs/concepts/function-pods.md` and the pages +that show `SelectDataColumns` after a pod call, the provisional mode and what an existing store sees +(section 5), `changelog.d/ITL-1518.md` (breaking change; known limitation: provisional). No hash site +is added: the label is a plain string in a structure `semantic_v1` hashes, and it names no algorithm. + +## 7. Open points + +- The side-effect question of section 5 (does a moved pipeline hash deliver again downstream). +- Whether the warning on the common call (section 4, consequence 1) is wanted, or the mode should be + provisional in the documents and golden files only. +- A function revision with the same `uri` and other parameters drops other columns under one + identity, as two such revisions are one identity today. diff --git a/docs/dev/specs/itl-1518/compare_golden.py b/docs/dev/specs/itl-1518/compare_golden.py new file mode 100644 index 000000000..91dca8ef5 --- /dev/null +++ b/docs/dev/specs/itl-1518/compare_golden.py @@ -0,0 +1,56 @@ +"""ITL-1518: every pinned golden entry against the values a tree computes. + + uv run python tests/test_hashing/golden/generate_golden_hashes.py --stdout > computed.json + uv run python docs/dev/specs/itl-1518/compare_golden.py computed.json + +Writes nothing. An entry pinned as ``null`` is not printed by ``--stdout`` and shows as +GONE; the generator's own ``--check`` is the authority on those. +""" + +from __future__ import annotations + +import glob +import json +import os +import sys + +ROOT = "tests/test_hashing/golden/data/v1" + + +def main() -> None: + with open(sys.argv[1]) as f: + groups = json.load(f) + pinned = {} + for path in sorted( + glob.glob(ROOT + "/*.json") + glob.glob(ROOT + "/provisional/*.json") + ): + group = os.path.basename(path).split("-")[0].split(".")[0] + with open(path) as f: + for key, value in json.load(f).items(): + pinned[f"{group}:{key}"] = (value, os.path.relpath(path, ROOT)) + computed = {f"{g}:{k}": v for g, d in groups.items() for k, v in d.items()} + print( + "computed", + len(computed), + {g: len(d) for g, d in groups.items()}, + "pinned", + len(pinned), + ) + differ = 0 + for key in sorted(set(pinned) | set(computed)): + old, new = pinned.get(key), computed.get(key) + if old is None: + differ += 1 + print("NEW ", key, "\n ->", json.dumps(new)) + elif new is None: + differ += 1 + print("GONE ", old[1], key, "\n was", json.dumps(old[0])) + elif old[0] != new: + differ += 1 + print("MOVED ", old[1], key) + print(" was", json.dumps(old[0]), "\n now", json.dumps(new)) + print("differ", differ) + + +if __name__ == "__main__": + main() diff --git a/docs/dev/specs/itl-1518/golden_check.out b/docs/dev/specs/itl-1518/golden_check.out new file mode 100644 index 000000000..6b0709878 --- /dev/null +++ b/docs/dev/specs/itl-1518/golden_check.out @@ -0,0 +1,36 @@ +34 golden problem(s): + pipeline:rejoin_job.node[SelectDataColumns].content_hash is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].pipeline_hash is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}].data_hash is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}].data_hash is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}].data_hash is pinned but no longer produced + pipeline:rejoin_job.node[SelectDataColumns].system_tag_columns is pinned but no longer produced + pipeline:rejoin_job.node[ratio].content_hash moved: pinned 'semantic_v1:84f5f8ce9de0dac0e361d0b0d69f186075974bd359ccbee04ca58f2cc6fefbac', live 'semantic_v1:511d3c57512025445c23773ce648ee29b277882027ddf8a1e5080b1e2adc06a3' + pipeline:rejoin_job.node[ratio].pipeline_hash moved: pinned 'semantic_v1:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba', live 'semantic_v1:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87' + pipeline:rejoin_job.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2].instance_ids is pinned but no longer produced + pipeline:rejoin_job.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2].instance_ids is computed but not pinned + pipeline:rejoin_job.table_paths moved: pinned ['golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1', 'golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2'], live ['golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1', 'golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2'] + pipeline:rejoin_job_async.node[SelectDataColumns].content_hash is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].pipeline_hash is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}].data_hash is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}].data_hash is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}].data_hash is pinned but no longer produced + pipeline:rejoin_job_async.node[SelectDataColumns].system_tag_columns is pinned but no longer produced + pipeline:rejoin_job_async.node[ratio].content_hash moved: pinned 'semantic_v1:84f5f8ce9de0dac0e361d0b0d69f186075974bd359ccbee04ca58f2cc6fefbac', live 'semantic_v1:511d3c57512025445c23773ce648ee29b277882027ddf8a1e5080b1e2adc06a3' + pipeline:rejoin_job_async.node[ratio].pipeline_hash moved: pinned 'semantic_v1:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba', live 'semantic_v1:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87' + pipeline:rejoin_job_async.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2].instance_ids is pinned but no longer produced + pipeline:rejoin_job_async.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2].instance_ids is computed but not pinned + pipeline:rejoin_job_async.table_paths moved: pinned ['golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1', 'golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2'], live ['golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1', 'golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2'] +exit=1 diff --git a/docs/dev/specs/itl-1518/golden_differences.out b/docs/dev/specs/itl-1518/golden_differences.out new file mode 100644 index 000000000..80f91127b --- /dev/null +++ b/docs/dev/specs/itl-1518/golden_differences.out @@ -0,0 +1,82 @@ +computed 2480 {'arrow': 222, 'datagram': 329, 'pipeline': 1372, 'schema': 335, 'semantic': 190, 'torch': 32} pinned 2504 +GONE provisional/pipeline.json pipeline:group_by_nan_keys.data_tag_key.row[{"k":null}].key_bits + was null +GONE provisional/pipeline.json pipeline:group_by_nan_keys.row[{"k":null}].key_bits + was null +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].content_hash + was "semantic_v1:96904fb283607c88e95e96842137d3683aea92ddb26978b2cd1c075eb5f8ebf7" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].pipeline_hash + was "semantic_v1:646655f033644fd96e1c1ea0fd56af969e3afe16c76b1cb176aa343a3d2ebbe5" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_0" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}].data_hash + was "arrow_v1:000002d1c5b49de38ef6efc552c2a47b8ab59dd267f8eb55d91814edee99b1b52acc65" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_1" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}].data_hash + was "arrow_v1:000002338ce8710f5ecb156a72c8446651adb7b0c21635d0aa92d298f09da56faed0f8" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_2" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}].data_hash + was "arrow_v1:0000023401f1ce40c8cfdd6e4f343d7ffdcd51c1f0521f44cf6030e27e1ca0da154616" +GONE provisional/pipeline.json pipeline:rejoin_job.node[SelectDataColumns].system_tag_columns + was ["_tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4", "_tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4"] +MOVED provisional/pipeline.json pipeline:rejoin_job.node[ratio].content_hash + was "semantic_v1:84f5f8ce9de0dac0e361d0b0d69f186075974bd359ccbee04ca58f2cc6fefbac" + now "semantic_v1:511d3c57512025445c23773ce648ee29b277882027ddf8a1e5080b1e2adc06a3" +MOVED provisional/pipeline.json pipeline:rejoin_job.node[ratio].pipeline_hash + was "semantic_v1:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba" + now "semantic_v1:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87" +GONE provisional/pipeline.json pipeline:rejoin_job.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2].instance_ids + was ["arrow_v1:00000264d51dd01edfbb777f7047d25e7cdb50e4f52e6b01454ffc56b70aa5b166b920", "arrow_v1:0000029b103c78b5c06ac0fe36d793fe576563a8609b835d662cf78a5828436f9b8aa3", "arrow_v1:000002b71bb228680318fe2cc0fc599241136f0fedc28658bda79e2a90915b87c82ef0"] +NEW pipeline:rejoin_job.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2].instance_ids + -> ["arrow_v1:00000264d51dd01edfbb777f7047d25e7cdb50e4f52e6b01454ffc56b70aa5b166b920", "arrow_v1:0000029b103c78b5c06ac0fe36d793fe576563a8609b835d662cf78a5828436f9b8aa3", "arrow_v1:000002b71bb228680318fe2cc0fc599241136f0fedc28658bda79e2a90915b87c82ef0"] +MOVED provisional/pipeline.json pipeline:rejoin_job.table_paths + was ["golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1", "golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2"] + now ["golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1", "golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2"] +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].content_hash + was "semantic_v1:96904fb283607c88e95e96842137d3683aea92ddb26978b2cd1c075eb5f8ebf7" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].pipeline_hash + was "semantic_v1:646655f033644fd96e1c1ea0fd56af969e3afe16c76b1cb176aa343a3d2ebbe5" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_0" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s1"}].data_hash + was "arrow_v1:000002d1c5b49de38ef6efc552c2a47b8ab59dd267f8eb55d91814edee99b1b52acc65" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_1" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"a","subject":"s2"}].data_hash + was "arrow_v1:000002338ce8710f5ecb156a72c8446651adb7b0c21635d0aa92d298f09da56faed0f8" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "row_2" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}]._tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4 + was "dict_v1:rejoin_origin" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].row[{"cohort":"b","subject":"s3"}].data_hash + was "arrow_v1:0000023401f1ce40c8cfdd6e4f343d7ffdcd51c1f0521f44cf6030e27e1ca0da154616" +GONE provisional/pipeline.json pipeline:rejoin_job_async.node[SelectDataColumns].system_tag_columns + was ["_tag_source_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4", "_tag_record_id::b5bbcf9ae6104dc1b569e22587fbde690abf127944838a4e1a1c96bf347db0e4"] +MOVED provisional/pipeline.json pipeline:rejoin_job_async.node[ratio].content_hash + was "semantic_v1:84f5f8ce9de0dac0e361d0b0d69f186075974bd359ccbee04ca58f2cc6fefbac" + now "semantic_v1:511d3c57512025445c23773ce648ee29b277882027ddf8a1e5080b1e2adc06a3" +MOVED provisional/pipeline.json pipeline:rejoin_job_async.node[ratio].pipeline_hash + was "semantic_v1:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba" + now "semantic_v1:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87" +GONE provisional/pipeline.json pipeline:rejoin_job_async.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2].instance_ids + was ["arrow_v1:00000264d51dd01edfbb777f7047d25e7cdb50e4f52e6b01454ffc56b70aa5b166b920", "arrow_v1:0000029b103c78b5c06ac0fe36d793fe576563a8609b835d662cf78a5828436f9b8aa3", "arrow_v1:000002b71bb228680318fe2cc0fc599241136f0fedc28658bda79e2a90915b87c82ef0"] +NEW pipeline:rejoin_job_async.table[golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2].instance_ids + -> ["arrow_v1:00000264d51dd01edfbb777f7047d25e7cdb50e4f52e6b01454ffc56b70aa5b166b920", "arrow_v1:0000029b103c78b5c06ac0fe36d793fe576563a8609b835d662cf78a5828436f9b8aa3", "arrow_v1:000002b71bb228680318fe2cc0fc599241136f0fedc28658bda79e2a90915b87c82ef0"] +MOVED provisional/pipeline.json pipeline:rejoin_job_async.table_paths + was ["golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1", "golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:2940d188693a284739b066b85def5c18e849c85c1de5fc9a3444d6dfbb25e7ba/pdb_v2"] + now ["golden_rejoin_job/_result/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/rev1/rdb_v1", "golden_rejoin_job/golden_ratio/43ebfd98b0b9497b3b820bb330f4727dd540e67883fd7588fdd98d1f176733b3/v0/python.function.v1/schema:64b6c04f3dd104e05264b806b1b24c1e20ac153ec8afd6df94d2afec64fe6b87/pdb_v2"] +GONE semantic-01.json semantic:function.stored_content.without_source + was null +differ 37 diff --git a/docs/dev/specs/itl-1518/prototype.patch b/docs/dev/specs/itl-1518/prototype.patch new file mode 100644 index 000000000..e6c3d0675 --- /dev/null +++ b/docs/dev/specs/itl-1518/prototype.patch @@ -0,0 +1,371 @@ +diff --git a/src/orcapod/core/function_pod.py b/src/orcapod/core/function_pod.py +index 8a24c3b4..d4fb87f0 100644 +--- a/src/orcapod/core/function_pod.py ++++ b/src/orcapod/core/function_pod.py +@@ -175,12 +175,32 @@ class _FunctionPodBase(TraceableBase): + return PodConfig() + + def identity_structure(self) -> Any: ++ mark = getattr(self, "_o34_mark", None) # PROTOTYPE (ITL-1472, O34, variant B) ++ if mark is _O34_LABEL: # in the node's tuple, not the pod's identity ++ mark = None + if self._ctx_arg_name is not None: +- return (self.data_function, self._ctx_arg_name) +- return self.data_function ++ base: Any = (self.data_function, self._ctx_arg_name) ++ else: ++ base = self.data_function ++ if mark is None: ++ return base ++ if mark is True: ++ return (base, ("drop_extra", True)) ++ if isinstance(mark, tuple): ++ return (base, ("ignored_columns", mark)) ++ return (base, ("input", mark)) + + def pipeline_identity_structure(self) -> Any: +- return self.data_function ++ mark = getattr(self, "_o34_mark", None) ++ if mark is _O34_LABEL: ++ mark = None ++ if mark is None: ++ return self.data_function ++ if mark is True: ++ return (self.data_function, ("drop_extra", True)) ++ if isinstance(mark, tuple): ++ return (self.data_function, ("ignored_columns", mark)) ++ return (self.data_function, ("input", mark)) + + def _build_invocation_context( + self, +@@ -804,7 +824,7 @@ class _FunctionPodBase(TraceableBase): + # nothing is unused and no select is added (developer, November 12, 2026, + # ITL-807). No data function kind accepts them today. + if strict or self.data_function.accepts_arbitrary_keywords: +- return self.process(*streams, label=label) ++ return _o34_marked(self, "strict").process(*streams, label=label) + + input_stream = self.handle_input_streams(*streams) + _, data_schema = input_stream.output_schema() +@@ -844,7 +864,7 @@ class _FunctionPodBase(TraceableBase): + self._validate_input_schema( + Schema({name: data_schema[name] for name in checked}) + ) +- from orcapod.core.operators import SelectDataColumns ++ from orcapod.core.operators.column_selection import ParameterColumns + + logger.info( + "Function pod %r: dropped data columns %s, which are not " +@@ -854,13 +874,21 @@ class _FunctionPodBase(TraceableBase): + ) + # The select is Orcapod's own step: the data-tags it turns into + # plain tags are not reported (ITL-1023). ++ # PROTOTYPE (ITL-1472, O34): no step; the pod reads these columns. + with materialization_diagnostic_off(): +- input_stream = SelectDataColumns(columns=kept)(input_stream) +- if fall_through_pod is not None and data_tags: +- return FallThroughPod(fall_through_pod, data_tags).process( ++ input_stream = ParameterColumns(kept).process(input_stream) ++ token = _O34_LENIENT.set(True) ++ ignored = tuple(sorted(dropped)) if dropped and kept else None ++ try: ++ if fall_through_pod is not None and data_tags: ++ return FallThroughPod( ++ _o34_marked(fall_through_pod, "lenient", ignored), data_tags ++ ).process(input_stream, label=label) ++ return _o34_marked(self, "lenient", ignored).process( + input_stream, label=label + ) +- return self.process(input_stream, label=label) ++ finally: ++ _O34_LENIENT.reset(token) + + def argument_symmetry(self, streams: Collection[StreamProtocol]) -> ArgumentGroup: + return self.multi_stream_handler().argument_symmetry(streams) +@@ -968,6 +996,17 @@ class FunctionPod(_FunctionPodBase): + """ + logger.debug("Invoking kernel %s on streams: %s", self, streams) + ++ # PROTOTYPE (ITL-1472, O34, variant B with the strict mode marked): a direct ++ # ``process`` is the strict mode. ++ import os ++ ++ if ( ++ os.environ.get("O34_MARK") == "strict" ++ and not _O34_LENIENT.get() ++ and getattr(self, "_o34_mark", None) is None ++ ): ++ return _o34_marked(self, "strict").process(*streams, label=label) ++ + input_stream = self.handle_input_streams(*streams) + + # perform input stream schema validation +@@ -1194,6 +1233,7 @@ class FunctionPodStream(StreamBase): + return ( + self._function_pod, + self._function_pod.argument_symmetry((self._input_stream,)), ++ *drops_extra_columns_suffix(self._function_pod), # PROTOTYPE (O34) + ) + + def pipeline_identity_structure(self) -> Any: +@@ -2283,6 +2323,56 @@ def with_fall_through( + return output + + ++import contextvars # noqa: E402 # PROTOTYPE ++ ++# PROTOTYPE (ITL-1472, O34): the one label appended to a function node's identity ++# tuple when its pod drops data columns its function does not take. ++_O34_LABEL = "drops_extra_columns" ++ ++ ++def drops_extra_columns_suffix(pod: Any) -> tuple[str, ...]: ++ """``(label,)`` when ``pod`` drops extra columns, else ``()``.""" ++ plain = getattr(pod, "_plain_pod", pod) ++ return (_O34_LABEL,) if getattr(plain, "_o34_mark", None) is _O34_LABEL else () ++ ++ ++_O34_LENIENT: contextvars.ContextVar[bool] = contextvars.ContextVar( ++ "o34_lenient", default=False ++) ++ ++ ++def _o34_marked(pod: Any, mode: str, ignored: Any = None) -> Any: ++ """PROTOTYPE (ITL-1472, O34, variant B): ``pod`` with its input mode in its identity. ++ ++ ``O34_MARK`` names the mode that is marked (``lenient`` or ``strict``); the other ++ mode, and every pod when it is unset (variant A), keeps today's identity. ++ """ ++ import copy ++ import os ++ ++ chosen = os.environ.get("O34_MARK") ++ if not isinstance(pod, FunctionPod): ++ return pod ++ if chosen in ("ignored", "bool", "label"): ++ # Marked only where the default mode ignores columns: with the names ++ # ("ignored"), a boolean field ("bool") or, the developer's encoding, one ++ # label appended to the node's identity tuple ("label"). ++ if mode != "lenient" or not ignored: ++ return pod ++ mark: Any = ( ++ ignored if chosen == "ignored" else True if chosen == "bool" else _O34_LABEL ++ ) ++ elif chosen == mode: ++ mark = mode ++ else: ++ return pod ++ marked = copy.copy(pod) ++ marked._content_hash_cache = {} ++ marked._pipeline_hash_cache = {} ++ marked._o34_mark = mark ++ return marked ++ ++ + def function_input_schema(pod: object, input_schema: Schema) -> Schema: + """The part of an input data schema that ``pod``'s function takes.""" + if isinstance(pod, FallThroughPod): +diff --git a/src/orcapod/core/nodes/function_node.py b/src/orcapod/core/nodes/function_node.py +index 9a035305..93e13985 100644 +--- a/src/orcapod/core/nodes/function_node.py ++++ b/src/orcapod/core/nodes/function_node.py +@@ -408,7 +408,50 @@ def run_job_node( + warn_row_failures(summary, caller) + + ++class _O34Narrowed: ++ """PROTOTYPE (ITL-1472, O34): a channel whose rows hold the pod's columns only.""" ++ ++ def __init__(self, channel: Any, pod: Any) -> None: ++ self._channel, self._pod, self._drop = channel, pod, None ++ ++ def __getattr__(self, name: str) -> Any: ++ return getattr(self._channel, name) ++ ++ def __aiter__(self) -> Any: ++ return self._rows() ++ ++ async def _rows(self) -> Any: ++ async for tag, data in self._channel: ++ if self._drop is None: ++ parameters = self._pod.input_data_schema if self._pod else None ++ data_tags = getattr(self._pod, "fall_through_tags", ()) ++ self._drop = ( ++ [] ++ if parameters is None ++ else [ ++ k ++ for k in data.keys() ++ if k not in parameters and k not in data_tags ++ ] ++ ) ++ if len(self._drop) == len(data.keys()): ++ self._drop = [] ++ yield (tag, data.drop(*self._drop) if self._drop else data) ++ ++ + class FunctionNodeBase(StreamBase): ++ def _o34_narrow(self, stream: Any) -> Any: ++ """PROTOTYPE (ITL-1472, O34): ``stream`` as this node's pod reads it.""" ++ from orcapod.core.operators.column_selection import parameter_columns ++ ++ pod = getattr(self, "_function_pod", None) ++ if pod is None: ++ return stream ++ try: ++ return parameter_columns(pod, stream) ++ except Exception: # noqa: BLE001 # a stream that cannot state its schema ++ return stream ++ + """Shared base for ``FunctionNode`` and ``FunctionJobNode``. + + Carries all non-DB state: identity, schema, upstreams, and properties +@@ -460,6 +503,16 @@ class FunctionNodeBase(StreamBase): + # data function's full schema, because ctx is auto-injected per row. + expected_data_schema = function_pod.input_data_schema + # Fall-through columns (ITL-1023) pass by the function. ++ # PROTOTYPE (ITL-1472, O34): columns that are not parameters are ignored. ++ incoming_data_types = type(incoming_data_types)( ++ { ++ k: v ++ for k, v in incoming_data_types.items() ++ if k in expected_data_schema ++ or k in getattr(function_pod, "fall_through_tags", ()) ++ }, ++ optional_fields=incoming_data_types.optional_fields, ++ ) + reason = schema_utils.schema_incompatibility( + function_input_schema(function_pod, incoming_data_types), + expected_data_schema, +@@ -2647,6 +2700,7 @@ class FunctionJobNode(ProvenanceMethods, RunHoldingNode, FunctionNodeBase): + """ + from orcapod.pipeline.observer import NoOpObserver + ++ input_stream = self._o34_narrow(input_stream) # PROTOTYPE (ITL-1472, O34) + if load_only: + return self._output_stream(self._execute_load_only(input_stream, observer)) + if self._function_pod is None: +@@ -4474,6 +4528,7 @@ class FunctionJobNode(ProvenanceMethods, RunHoldingNode, FunctionNodeBase): + """ + from orcapod.pipeline.serialization import LoadStatus + ++ input_channel = _O34Narrowed(input_channel, self._function_pod) # PROTOTYPE + if load_only: + await self._async_execute_load_only(input_channel, output, observer) + return +diff --git a/src/orcapod/core/operators/column_selection.py b/src/orcapod/core/operators/column_selection.py +index cbc6570b..e6d6fab1 100644 +--- a/src/orcapod/core/operators/column_selection.py ++++ b/src/orcapod/core/operators/column_selection.py +@@ -347,6 +347,37 @@ class SelectDataColumns(UnaryOperator): + ) + + ++class _NoTracker: ++ """PROTOTYPE (ITL-1472, O34): records nothing.""" ++ ++ def record_operator_pod_invocation(self, *args: Any, **kwargs: Any) -> None: ++ return None ++ ++ ++class ParameterColumns(SelectDataColumns): ++ """PROTOTYPE (ITL-1472, O34): the columns a function pod reads of its input. ++ ++ Not a step: it is recorded nowhere, and the stream it gives has the identity of ++ its input (``DynamicPodStream`` asks ``TRANSPARENT``). ++ """ ++ ++ TRANSPARENT: ClassVar[bool] = True ++ ++ def __init__(self, columns: str | Collection[str]): ++ super().__init__(columns, strict=True, tracker_manager=_NoTracker()) ++ ++ ++def parameter_columns(pod: Any, stream: Any) -> Any: ++ """PROTOTYPE: ``stream`` as ``pod`` reads it: parameters and fall-through tags.""" ++ _, data_schema = stream.output_schema() ++ parameters = pod.input_data_schema ++ data_tags = getattr(pod, "fall_through_tags", ()) ++ kept = [n for n in data_schema if n in parameters or n in data_tags] ++ if not kept or len(kept) == len(data_schema): ++ return stream ++ return ParameterColumns(kept).process(stream) ++ ++ + class DropTagColumns(UnaryOperator): + """ + Operator that drops specified columns from a stream. +diff --git a/src/orcapod/core/operators/static_output_pod.py b/src/orcapod/core/operators/static_output_pod.py +index f829d44a..7127ae7c 100644 +--- a/src/orcapod/core/operators/static_output_pod.py ++++ b/src/orcapod/core/operators/static_output_pod.py +@@ -1846,6 +1846,8 @@ class DynamicPodStream(StreamBase): + The content hash, unchanged by the note. + """ + self._pod._note_provisional_identity_use() ++ if getattr(self._pod, "TRANSPARENT", False): # PROTOTYPE (ITL-1472, O34) ++ return self._upstreams[0].content_hash(hasher) + return super().content_hash(hasher) + + def pipeline_hash(self, hasher=None) -> ContentHash: +@@ -1858,6 +1860,8 @@ class DynamicPodStream(StreamBase): + The pipeline hash, unchanged by the note. + """ + self._pod._note_provisional_identity_use() ++ if getattr(self._pod, "TRANSPARENT", False): # PROTOTYPE (ITL-1472, O34) ++ return self._upstreams[0].pipeline_hash(hasher) + return super().pipeline_hash(hasher) + + def identity_structure(self) -> Any: +diff --git a/src/orcapod/core/streams/base.py b/src/orcapod/core/streams/base.py +index 9f8b731f..73e28cb8 100644 +--- a/src/orcapod/core/streams/base.py ++++ b/src/orcapod/core/streams/base.py +@@ -761,7 +761,13 @@ class StreamBase(TraceableBase): + + def identity_structure(self) -> Any: + if self.producer is not None: +- return (self.producer, self.producer.argument_symmetry(self.upstreams)) ++ from orcapod.core.function_pod import drops_extra_columns_suffix ++ ++ return ( ++ self.producer, ++ self.producer.argument_symmetry(self.upstreams), ++ *drops_extra_columns_suffix(self.producer), # PROTOTYPE (O34) ++ ) + + raise NotImplementedError("StreamBase.identity_structure") + +diff --git a/src/orcapod/pipeline/base.py b/src/orcapod/pipeline/base.py +index 966809d9..9c8f32e2 100644 +--- a/src/orcapod/pipeline/base.py ++++ b/src/orcapod/pipeline/base.py +@@ -355,6 +355,9 @@ class AbstractPipelineBase(Generic[NodeT], AutoRegisteringContextBasedTracker, A + for upstream, upstream_hash in upstreams: + self._hash_graph.add_edge(upstream_hash, key) + if upstream_hash not in self._source_streams: ++ # PROTOTYPE (ITL-1472, O34): a pod's view of its input is not a leaf. ++ while getattr(getattr(upstream, "producer", None), "TRANSPARENT", False): ++ upstream = upstream.upstreams[0] + self._source_streams[upstream_hash] = upstream + + def _remember_invocation(self, key: str, invocation: PodInvocation) -> None: +diff --git a/src/orcapod/pipeline/pod_invocation.py b/src/orcapod/pipeline/pod_invocation.py +index 5569222d..2816a955 100644 +--- a/src/orcapod/pipeline/pod_invocation.py ++++ b/src/orcapod/pipeline/pod_invocation.py +@@ -76,7 +76,13 @@ class PodInvocation(ContentIdentifiableBase): + This matches the identity structure of the corresponding compiled + node, ensuring hash equality between invocation and node. + """ +- return (self._pod, self._pod.argument_symmetry(self._input_streams)) ++ from orcapod.core.function_pod import drops_extra_columns_suffix ++ ++ return ( ++ self._pod, ++ self._pod.argument_symmetry(self._input_streams), ++ *drops_extra_columns_suffix(self._pod), # PROTOTYPE (ITL-1472, O34) ++ ) + + def pipeline_identity_structure(self) -> Any: + """Return same as ``identity_structure()``.""" diff --git a/docs/dev/specs/itl-1518/store_functions.py b/docs/dev/specs/itl-1518/store_functions.py new file mode 100644 index 000000000..f6a0a245c --- /dev/null +++ b/docs/dev/specs/itl-1518/store_functions.py @@ -0,0 +1,51 @@ +"""Functions of the store measurement (ITL-1518). + +Each call appends a line to the file ``CALLS_FILE`` names, so calls are counted across +processes. +""" + +from __future__ import annotations + +import os + +from orcapod import function_pod + + +def _note(name: str) -> None: + with open(os.environ["CALLS_FILE"], "a") as f: + f.write(name + "\n") + + +@function_pod(output_keys="doubled") +def double(amplitude: float) -> float: + """Return twice ``amplitude``.""" + _note("double") + return 2 * amplitude + + +@function_pod(output_keys="tripled") +def triple(doubled: float) -> float: + """Return three times ``doubled``.""" + _note("triple") + return 3 * doubled + + +@function_pod(output_keys="halved") +def halve(amplitude: float) -> float: + """Return half of ``amplitude``.""" + _note("halve") + return amplitude / 2 + + +@function_pod(output_keys="total") +def add(x: float, y: float) -> float: + """Return ``x + y``.""" + _note("add") + return x + y + + +@function_pod(output_keys="scaled") +def scale(amplitude: float) -> float: + """Return ten times ``amplitude``.""" + _note("scale") + return 10 * amplitude diff --git a/docs/dev/specs/itl-1518/store_run.py b/docs/dev/specs/itl-1518/store_run.py new file mode 100644 index 000000000..5b0200e80 --- /dev/null +++ b/docs/dev/specs/itl-1518/store_run.py @@ -0,0 +1,94 @@ +"""ITL-1518: what one job finds in an existing store, before and after the change. + +Run it on the base code, then again on a tree with ``prototype.patch`` applied, on the +same store directory and with the same ``CALLS_FILE``: + + CALLS_FILE= uv run python docs/dev/specs/itl-1518/store_run.py + O34_MARK=label CALLS_FILE= uv run python docs/dev/specs/itl-1518/store_run.py + +It prints the function calls made by this run, every node with its hashes, and every +table of the store with its row count. +""" + +from __future__ import annotations + +import collections +import os +import sys +import warnings + +import deltalake + +sys.path.insert(0, os.path.dirname(__file__)) + +import store_functions as fns # noqa: E402 # beside this script + +from orcapod import PipelineJob # noqa: E402 +from orcapod.core.sources import DictSource # noqa: E402 +from orcapod.databases import DeltaTableDatabase # noqa: E402 + +warnings.simplefilter("ignore") + + +def src(name: str, columns: tuple[str, ...], tag_only: bool = True) -> DictSource: + """A three-row source with tags ``subject`` and ``t`` and the given data columns.""" + rows = [ + {"subject": s, "t": t, **{c: i + 1.5 + t for i, c in enumerate(columns)}} + for s, t in (("m1", 1), ("m1", 2), ("m2", 3)) + ] + kw = {"tag_only_columns": True} if tag_only else {} + return DictSource(rows, tag_columns=["subject", "t"], source_id=name, **kw) + + +def calls() -> collections.Counter[str]: + """The calls recorded so far, per function.""" + path = os.environ["CALLS_FILE"] + if not os.path.exists(path): + return collections.Counter() + with open(path) as f: + return collections.Counter(f.read().split()) + + +def main() -> None: + store = sys.argv[1] + job = PipelineJob(name="store", database=DeltaTableDatabase(store)) + with job: + wide = src("wide", ("amplitude", "noise", "gain")) + doubled = fns.double.pod(wide, label="double_wide") # extra columns + fns.triple.pod(doubled, label="triple_down") # downstream of it + fns.halve.pod(src("narrow", ("amplitude",)), label="halve_narrow") # none + fns.add.pod( # two inputs, each with an extra column + src("a", ("x", "e1")), src("b", ("y", "e2")), label="add_two" + ) + fns.scale.pod( # data-tags fall through + src("dt", ("amplitude", "noise"), tag_only=False), label="scale_datatags" + ) + before = calls() + job.run() + print("calls in this run:", dict(calls() - before)) + for name, node in sorted(job.nodes.items()): + print( + f" node {name:28s} {type(node).__name__:18s} " + f"c={node.content_hash().to_hex()[:10]} p={node.pipeline_hash().to_hex()[:10]}" + ) + for name in ( + "double_wide", + "triple_down", + "halve_narrow", + "add_two", + "scale_datatags", + ): + table = job.nodes[name].as_table() + print(" rows", name, table.num_rows, sorted(table.column_names)) + print("tables in the store:") + for root, dirs, _ in os.walk(store): + if "_delta_log" in dirs: + n = deltalake.DeltaTable(root).to_pyarrow_table().num_rows + print(f" {n:3d} rows {os.path.relpath(root, store)}") + dirs[:] = [] + sys.stdout.flush() + os._exit(0) # the process otherwise stays alive after the run + + +if __name__ == "__main__": + main() diff --git a/docs/dev/specs/itl-1518/store_run_after.out b/docs/dev/specs/itl-1518/store_run_after.out new file mode 100644 index 000000000..21e8377b2 --- /dev/null +++ b/docs/dev/specs/itl-1518/store_run_after.out @@ -0,0 +1,32 @@ +calls in this run: {} + node Join OperatorJobNode c=e3ae9672aa p=575aeffd15 + node a SourceJobNode c=6b304269b0 p=2581c9c268 + node add_two FunctionJobNode c=31531185c4 p=e867ea781c + node b SourceJobNode c=55e93213ea p=6364a4f9c0 + node double_wide FunctionJobNode c=bd146b465c p=861145e877 + node dt SourceJobNode c=dd5b3e8c0c p=c51ee2adba + node halve_narrow FunctionJobNode c=be73b57e33 p=318c1ac883 + node narrow SourceJobNode c=a6f510eb4b p=2ad9ee7280 + node scale_datatags FunctionJobNode c=9486109a24 p=6f84e5f133 + node triple_down FunctionJobNode c=618133d13f p=25054c1485 + node wide SourceJobNode c=91a19f1691 p=1e11870837 + rows double_wide 3 ['doubled', 'subject', 't'] + rows triple_down 3 ['subject', 't', 'tripled'] + rows halve_narrow 3 ['halved', 'subject', 't'] + rows add_two 3 ['subject', 't', 'total'] + rows scale_datatags 3 ['scaled', 'subject', 't'] +tables in the store: + 3 rows store/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/schema:fca0692262857914d6b5b1e4cfb0098e5ffe1d8ae87390dba6df577dfeedfb2a/pdb_v2 + 3 rows store/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/schema:6f84e5f133dd27788b5da45ad6bd88d2718f612c7764643c54824feeb3dbf37b/pdb_v2 + 3 rows store/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/schema:318c1ac883bb279415261ce754701421cd2823adde5d240975ecb23fe2eec3b0/pdb_v2 + 3 rows store/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/schema:e867ea781c30d57070debb858afd63bda7215903dd715d7f1f700a49b749263c/pdb_v2 + 3 rows store/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/schema:ce5a7f2f151ef8f90ae98e425e161c084f593083ebf484b84ab5c3410a1d1573/pdb_v2 + 3 rows store/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/schema:861145e8778e4b2a0ba0ce818d423e31e22f85407d65bc048a04964a6c0fb1bc/pdb_v2 + 3 rows store/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/schema:aebb47da97fb3ae0ac89f20309fda5574eff277e08d74389d2f3dd0b1af0c484/pdb_v2 + 3 rows store/_result/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/schema:25054c148535bc7cf6e96273e203d2fcb1a1e25a0c23a9dde2005db5ff7df8ef/pdb_v2 + 3 rows store/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/schema:c3976f0dc929f098068f18846192479937f75172d1bc373a7bc5515b14068b7c/pdb_v2 diff --git a/docs/dev/specs/itl-1518/store_run_before.out b/docs/dev/specs/itl-1518/store_run_before.out new file mode 100644 index 000000000..2d3d75750 --- /dev/null +++ b/docs/dev/specs/itl-1518/store_run_before.out @@ -0,0 +1,31 @@ +calls in this run: {'halve': 3, 'scale': 3, 'double': 3, 'add': 3, 'triple': 3} + node Join OperatorJobNode c=e3ae9672aa p=575aeffd15 + node SelectDataColumns_1 OperatorJobNode c=a51f60c1fb p=2fffee0195 + node SelectDataColumns_2 OperatorJobNode c=c830b191d8 p=18354e87fa + node SelectDataColumns_3 OperatorJobNode c=ff5f904585 p=5afc03ca51 + node a SourceJobNode c=6b304269b0 p=2581c9c268 + node add_two FunctionJobNode c=10c94f7f38 p=ce5a7f2f15 + node b SourceJobNode c=55e93213ea p=6364a4f9c0 + node double_wide FunctionJobNode c=b56db9fdeb p=aebb47da97 + node dt SourceJobNode c=dd5b3e8c0c p=c51ee2adba + node halve_narrow FunctionJobNode c=be73b57e33 p=318c1ac883 + node narrow SourceJobNode c=a6f510eb4b p=2ad9ee7280 + node scale_datatags FunctionJobNode c=170f56dfa9 p=fca0692262 + node triple_down FunctionJobNode c=3400d35199 p=c3976f0dc9 + node wide SourceJobNode c=91a19f1691 p=1e11870837 + rows double_wide 3 ['doubled', 'subject', 't'] + rows triple_down 3 ['subject', 't', 'tripled'] + rows halve_narrow 3 ['halved', 'subject', 't'] + rows add_two 3 ['subject', 't', 'total'] + rows scale_datatags 3 ['scaled', 'subject', 't'] +tables in the store: + 3 rows store/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/schema:fca0692262857914d6b5b1e4cfb0098e5ffe1d8ae87390dba6df577dfeedfb2a/pdb_v2 + 3 rows store/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/schema:318c1ac883bb279415261ce754701421cd2823adde5d240975ecb23fe2eec3b0/pdb_v2 + 3 rows store/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/schema:ce5a7f2f151ef8f90ae98e425e161c084f593083ebf484b84ab5c3410a1d1573/pdb_v2 + 3 rows store/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/schema:aebb47da97fb3ae0ac89f20309fda5574eff277e08d74389d2f3dd0b1af0c484/pdb_v2 + 3 rows store/_result/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/schema:c3976f0dc929f098068f18846192479937f75172d1bc373a7bc5515b14068b7c/pdb_v2 diff --git a/docs/dev/specs/itl-1518/store_run_before_again.out b/docs/dev/specs/itl-1518/store_run_before_again.out new file mode 100644 index 000000000..3ebf3ba62 --- /dev/null +++ b/docs/dev/specs/itl-1518/store_run_before_again.out @@ -0,0 +1,31 @@ +calls in this run: {} + node Join OperatorJobNode c=e3ae9672aa p=575aeffd15 + node SelectDataColumns_1 OperatorJobNode c=a51f60c1fb p=2fffee0195 + node SelectDataColumns_2 OperatorJobNode c=c830b191d8 p=18354e87fa + node SelectDataColumns_3 OperatorJobNode c=ff5f904585 p=5afc03ca51 + node a SourceJobNode c=6b304269b0 p=2581c9c268 + node add_two FunctionJobNode c=10c94f7f38 p=ce5a7f2f15 + node b SourceJobNode c=55e93213ea p=6364a4f9c0 + node double_wide FunctionJobNode c=b56db9fdeb p=aebb47da97 + node dt SourceJobNode c=dd5b3e8c0c p=c51ee2adba + node halve_narrow FunctionJobNode c=be73b57e33 p=318c1ac883 + node narrow SourceJobNode c=a6f510eb4b p=2ad9ee7280 + node scale_datatags FunctionJobNode c=170f56dfa9 p=fca0692262 + node triple_down FunctionJobNode c=3400d35199 p=c3976f0dc9 + node wide SourceJobNode c=91a19f1691 p=1e11870837 + rows double_wide 3 ['doubled', 'subject', 't'] + rows triple_down 3 ['subject', 't', 'tripled'] + rows halve_narrow 3 ['halved', 'subject', 't'] + rows add_two 3 ['subject', 't', 'total'] + rows scale_datatags 3 ['scaled', 'subject', 't'] +tables in the store: + 3 rows store/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/schema:fca0692262857914d6b5b1e4cfb0098e5ffe1d8ae87390dba6df577dfeedfb2a/pdb_v2 + 3 rows store/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/schema:318c1ac883bb279415261ce754701421cd2823adde5d240975ecb23fe2eec3b0/pdb_v2 + 3 rows store/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/schema:ce5a7f2f151ef8f90ae98e425e161c084f593083ebf484b84ab5c3410a1d1573/pdb_v2 + 3 rows store/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/schema:aebb47da97fb3ae0ac89f20309fda5574eff277e08d74389d2f3dd0b1af0c484/pdb_v2 + 3 rows store/_result/scale/db2a8dbe19e033421a1e38fe61f32c1ce815934b2b1f2c462fc89c42a7f63929/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/halve/33dee9f51b439bd82359e2cf8d3b1aa722fbaaae212b25d9577f44a816a1b906/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/add/b840ab474a1f0e9bc6e4f33b3536584efc97782c333100f78cc42058c3e9c307/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/double/f741c0fb382f2f9961ea9abbb8fd5fad30eee802c3885b8e54ee267733232525/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/_result/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/rev1/rdb_v1 + 3 rows store/triple/42db866ccb252e53965e707c268d9581c3754970e3b04b4f2a04ec95e2bbba08/v0/python.function.v1/schema:c3976f0dc929f098068f18846192479937f75172d1bc373a7bc5515b14068b7c/pdb_v2 diff --git a/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py b/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py index f5f10c82d..6eca90da1 100644 --- a/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py +++ b/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py @@ -29,7 +29,7 @@ CopyTagsToData = importlib.import_module("exp03_copy_tag_prototype").CopyTagsToData from orcapod import contexts, function_pod -from orcapod.core.nodes.function_node import _build_record_id_preimage +from orcapod.core.row_ids import entry_id_preimage as _build_record_id_preimage from orcapod.operators import MapData COLS = ["session_start", "experiment_start_timestamp"] diff --git a/docs/reference/data-function-types.md b/docs/reference/data-function-types.md index 82017abb1..35b81a9ad 100644 --- a/docs/reference/data-function-types.md +++ b/docs/reference/data-function-types.md @@ -35,7 +35,7 @@ columns): a new result table, and no hash moves. The function's pipeline table carries no revision: ```text -///v/python.function.v1/schema:/pdb_v1 +///v/python.function.v1/schema:/pdb_v2 ``` A saved job names the type and its major only (`"data_function_type_id": @@ -69,7 +69,7 @@ print(describe_pair.pod.uri[-1]) for path in sorted(types_store.list_sources()): print(path[-4:]) # ('v0', 'python.function.v1', 'rev1', 'rdb_v1') -# ('v0', 'python.function.v1', 'schema:...', 'pdb_v1') +# ('v0', 'python.function.v1', 'schema:...', 'pdb_v2') ``` ## The Python function type, `python.function.v1` @@ -148,7 +148,7 @@ print([name for name in stored.column_names if name.startswith("__pf_var_")]) # ['__pf_var_function_name', '__pf_var_function_version', '__pf_var_function_module', '__pf_var_function_signature_hash', '__pf_var_function_content_hash', '__pf_var_git_hash'] ``` -## The pipeline columns, `pdb_v1` +## The pipeline columns, `pdb_v2` A function node's pipeline table stores the input tags and source-info tokens, the input and output hashes, the referenced result record ID, and bookkeeping @@ -156,6 +156,8 @@ for the entry, including: | Column | Arrow type | Nullable | Meaning | |---|---|---|---| +| `__pipeline_instance_id` | `large_binary` | yes | The row's instance id: the hash of its entry id (tags, system tags, input data hash) and the input's source-info tokens. The node looks a row up by it. | +| `__pipeline_record_id` | `large_binary` | yes | The row's record id: the hash of the node's content hash (`__node_content_hash`), its instance id and the id of its result. It is the table's key. | | `__pipeline_run_id` | `large_string` | yes | The ID of the job run that recorded the entry. A node run outside a job stores null. | | `__recorded_at` | `timestamp[us, tz=UTC]` | no | The UTC time the node recorded the entry. | @@ -166,16 +168,52 @@ Reusing a pipeline entry preserves its original run ID and recording time. If the result is lost and the node recomputes it, the new entry has its own run ID and recording time. +A row is named by its record id, the hash of the node's content hash, its +instance id and the id of its result +([the three ids](hashing.md#3-pipeline-db-entry-keys)), stored in +`__pipeline_record_id`; it is the table's key. One table holds the rows of every +node with one pipeline hash, told apart by `__node_content_hash`, and the record +id covers that hash: two such nodes that record one instance with one stored +result have two record ids, and each keeps its row. A row is written unless this node already +stored that record, so the table keeps every distinct record of every node: + +- the same instance recorded again with the same result is one row; +- a recompute has a new result, so it is a new row, and the row recorded last is + the instance's current one; +- an input that arrives with other source-info tokens (its upstream result was + computed again) is a new instance: it gets a new row. Its result is looked up + in the result database by the input data hash: when a result is stored there + the function is not called, and when none is (it was removed, or was an + ephemeral result that is gone) the function is called. + +"Recorded last" is read from `__recorded_at`, the recording process's UTC clock at +the write. So among the records of one instance the current one is the one with +the latest time: a clock set back between two writes of one instance leaves the +earlier record current until a later write. + During a sync run, a repeated identical input without system tags reuses the first entry. During an async run, both copies can be scheduled before either -entry is available, producing two entries with successive recomputation indices. +entry is available; when each then computes its own result, each has its own row. A load-only run writes nothing. Neither recording column enters any hash. -Read these columns on joined records with -`node.get_all_records(columns={"meta": True})` or `node.get_all_records(all_info=True)`. -Pipeline tables written by 0.4.0rc1 through 0.4.0rc3 lack these columns. Rebuild -those tables before appending, even if their rows have been deleted. The layout -name stays `pdb_v1`. +Read the two recording columns (`__pipeline_run_id`, `__recorded_at`) on joined +records with `node.get_all_records(columns={"meta": True})` or +`node.get_all_records(all_info=True)`. The joined records do not hold the two +ids: `__pipeline_instance_id` and `__pipeline_record_id` are columns of the +pipeline table itself, read from the database by the table's path: + +```python +pipeline_path = next(p for p in types_store.list_sources() if p[-1] == "pdb_v2") +pipeline_rows = types_store.get_all_records(pipeline_path) +print([name for name in pipeline_rows.column_names if name.startswith("__pipeline_")]) +# ['__pipeline_instance_id', '__pipeline_record_id', '__pipeline_run_id'] +joined = types_job.nodes["describe"].get_all_records(all_info=True) +print([name for name in joined.column_names if name.startswith("__pipeline_")]) +# ['__pipeline_run_id'] +``` + +Pipeline tables written by a release candidate before the three ids are at the +layout `pdb_v1`: they are reported as tables of another layout and are not read. ## Where it is declared, and how a released declaration is kept diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 6130f2dd5..43770f591 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -27,10 +27,11 @@ appended, because it is a variant of the same system tag mechanism.) | 5 | Per-row `record_id` (system tag value) | the row identifier itself: `row_`, or the canonical JSON of the key columns (`key_row_identifier`) | `str` (`large_string`) | Names the row within its source; stable as long as its position or its key is | | 6 | Join system tag suffix | `stream.pipeline_hash().to_hex(n)` + `:{idx}` appended to column name | Column name suffix | Unique per `(input topology, canonical join position)`; encodes full join lineage in column name | | 6b | Aggregating operator system tag fold | SHA-256 of the canonical JSON list of member values, after the operation's label, for both system tags | `":"` `str`, plus a column name suffix | Deterministic per ordered member set; keeps system tags scalar through a many-to-one reduction | -| 7 | `compute_base_entry_id()` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL)` | `bytes` (`b"method:digest"`) | Unique per `(node, tag lineage, input_data content)` across all recomputation attempts | -| 8 | `compute_pipeline_entry_id()` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL + recomputation_index)` | `bytes` (`b"method:digest"`) | Unique per `(node, tag lineage, input_data content, recomputation attempt)` | -| 9 | Side-effect `record_id` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL + recomputation_index=0)` | `bytes` | Unique per `(tag lineage, input_data content)`; pod-version scoped via table path (`uri` + `pipeline_hash()`) | -| 10 | `invocation_hash` | `f"{serialize(pipeline_hash_ch)}::{serialize(record_id_hash_ch)}"` | `str` | Unique per `(pod topology, tag lineage, input_data content)`; pod-version scoped via table path | +| 7 | Entry id (`row_ids.entry_id`) | `StarfixArrowHasher.hash_table(tags + system_tags + INPUT_DATA_HASH_COL)` | `ContentHash`; stored as `bytes` (`b"method:digest"`) | Unique per `(tag lineage, input_data content)`: an entry of the pipeline table | +| 8 | Instance id (`row_ids.instance_id`) | `StarfixArrowHasher.hash_table(entry id + source-info tokens in name order)` | `ContentHash`; stored as `bytes` | Unique per `(entry, provenance of the input)`: one arrival of an entry; the pipeline table's lookup column | +| 8b | Record id (`row_ids.record_id`) | `StarfixArrowHasher.hash_table(node content hash + instance id + result id)` | `ContentHash`; stored as `bytes` | Unique per `(node, instance, result)`: names a pipeline table row and is the table's key | +| 9 | Side-effect log key | the entry id (site 7) of the delivered row | `bytes` | Unique per `(tag lineage, input_data content)`; pod-version scoped via table path (`uri` + `pipeline_hash()`) | +| 10 | `invocation_hash` | `f"{serialize(pipeline_hash_ch)}::{serialize(entry_id_hash_ch)}"` | `str` | Unique per `(pod topology, tag lineage, input_data content)`; pod-version scoped via table path | | 11 | Output schema hash | `SemanticAwarePythonHasher.hash_object((hash_schema(output Arrow schema),)).to_hex()` | `str` (bare hex digest) | Unique per Arrow schema of the declared outputs; embedded in function URI | | 12 | `run_id` | `uuid.uuid4().hex[:16]` | 16-char hex `str` | Non-deterministic; unique per pipeline execution | | 13 | `snapshot_hash` | `hashlib.sha256(sorted labelled leaf content hashes joined by newline).hexdigest()[:16]` | 16-char hex `str` | Unique per `(DAG leaf topology + data state)` at run time | @@ -98,8 +99,8 @@ Where a hash appears, and in which form: | Form | Where | |---|---| -| Labelled value | `__input_data_hash`, `__output_data_hash`, `__node_content_hash`, `__pipeline_base_entry_id`, the pipeline table's record id, the side-effect log's `record_id` and `record_id_hash`, the record id (`_record_hash`) of operator-node and cached-source tables, the `_content_hash` column, the hashes in a saved job file, `InvocationContext.invocation_hash` | -| Labelled, inside a hash input | a nested hash in a structure: `{"__type__": "hash", "label": "