diff --git a/changelog.d/ITL-1365.md b/changelog.d/ITL-1365.md new file mode 100644 index 000000000..407db7a18 --- /dev/null +++ b/changelog.d/ITL-1365.md @@ -0,0 +1,11 @@ +### Fixed + +- **A stream lists its tags in one order** — for a table not laid out in tag order (a + source over columns `a, b, c, x` with `tag_columns=["c", "b", "a"]`), + `output_schema()` listed the tags in the table's column order while `keys()` and the + rows list them in tag order, so every operator over such a stream predicted its tags in + another order than it produced them (`DropTagColumns(["a"])` predicted `("b", "c")` and + produced `("c", "b")`). The tag schema now follows the tag order, so `output_schema()`, + `keys()`, predicted schemas and rows agree, and a saved job writes its tag schemas in + that order. No row, table column order, stored table, hash or stored path changes, and + a job saved before loads with the same hashes. (ITL-1365) diff --git a/docs/dev/design_issues/ITL-1365-TS1.md b/docs/dev/design_issues/ITL-1365-TS1.md new file mode 100644 index 000000000..5e6f8e9e9 --- /dev/null +++ b/docs/dev/design_issues/ITL-1365-TS1.md @@ -0,0 +1,34 @@ +## Cross-cutting + +### TS1 — A stream's tag schema followed its table layout, not its tag order +**Status:** resolved +**Severity:** medium +**Issue:** ITL-1365 + +`ArrowTableStream` built its tag schema (and its system-tag schema) from its table's +columns in table order, while its `keys()` list the tags in the declared tag order and its +data schema follows `keys()` too. For a table not laid out in tag order (a source over +columns `a, b, c, x` with `tag_columns=["c", "b", "a"]`), `output_schema()[0]` gave +`a, b, c` and `keys()[0]` gave `c, b, a`. Every operator predicts its schema from its +input's `output_schema()`, so its predicted `keys()` and `output_schema()` listed the +tags in another order than its computed result, its rows (sync and async) and its own +input: `DropTagColumns(["a"])` predicted `("b", "c")` and computed `("c", "b")` (192 of +1,536 cases of the reporter's sweep). It was not only `DropTagColumns`: on main almost +every unary operator's predicted keys disagreed with its rows in such a layout +(ITL-1249, symptom A). No value, row, stored table or hash differed: only the order. + +**Fix:** `ArrowTableStream.__init__` builds the tag and system-tag schemas from the tag +columns in tag order, as the data schema already followed the data columns. What +changes for a user: `output_schema()` lists the tags of such a stream (every source kind +over such a table) in tag order, and so does every prediction downstream; a saved job +writes those tag schemas in that order. What does not change, measured by +`docs/dev/scripts/itl1365_tag_schema_order.py` over every source kind and a job before +and after: rows, every table's column order, content and pipeline hashes, source ids, +stored paths and stored column order, and the golden values; a job saved before loads +with the same hashes and stored rows. Part of ITL-1249 is resolved with it, and its +strict expected failures removed: every unary operator's keys now equal its rows' keys, +`Join`, `SemiJoin` and `MergeJoin` give the sync and the async rows one column order, and +`Batch` presents its input's tag order. Left open (ITL-1249): a data-tag that loses its +tag role (`DropTagColumns`, `SelectTagColumns`, `MapTags` with `drop_unmapped` or +`tag_only`, a `GroupBy` non-key) is predicted, and sent on the async path, right after +the data-tags, but sits at its table position in the sync result. diff --git a/docs/dev/scripts/itl1365_tag_schema_order.py b/docs/dev/scripts/itl1365_tag_schema_order.py new file mode 100644 index 000000000..43fb7e81d --- /dev/null +++ b/docs/dev/scripts/itl1365_tag_schema_order.py @@ -0,0 +1,192 @@ +"""ITL-1365: what the tag-schema order fix changes, and what it does not. + +Run on two checkouts (before and after the fix) with the same output folder name in +two places, then compare the two ``summary.json`` files: + + uv run python docs/dev/scripts/itl1365_tag_schema_order.py + uv run python docs/dev/scripts/itl1365_tag_schema_order.py --load + +Every source kind is built over a table laid out ``a, b, c, x, y`` with the tags +declared ``c, b, a`` (``a`` and ``b`` data-tags), plus a raw ``ArrowTableStream``. +For each it records the keys, the ``output_schema`` order, the rows of +``as_table(all_info=True)`` (column names and values), the content and pipeline +hashes and the source id; then a job over it (``DropTagColumns``, ``MapTags`` and a +function pod, on a Delta database), run and saved: every node's hashes, every stored +table path with its column names, the saved job's text; and a standalone ``LOG`` +operator node: its stored table path and columns. With ``--load``, the job saved by +the other checkout is loaded here, against its own database, and its node hashes and +stored rows are recorded too. +""" + +from __future__ import annotations + +import json +import sqlite3 +import sys +import warnings +from pathlib import Path +from typing import Any + +import polars as pl +import pyarrow as pa +import pyarrow.csv as pacsv +from deltalake import write_deltalake + +from orcapod import function_pod +from orcapod.core.nodes import OperatorJobNode +from orcapod.core.operators import DropTagColumns, MapTags +from orcapod.core.sources import ( + ArrowTableSource, + CSVSource, + DataFrameSource, + DeltaTableSource, + DictSource, +) +from orcapod.core.sources.sqlite_table_source import SQLiteTableSource +from orcapod.core.streams import ArrowTableStream +from orcapod.databases import DeltaTableDatabase +from orcapod.pipeline import PipelineJob +from orcapod.types import CacheMode + +warnings.simplefilter("ignore") + +TABLE = pa.table( + { + "a": pa.array([1, 2, 3], pa.int64()), + "b": pa.array(["p", "q", "r"], pa.large_string()), + "c": pa.array([7, 8, 9], pa.int64()), + "x": pa.array([0.5, 1.5, 2.5], pa.float64()), + "y": pa.array(["u", "v", "w"], pa.large_string()), + } +) +TAGS = ["c", "b", "a"] +TAG_ONLY = ["c"] + + +@function_pod(output_keys="z") +def double(x: float | None) -> float | None: + return None if x is None else 2 * x + + +def _sources(root: Path) -> dict[str, Any]: + root.mkdir(parents=True, exist_ok=True) + pacsv.write_csv(TABLE, root / "t.csv") + write_deltalake(str(root / "delta"), TABLE) + db = root / "t.sqlite" + with sqlite3.connect(db) as conn: + _ = conn.execute( + "CREATE TABLE t (a INTEGER PRIMARY KEY, b TEXT, c INTEGER, x REAL, y TEXT)" + ) + _ = conn.executemany("INSERT INTO t VALUES (:a,:b,:c,:x,:y)", TABLE.to_pylist()) + return { + "raw_stream": ArrowTableStream(TABLE, tag_columns=TAGS, data_tags=["a", "b"]), + "arrow_table": ArrowTableSource( + TABLE, tag_columns=TAGS, source_id="s", tag_only_columns=TAG_ONLY + ), + "dict": DictSource( + TABLE.to_pylist(), + tag_columns=TAGS, + source_id="s", + tag_only_columns=TAG_ONLY, + ), + "data_frame": DataFrameSource( + pl.from_arrow(TABLE), + tag_columns=TAGS, + source_id="s", + tag_only_columns=TAG_ONLY, + ), + "csv": CSVSource( + str(root / "t.csv"), + tag_columns=TAGS, + source_id="s", + schema=TABLE.schema, + tag_only_columns=TAG_ONLY, + ), + "delta": DeltaTableSource( + root / "delta", tag_columns=TAGS, source_id="s", tag_only_columns=TAG_ONLY + ), + "sqlite": SQLiteTableSource( + db, "t", tag_columns=TAGS, source_id="s", tag_only_columns=TAG_ONLY + ), + } + + +def _rows(table: pa.Table) -> dict[str, Any]: + return {"columns": table.column_names, "rows": [str(r) for r in table.to_pylist()]} + + +def _stored(database: DeltaTableDatabase) -> dict[str, Any]: + out = {} + for path in sorted(database.list_table_paths()): + table = database.get_all_records(path) + out["/".join(path)] = None if table is None else table.column_names + return out + + +def _job_nodes(job: PipelineJob) -> dict[str, Any]: + return { + label: [str(node.content_hash()), str(node.pipeline_hash())] + for label, node in sorted(job.nodes.items()) + } + + +def main(out: Path, load_from: Path | None) -> None: + summary: dict[str, Any] = {} + for kind, source in _sources(out / "inputs").items(): + entry: dict[str, Any] = { + "keys": source.keys(all_info=True), + "output_schema_order": [ + list(s) for s in source.output_schema(all_info=True) + ], + "table": _rows(source.as_table(all_info=True)), + "content_hash": str(source.content_hash()), + "pipeline_hash": str(source.pipeline_hash()), + "source_id": getattr(source, "source_id", None), + } + if kind != "raw_stream": + database = DeltaTableDatabase(out / "jobs" / kind / "db") + job = PipelineJob(name="itl1365", database=database) + with job: + dropped = DropTagColumns(["a"])(source, label="dropped") + mapped = MapTags({"b": "bb"})(dropped, label="mapped") + double.pod(mapped, label="doubled") + job.run() + job.save(out / "jobs" / kind / "job.json") + entry["job_nodes"] = _job_nodes(job) + entry["job_node_tables"] = { + label: _rows(node.as_table(all_info=True)) + for label, node in sorted(job.nodes.items()) + } + entry["stored"] = _stored(database) + entry["saved_job"] = json.loads( + (out / "jobs" / kind / "job.json").read_text() + ) + op_db = DeltaTableDatabase(out / "jobs" / kind / "opdb") + node = OperatorJobNode( + operator=DropTagColumns(["a"]), + input_streams=[source], + pipeline_database=op_db, + cache_mode=CacheMode.LOG, + ) + node.run() + entry["operator_node"] = [ + str(node.content_hash()), + str(node.pipeline_hash()), + ] + entry["operator_stored"] = _stored(op_db) + if load_from is not None: + other = load_from / "jobs" / kind + loaded = PipelineJob.load( + other / "job.json", database=DeltaTableDatabase(other / "db") + ) + entry["loaded_other_job_nodes"] = _job_nodes(loaded) + entry["loaded_other_stored_rows"] = _rows( + loaded.nodes["doubled"].as_source().as_table(all_info=True) + ) + summary[kind] = entry + (out / "summary.json").write_text(json.dumps(summary, indent=1, default=str)) + + +if __name__ == "__main__": + load = Path(sys.argv[3]) if len(sys.argv) > 3 and sys.argv[2] == "--load" else None + main(Path(sys.argv[1]), load) diff --git a/src/orcapod/core/streams/arrow_table_stream.py b/src/orcapod/core/streams/arrow_table_stream.py index ddac12f03..2fdc1fec6 100644 --- a/src/orcapod/core/streams/arrow_table_stream.py +++ b/src/orcapod/core/streams/arrow_table_stream.py @@ -197,11 +197,20 @@ def __init__( # Respect Arrow nullable flags as-is (after optional inference above): # nullable=True → T | None, nullable=False → T. + # The tag schema lists the tags in tag order, as ``keys()`` does and as the + # data schema follows ``_data_columns``; never in table layout (ITL-1365). + # A declared name the table does not hold (renamed into a system tag, or a + # system tag that is not there) is left out, as before. + names = set(self._table.column_names) tag_schema = pa.schema( - f for f in self._table.schema if f.name in self._tag_columns + self._table.schema.field(name) + for name in dict.fromkeys(self._tag_columns) + if name in names ) system_tag_schema = pa.schema( - f for f in self._table.schema if f.name in self._system_tag_columns + self._table.schema.field(name) + for name in dict.fromkeys(self._system_tag_columns) + if name in names ) all_tag_schema = arrow_utils.join_arrow_schemas(tag_schema, system_tag_schema) data_schema = pa.schema( diff --git a/tests/test_core/data_tags/test_several_items.py b/tests/test_core/data_tags/test_several_items.py index b2b5e4026..79706203d 100644 --- a/tests/test_core/data_tags/test_several_items.py +++ b/tests/test_core/data_tags/test_several_items.py @@ -145,8 +145,8 @@ def test_index_reads_a_list_valued_data_tag_as_a_data_column( first = [data[f"first_{column}"] for _, data in indexed.iter_data()] assert first == {"t1": ["b", "b"], "t3": [1, 2], "d1": [10, 40]}[column] # The data-tag itself is unchanged: still a tag and a data column, with its lists; - # Index keeps its input's tag order as its input presents it (that Batch presents - # the source's tag order is ITL-1249, below), and nothing else depends on the + # Index keeps its input's tag order as its input presents it (Batch presents + # the source's tag order, below), and nothing else depends on the # arrangement. assert presentation(indexed)[0] == presentation(batched)[0] control = Index(column, 0, out=f"first_{column}")( @@ -164,11 +164,7 @@ def test_index_reads_a_list_valued_data_tag_as_a_data_column( ) == rows_fingerprint(list(indexed.iter_data())) -@pytest.mark.xfail( - strict=True, - reason="ITL-1249: an operator presents its output tags in the input table's " - + "physical column order, not in the input stream's tag order", -) +# Resolved by ITL-1365: a stream's tag schema follows its tag order. @pytest.mark.parametrize("role", [DATA_TAGS, MIXED]) def test_batch_presents_its_input_streams_tag_order(role: str) -> None: """The source's tags are (t3, t2, t1); its table holds them as t1, t2, t3.""" diff --git a/tests/test_core/operators/test_several_items.py b/tests/test_core/operators/test_several_items.py index a24d863fd..3c7443897 100644 --- a/tests/test_core/operators/test_several_items.py +++ b/tests/test_core/operators/test_several_items.py @@ -68,7 +68,6 @@ from .several_items import ( DATA_FIRST_REVERSED, DATA_TAGS, - INTERLEAVED, LAYOUTS, MAIN, MIXED, @@ -205,8 +204,7 @@ def test_unary_async_rows_equal_sync_rows_in_every_arrangement( KEYS_XFAIL = pytest.mark.xfail( strict=True, reason=f"{COLUMN_ORDER_ISSUE}: with a table layout other than the tag order, the " - + "result's keys list the tags in the input table's physical order, its rows in " - + "tag order", + + "keys and the sync rows place a demoted data-tag differently", ) ASYNC_ORDER_XFAIL = pytest.mark.xfail( strict=True, @@ -232,12 +230,10 @@ def assert_async_column_order_equals_sync( ) -# Where the column order fails today (ITL-1249), per arrangement. In the reversed layout -# the tags sit in another order than the tag order: every unary result's keys follow -# the table (but ``DropTagColumns(["t3", "t1"])`` of plain tags leaves one tag). With -# data-tags, a tag demoted to data sits elsewhere in the sync rows than in the async -# rows, in the reversed and the interleaved layout. -KEYS_PASS = {("drop_tag_columns", PLAIN)} +# Where the column order fails today (ITL-1249), per arrangement. Since ITL-1365 a +# stream's tag schema follows its tag order, so every result's keys list the tags as its +# rows do. With data-tags, a tag demoted to data sits elsewhere in the sync rows than in +# the keys and the async rows, in the reversed and the interleaved layout. DEMOTED_DATA_TAG_CASES = { ("select_tag_columns", DATA_TAGS), ("drop_tag_columns", DATA_TAGS), @@ -249,9 +245,7 @@ def assert_async_column_order_equals_sync( def _keys_fail(label: str, role: str, layout: str) -> bool: - if layout == DATA_FIRST_REVERSED: - return (label, role) not in KEYS_PASS - return layout == INTERLEAVED and (label, role) in DEMOTED_DATA_TAG_CASES + return layout != TAGS_FIRST and (label, role) in DEMOTED_DATA_TAG_CASES def _async_order_fails(label: str, role: str, layout: str) -> bool: @@ -825,7 +819,7 @@ def _several_input_sources( return op, _sources(specs, order_index, layout, role, rows=rows) -def _several_input_params(fails_in_reversed_layout: bool) -> list[Any]: +def _several_input_params() -> list[Any]: """One parameter per several-input case, role, tag order and layout.""" return [ pytest.param( @@ -834,9 +828,6 @@ def _several_input_params(fails_in_reversed_layout: bool) -> list[Any]: order_index, layout, id=f"{label}/{role}/{order_index}/{layout}", - marks=[ASYNC_ORDER_XFAIL] - if fails_in_reversed_layout and layout == DATA_FIRST_REVERSED - else [], ) for label in SEVERAL_INPUT_CASES for role in ROLES @@ -846,7 +837,7 @@ def _several_input_params(fails_in_reversed_layout: bool) -> list[Any]: @pytest.mark.parametrize( - ("label", "role", "order_index", "layout"), _several_input_params(False) + ("label", "role", "order_index", "layout"), _several_input_params() ) def test_several_input_result_keys_equal_its_row_keys( label: str, role: str, order_index: int, layout: str @@ -855,10 +846,10 @@ def test_several_input_result_keys_equal_its_row_keys( assert_keys_equal_row_keys(op()(*sources)) -# In the reversed layout, Join, SemiJoin and MergeJoin give the sync rows the table's -# tag order and the async rows the tag order (ITL-1249). +# Join, SemiJoin and MergeJoin give the sync and the async rows one column order, also +# in the reversed layout (ITL-1249's case, resolved by ITL-1365). @pytest.mark.parametrize( - ("label", "role", "order_index", "layout"), _several_input_params(True) + ("label", "role", "order_index", "layout"), _several_input_params() ) def test_several_input_async_column_order_equals_sync( label: str, role: str, order_index: int, layout: str diff --git a/tests/test_core/test_tag_schema_order.py b/tests/test_core/test_tag_schema_order.py new file mode 100644 index 000000000..ee22a3e3e --- /dev/null +++ b/tests/test_core/test_tag_schema_order.py @@ -0,0 +1,192 @@ +"""A stream lists its tags in one order: ``keys()`` and ``output_schema()`` agree (ITL-1365). + +``ArrowTableStream`` built its tag schema in the order of its table's columns while its +``keys()`` (and its data schema) follow the declared tag order. Every operator's +predicted schema starts from its input's ``output_schema()``, so for a table not laid +out in tag order a prediction listed the tags in another order than the computed +result: ``DropTagColumns(["a"])`` over tags ``c, b, a`` predicted ``("b", "c")`` and +computed ``("c", "b")``. The tag schema now follows the tag order; no row, table, +stored column order or hash changes (``docs/dev/scripts/itl1365_tag_schema_order.py`` +compares a job before and after). + +The sweep runs every select, drop and map operator over a source with three tags and +three data columns, in every tag order and table layout, with every set of data-tags, +and compares the predicted ``keys()`` and ``output_schema()`` order with +``static_process(...)`` (CLAUDE.md's standing exception), and the tag order of the sync +and the async rows with the prediction. +""" + +from __future__ import annotations + +import itertools +from collections.abc import Callable +from pathlib import Path +from typing import Any + +import pyarrow as pa +import pytest + +from orcapod.core.operators import ( + DropColumns, + DropDataColumns, + DropTagColumns, + MapColumns, + MapData, + MapTags, + SelectColumns, + SelectDataColumns, + SelectTagColumns, +) +from orcapod.core.operators.static_output_pod import StaticOutputOperatorPod +from orcapod.core.sources import ArrowTableSource +from orcapod.core.streams import ArrowTableStream +from orcapod.errors import ProvisionalHashWarning + +from .operators.several_items import MAIN, LAYOUTS, _layout, async_rows +from .test_order_invariance import STREAM_CASES, StreamCase + +pytestmark = [ + pytest.mark.filterwarnings( + f"ignore::{ProvisionalHashWarning.__module__}.{ProvisionalHashWarning.__name__}" + ), + pytest.mark.filterwarnings("ignore::UserWarning"), +] + +CONFIGS: tuple[dict[str, Any], ...] = ( + {}, + {"columns": {"system_tags": True}}, + {"columns": {"source": True, "meta": True, "context": True}}, + {"all_info": True}, +) + + +# ── every source and stream kind ───────────────────────────────────────────── + + +@pytest.mark.parametrize("case", STREAM_CASES, ids=lambda c: c.label) +def test_a_stream_lists_its_tags_in_keys_order( + case: StreamCase, tmp_path: Path +) -> None: + """``output_schema()[0]`` lists the tags in ``keys()[0]`` order, in every layout.""" + for n, (role, order, layout) in enumerate( + itertools.product(case.roles, range(3), LAYOUTS) + ): + folder = tmp_path / str(n) + folder.mkdir() + stream = case.build(role, order, layout, folder) + for config in CONFIGS: + label = f"{role}/{order}/{layout} {config}" + tag_keys = stream.keys(**config)[0] + assert tuple(stream.output_schema(**config)[0]) == tuple(tag_keys), label + + +def test_the_reported_case() -> None: + """Tags ``c, b, a`` over a table laid out ``a, b, c, x``; ``a`` and ``b`` data-tags.""" + table = pa.table({"a": [1, 2], "b": [3, 4], "c": [7, 8], "x": [5.0, 6.0]}) + stream = ArrowTableStream(table, tag_columns=["c", "b", "a"], data_tags=["a", "b"]) + assert tuple(stream.output_schema()[0]) == stream.keys()[0] == ("c", "b", "a") + op = DropTagColumns(["a"]) + assert op(stream).keys() == op.static_process(stream).keys() + assert op(stream).keys()[0] == ("c", "b") + + +# ── select, drop and map operators ─────────────────────────────────────────── + + +def _source(order: tuple[str, ...], layout: str, data_tags: tuple[str, ...]) -> Any: + names = _layout(MAIN, order, layout) + table = pa.table({name: MAIN.columns[name] for name in names}) + return ArrowTableSource( + table, + tag_columns=list(order), + source_id="s", + tag_only_columns=[t for t in order if t not in data_tags], + ) + + +OPERATORS: dict[str, Callable[[], StaticOutputOperatorPod]] = { + "select_tag_columns": lambda: SelectTagColumns(["t3", "t1"]), + "drop_tag_columns_one": lambda: DropTagColumns(["t1"]), + "drop_tag_columns_two": lambda: DropTagColumns(["t3", "t1"]), + "select_data_columns": lambda: SelectDataColumns(["d3", "d1"]), + "drop_data_columns": lambda: DropDataColumns(["d2"]), + "select_columns": lambda: SelectColumns(["t3", "d3", "t1", "d1"]), + "drop_columns": lambda: DropColumns(["d2", "t2"]), + "map_tags": lambda: MapTags({"t3": "u3", "t1": "u1"}), + "map_tags_drop": lambda: MapTags({"t3": "u3", "t1": "u1"}, drop_unmapped=True), + "map_tags_tag_only": lambda: MapTags({"t3": "u3", "t1": "u1"}, tag_only=True), + "map_data": lambda: MapData({"d3": "e3", "d1": "e1"}), + "map_data_drop": lambda: MapData({"d3": "e3", "d1": "e1"}, drop_unmapped=True), + "map_columns": lambda: MapColumns({"t3": "u3", "d1": "e1"}), + "map_columns_drop": lambda: MapColumns( + {"t3": "u3", "t1": "u1", "d1": "e1"}, drop_unmapped=True + ), +} +# MapColumns is refused with data-tags (ITL-1022). +PLAIN_ONLY = {"map_columns", "map_columns_drop"} + +DATA_TAG_SETS = [ + tuple(c) + for n in range(len(MAIN.tags) + 1) + for c in itertools.combinations(MAIN.tags, n) +] + + +def _demoted(stream: Any, result: Any) -> set[str]: + """Data-tags of ``stream`` that are data, but no tag, of ``result``.""" + tags, data = stream.keys() + out_tags, out_data = result.keys() + return {c for c in tags if c in data and c not in out_tags and c in out_data} + + +# MapTags(drop_unmapped=True) predicts no system tags (ITL-1363, fixed by PR 484): +# remove this mark when that fix is on main. +_ITL_1363 = pytest.mark.xfail( + strict=True, + raises=AssertionError, + reason="ITL-1363: MapTags(drop_unmapped=True) predicts no system-tag columns", +) + + +@pytest.mark.parametrize( + "data_tags", DATA_TAG_SETS, ids=lambda d: "+".join(d) or "none" +) +@pytest.mark.parametrize( + "name", + [ + pytest.param(name, marks=_ITL_1363) if name == "map_tags_drop" else name + for name in OPERATORS + ], +) +def test_the_prediction_lists_the_columns_in_the_result_order( + name: str, data_tags: tuple[str, ...] +) -> None: + if name in PLAIN_ONLY and data_tags: + pytest.skip("MapColumns is refused with data-tags (ITL-1022)") + for order in MAIN.tag_orders(): + for layout in LAYOUTS: + source = _source(order, layout, data_tags) + op = OPERATORS[name]() + predicted = op(source) + computed = op.static_process(source) + label = f"{'-'.join(order)}/{layout}" + for config in CONFIGS: + p_tags, p_data = predicted.keys(**config) + c_tags, c_data = computed.keys(**config) + assert p_tags == c_tags, f"{label} {config}" + p_schema = predicted.output_schema(**config) + assert tuple(p_schema[0]) == c_tags, f"{label} {config}" + if _demoted(source, computed): + # A data-tag that loses its tag role keeps its data column at its + # table position in the result and right after the data-tags in + # the prediction (ITL-1249): the names agree here. + assert sorted(p_data) == sorted(c_data), f"{label} {config}" + else: + assert p_data == c_data, f"{label} {config}" + assert tuple(p_schema[1]) == c_data, f"{label} {config}" + # The rows, sync and async, list their tags in the predicted order. + tags = predicted.keys()[0] + for tag, _ in computed.iter_data(): + assert tuple(tag.keys()) == tags, label + for tag, _ in async_rows(op, source): + assert tuple(tag.keys()) == tags, label