From b20d3b0292d56f5f78273fea96d448546d8f3487 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Wed, 18 Nov 2026 15:22:33 -0800 Subject: [PATCH 1/8] fix(derived_source): tags_as_data copies in the order of their new names (ITL-1271) The mapping names a set of copies. Its identity was already sorted; the copies were placed in the order the mapping was given. They now follow the origin's data columns in the order of their new names, so the mapping's order changes neither the columns, their order, nor any hash. Moves no hash (golden --check: all match). Co-Authored-By: Claude Opus 5.5 --- docs/concepts/sources.md | 3 ++ src/orcapod/core/sources/derived_source.py | 6 ++- .../test_derived_source_tags_as_data.py | 38 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/concepts/sources.md b/docs/concepts/sources.md index a695bd1b4..0bacbab15 100644 --- a/docs/concepts/sources.md +++ b/docs/concepts/sources.md @@ -437,6 +437,9 @@ before. Things to know: - The mapping is `{tag column: new data column}`. The new name must not already be a column and must not start with `_`; a wrong name raises `InputValidationError` when the source is built. +- The copies follow the origin's data columns, in the order of their new names. The mapping + names a set of copies: the order you give it in changes neither the columns, their order, + nor any hash. - The copy has exactly the tag's type, including whether it may be null. If the tag may be null, annotate the function parameter as optional (`datetime | None`). - The copy equals the tag when the source is read. After that it is ordinary data: a function diff --git a/src/orcapod/core/sources/derived_source.py b/src/orcapod/core/sources/derived_source.py index b12a92b6b..ec4d35764 100644 --- a/src/orcapod/core/sources/derived_source.py +++ b/src/orcapod/core/sources/derived_source.py @@ -266,7 +266,11 @@ def __init__( ) self._tags_as_data: dict[str, str] | None = None else: - self._tags_as_data = dict(tags_as_data) + # The mapping names a set of copies: they are placed in the order of their + # new names, so the order it is given in changes nothing (ITL-1271). + self._tags_as_data = dict( + sorted(tags_as_data.items(), key=lambda item: item[1]) + ) tag_keys, data_keys = origin.keys() validate_tags_as_data(self._tags_as_data, tag_keys, data_keys) kwargs.setdefault("data_context", origin.data_context_key) diff --git a/tests/test_core/sources/test_derived_source_tags_as_data.py b/tests/test_core/sources/test_derived_source_tags_as_data.py index 6e346bb67..2f1337a39 100644 --- a/tests/test_core/sources/test_derived_source_tags_as_data.py +++ b/tests/test_core/sources/test_derived_source_tags_as_data.py @@ -11,6 +11,7 @@ from __future__ import annotations import datetime as dt +import itertools import sqlite3 from contextlib import closing from pathlib import Path @@ -27,6 +28,8 @@ from orcapod.types import ColumnConfig from orcapod.sources import ArrowTableSource, DictSource, SQLiteTableSource +from ..operators.several_items import MAIN, TAGS_FIRST, Arrangement, make_source + UTC = dt.timezone.utc TS = pa.timestamp("us", tz="UTC") S1 = dt.datetime(2026, 1, 5, 9, 0, tzinfo=UTC) @@ -822,3 +825,38 @@ def test_zero_row_source_origin(self): assert copy_field.type == pa.large_string() assert copy_field.nullable is False assert list(derived.iter_data()) == [] + + +# ── the order of the mapping (ITL-1271) ───────────────────────────────────── + + +@pytest.mark.parametrize("roles", ["plain", "data_tags", "mixed"]) +def test_the_order_of_the_mapping_changes_nothing_not_even_the_column_order( + roles: str, +) -> None: + """Three copies in every mapping order: one identity, one table, copies in name order. + + The mapping names a set of copies: its identity was already sorted; the copies are + placed after the origin's data columns in the order of their new names, so the + mapping's order changes neither the columns nor their order (ITL-1271). + """ + origin = make_source(MAIN, Arrangement(MAIN.tags, TAGS_FIRST, roles)) + # The new names sort in another order than the tags they copy. + items = (("t1", "z1"), ("t2", "y2"), ("t3", "x3")) + results = set() + for order in itertools.permutations(items): + source = DerivedSource(origin, tags_as_data=dict(order)) + tag_keys, data_keys = source.keys() + assert data_keys[-3:] == ("x3", "y2", "z1") + table = source.as_table(all_info=True) + results.add( + ( + source.content_hash().to_string(), + source.pipeline_hash().to_string(), + tag_keys, + data_keys, + tuple(table.column_names), + tuple(map(str, table.to_pylist())), + ) + ) + assert len(results) == 1 From 5d13aebef852eb4524546a66fb6bac68c1e5efc0 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" <> Date: Wed, 18 Nov 2026 15:29:23 -0800 Subject: [PATCH 2/8] fix(polling_source): its identity holds the tag columns in name order (ITL-1271) PollingSource's identity was (impl.identity(), tag_columns, key_columns) with the tag columns in declared order, so declaring them in another order gave another content hash (and every downstream content hash) for the same source. They now enter sorted; the key columns keep their order, the explicit order of the record id. The default source id, pipeline hash, rows and record ids were already order-free. Moves no pinned hash (golden --check: all match; the one pinned PollingSource has a single tag and pins its source id only). Co-Authored-By: Claude Opus 5.5 --- docs/reference/hashing.md | 2 +- src/orcapod/core/sources/polling_source.py | 9 +++- tests/test_channels/test_polling_source.py | 54 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 02a5059a0..b7d987b9f 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -522,7 +522,7 @@ The table below shows what each class returns from `identity_structure()`. | `DerivedSource` | Origin node's `content_hash` | Inherits its generating node's identity | | `DerivedSource` with `tags_as_data` | `(class_name, output_schema, source_id, key_columns, ("tags_as_data", sorted items))`; the default `source_id` is `tags_as_data: