Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0bf5e72
test(operators): several columns, names, mappings and inputs, in ever…
Nov 18, 2026
03f4a26
test(sources, function_pod, pipeline): several tags, keys, inputs and…
Nov 18, 2026
e8ae621
test(operators): async rows equal sync rows in every several-input ca…
Nov 18, 2026
f40e1af
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
8129cfa
test(operators): issue ids for the defects found (ITL-1243, ITL-1247)…
Nov 18, 2026
86a99fc
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
ec9c140
test(operators): type the results helper by Mapping (ITL-1236)
Nov 18, 2026
7217f5c
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
aa7fa71
test(operators): column order of sync rows, async rows and keys, per …
Nov 18, 2026
b66ee60
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
ea4814f
test(sources, pipeline): compare key orders with each other; check bo…
Nov 18, 2026
d896a18
test(operators): ITL-1249 for the column order xfails; an operator no…
Nov 18, 2026
fb75b54
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
e1800eb
test(operators): one column-order test per arrangement, xfail only wh…
Nov 18, 2026
4bf0e18
Merge branch 'eywalker/itl-1236-tests-audit-every-argument-that-takes…
Nov 18, 2026
3702e65
test(function_pod, sources, pipeline): weighted outputs, async arrang…
Nov 18, 2026
91c49ec
Merge remote-tracking branch 'origin/main' into eywalker/itl-1236-par…
Nov 18, 2026
54708fe
test(sources): compare whole record ids with canonical JSON built fro…
Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion docs/dev/specs/itl-1236-several-item-test-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Legend: **yes** (with the best test as evidence), **no** (with what the closest
| 3 | `MergeJoin` raises `TypeError` on a null in a colliding column | error only | ITL-1243 |
| 4 | Swapping `output_keys` keeps the function's uri, so a job serves stored values under swapped names | result cache: wrong values served | ITL-1244 (rule undecided) |
| 5 | Binding a source with mixed tag roles in another column order is accepted, then the source node's `as_table` raises | error on read; the run is right | ITL-1245 |
| 6 | A function pod over data-tags (`FallThroughPod`) hashes its fall-through tags in the input's tag order: two sources that differ only in tag order give the function node another content and pipeline hash | pipeline hash, pipeline table path | ITL-1246 |
| 7 | Input whose table layout differs from its tag order: every unary operator's result keys list the tags in the physical order while its rows use the tag order; Join, SemiJoin, MergeJoin (and, with data-tags, the tag select/drop and `MapTags` forms) give the async rows another column order than the sync rows. In a job, an operator node stores one column order on both orchestrators (measured, tested) | column order only; no hash, no stored table | ITL-1249 |
| Q1 | `PolarsFilter`: the order of the predicates is in the identity (and the stored path); the order of the constraints is not | pipeline hash | ITL-1247 (rule undecided) |

Expand All @@ -122,9 +123,27 @@ Order- or role-dependent behaviour that reaches a hash or a stored table first.
14. `DerivedSource(tags_as_data=)` reversed: default `source_id` and pipeline hash.
15. `CachedSource` over a data-tag source; `Pick` / `Index` from a data-tag with `out=`; schema arguments in another field order; the stream methods' several-argument forms (`polars_filter` with `constraint_map` and keywords).

## Checked and found as documented (part 2)

- A source's `tag_columns` order and table layout: keys follow the tag order; rows, record
ids, system tags, content and pipeline hashes do not change (plain, data-tags, mixed).
- `tag_only_columns` given in two orders: no change.
- `record_id_columns` in another key order: record ids follow the key order; the content
hash changes, the pipeline hash and the source id do not; a set is refused.
- `DerivedSource(tags_as_data=)` reversed: only the new columns' order changes.
- `CachedSource` over a source of each role and arrangement: reads back as the source.
- `pod(a, b, c)` in every input order: same rows, hashes and columns; a job over the inputs
in another order finds every result stored (sync and async). The in-memory output's
source info names a fresh random record per computation, so comparisons leave it out.
- `bind(sources=)` with two sources: both bound, nothing moves; one refused, neither bound.
A plain or data-tag source in any arrangement binds and reads; a mixed one is ITL-1245.

## Tests added

`tests/test_core/operators/several_items.py` is the shared family: `MAIN` (tags `t1`,
`t2`, `t3`; data `d1`, `d2`, `d3`) and join partners `P`, `Q`, `R`, each in any tag order,
three layouts and three role settings. `ops/test_several_items.py` uses it for every
operator (gaps 5, 6, 7, 9, 11 and the operator half of 1, 2, 3).
operator (gaps 5, 6, 7, 9, 11 and the operator half of 1, 2, 3). Part 2:
`tests/test_core/sources/test_several_items.py` (gaps 4, 13, 14, 15: CachedSource),
`tests/test_core/function_pod/test_several_items.py` (gaps 1, 10; ITL-1244, ITL-1246) and
`tests/test_pipeline/test_bind_several_items.py` (gap 8; ITL-1245).
244 changes: 244 additions & 0 deletions tests/test_core/function_pod/test_several_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
"""Function pods over several inputs, reading several parameters, with several outputs (ITL-1236).

The rules tested:

* ``pod(a, b, c)`` joins its inputs as ``Join`` does, so the order of the inputs changes
nothing: rows, hashes, system-tag names and column order, in memory and in a job (a
second job over the inputs in another order finds every result stored).
* Data columns that the function does not read are dropped by the automatic select
(ITL-807), whatever their number and position.
* The function's parameters are matched by name, never by position.
* A data-tag is a data column a function may read (ITL-1023).
"""

from __future__ import annotations

import itertools

import pytest

from orcapod import PipelineJob, function_pod
from orcapod.core.sources import ArrowTableSource
from orcapod.databases import InMemoryArrowDatabase
from orcapod.pipeline.async_orchestrator import AsyncPipelineOrchestrator
from orcapod.pipeline.sync_orchestrator import SyncPipelineOrchestrator

from ..operators.several_items import (
DATA_TAGS,
LAYOUTS,
MAIN,
MIXED,
ROLES,
TAGS_FIRST,
Arrangement,
P,
Q,
Spec,
fingerprint,
make_source,
presentation,
rows_fingerprint,
)

INPUTS: tuple[Spec, ...] = (MAIN, P, Q)


# Parameters in another order than the columns: q2 is in Q, d1 in MAIN, p1 in P.
@function_pod(output_keys=["total", "product"])
def combine(q2: int, d1: int, p1: int) -> tuple[int, int]:
# Weighted: no two parameters can be swapped without changing ``total``.
return q2 + 2 * d1 + 3 * p1, d1 * p1


def _inputs(role: str) -> list[ArrowTableSource]:
return [
make_source(spec, Arrangement(spec.tags, TAGS_FIRST, role)) for spec in INPUTS
]


@pytest.mark.parametrize("role", ROLES)
def test_the_order_of_the_inputs_changes_nothing(role: str) -> None:
"""All six orders of three inputs: same rows, hashes and columns.

Each in-memory computation names a fresh record in its outputs' source info, so the
rows are compared without it.
"""
results = {}
for permutation in itertools.permutations(range(len(INPUTS))):
inputs = _inputs(role)
stream = combine.pod(*(inputs[i] for i in permutation))
results[permutation] = {
**fingerprint(stream, source_info=False),
"presentation": presentation(stream),
}
first = results[(0, 1, 2)]
for permutation, result in results.items():
assert result == first, permutation
# The extra data columns (d2, d3, p2, q1) were dropped; every tag stays.
tag_keys, data_keys = first["presentation"]
assert sorted(tag_keys) == ["t1", "t2", "t3"]
assert {"d2", "d3", "p2", "q1"}.isdisjoint(data_keys)
assert {"total", "product"} <= set(data_keys)


@pytest.mark.parametrize("role", ROLES)
def test_values_are_matched_by_parameter_name(role: str) -> None:
stream = combine.pod(*_inputs(role))
rows = sorted(
(tag["t1"], tag["t2"], tag["t3"], data["total"], data["product"])
for tag, data in stream.iter_data()
)
# MAIN x P on (t1, t2) x Q on (t2, t3); total = q2 + 2 d1 + 3 p1, product = d1 p1.
assert rows == [
("a", 1, 1, 400 + 2 * 50 + 3 * 9, 50 * 9),
("a", 1, 2, 100 + 2 * 20 + 3 * 9, 20 * 9),
("a", 2, 1, 200 + 2 * 30 + 3 * 7, 30 * 7),
("b", 1, 2, 100 + 2 * 40 + 3 * 8, 40 * 8),
("b", 2, 1, 200 + 2 * 10 + 3 * 6, 10 * 6),
("b", 2, 2, 300 + 2 * 60 + 3 * 6, 60 * 6),
]


@pytest.mark.parametrize(
"orchestrator",
[SyncPipelineOrchestrator, AsyncPipelineOrchestrator],
ids=["sync", "async"],
)
@pytest.mark.parametrize("role", ROLES)
def test_a_job_over_the_inputs_in_another_order_finds_every_result_stored(
role: str, orchestrator: type
) -> None:
database = InMemoryArrowDatabase()
stored = {}
for permutation in ((0, 1, 2), (2, 0, 1), (1, 2, 0)):
inputs = _inputs(role)
job = PipelineJob(name="several", database=database)
with job:
combine.pod(*(inputs[i] for i in permutation), label="combine")
summary = job.run(orchestrator=orchestrator())
node = job.nodes["combine"]
stored[permutation] = (
rows_fingerprint(list(node.iter_data()), source_info=False),
node.pipeline_hash(),
node.content_hash(),
presentation(node),
)
if permutation != (0, 1, 2):
assert summary.nodes["combine"].computed == 0, permutation
assert summary.nodes["combine"].reused == 6, permutation
first = stored[(0, 1, 2)]
assert all(result == first for result in stored.values())


@function_pod(output_keys="labelled")
def label_rows(t1: str, d3: str, t3: int) -> str:
return f"{t1}{t3}{d3}"


@pytest.mark.parametrize("role", [DATA_TAGS, MIXED])
def test_a_function_reads_several_data_tags_and_data_in_any_arrangement(
role: str,
) -> None:
"""t1 and t3 are data-tags; the tag order and layout change no row."""
results = {}
for order in MAIN.tag_orders():
for layout in LAYOUTS:
stream = label_rows.pod(make_source(MAIN, Arrangement(order, layout, role)))
results[(order, layout)] = rows_fingerprint(
list(stream.iter_data()), source_info=False
)
Comment thread
eywalker marked this conversation as resolved.
Resolved
values = sorted(str(data["labelled"]) for _, data in stream.iter_data())
assert values == ["a1v", "a1y", "a2x", "b1w", "b2u", "b2z"]
first = next(iter(results.values()))
assert all(result == first for result in results.values())


@pytest.mark.parametrize("layout", LAYOUTS)
@pytest.mark.parametrize("order", MAIN.tag_orders(), ids="-".join)
@pytest.mark.parametrize("role", [DATA_TAGS, MIXED])
def test_a_function_over_several_data_tags_gives_the_same_rows_on_both_orchestrators(
role: str, order: tuple[str, ...], layout: str
) -> None:
"""In a job, sync and async: same rows, column order and stored results."""
tables = []
for orchestrator in (SyncPipelineOrchestrator, AsyncPipelineOrchestrator):
job = PipelineJob(name="labels", database=InMemoryArrowDatabase())
with job:
label_rows.pod(
make_source(MAIN, Arrangement(order, layout, role)), label="labels"
)
job.run(orchestrator=orchestrator())
node = job.nodes["labels"]
tables.append(
(
presentation(node),
[(tuple(t.keys()), tuple(d.keys())) for t, d in node.iter_data()],
rows_fingerprint(list(node.iter_data()), source_info=False),
sorted(str(data["labelled"]) for _, data in node.iter_data()),
)
)
assert tables[0] == tables[1]
assert tables[0][3] == ["a1v", "a1y", "a2x", "b1w", "b2u", "b2z"]


@pytest.mark.parametrize("role", [DATA_TAGS, MIXED])
def test_a_layout_of_the_input_does_not_change_a_fall_through_pods_hashes(
role: str,
) -> None:
hashes = {
layout: fingerprint(
label_rows.pod(make_source(MAIN, Arrangement(MAIN.tags, layout, role))),
source_info=False,
)
for layout in LAYOUTS
}
first = next(iter(hashes.values()))
assert all(result == first for result in hashes.values())


FALL_THROUGH_ORDER_ISSUE = "ITL-1246"


@pytest.mark.xfail(
strict=True,
reason=f"{FALL_THROUGH_ORDER_ISSUE}: the fall-through tags enter the pod's "
+ "identity in the input's tag order",
)
@pytest.mark.parametrize("role", [DATA_TAGS, MIXED])
def test_the_tag_order_of_the_input_does_not_change_a_fall_through_pods_hashes(
role: str,
) -> None:
results = {
order: fingerprint(
label_rows.pod(make_source(MAIN, Arrangement(order, TAGS_FIRST, role))),
source_info=False,
)
for order in MAIN.tag_orders()
}
first = next(iter(results.values()))
assert all(result == first for result in results.values())


OUTPUT_KEYS_ISSUE = "ITL-1244 (rule undecided)"


@pytest.mark.xfail(
strict=True,
reason=f"{OUTPUT_KEYS_ISSUE}: the order of output_keys is not in the identity",
)
def test_swapped_output_keys_are_another_function() -> None:
"""Swapped output keys map the results to other names: not the same function.

Today both have one uri, so a job serves one's stored values under the other's
names.
"""

def make(keys: list[str]):
@function_pod(output_keys=keys)
def stats(d1: int, t2: int) -> tuple[int, int]:
return d1 + t2, d1 * t2

return stats

forward, backward = make(["sum", "product"]), make(["product", "sum"])
assert forward.pod.uri != backward.pod.uri
29 changes: 22 additions & 7 deletions tests/test_core/operators/several_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,35 @@ def make_source(
)


def row_fingerprint(tag: TagProtocol, data: DataProtocol) -> tuple[str, ...]:
"""What identifies one row regardless of column order: values, system tags, hashes."""
def row_fingerprint(
tag: TagProtocol, data: DataProtocol, *, source_info: bool = True
) -> tuple[str, ...]:
"""What identifies one row regardless of column order: values, system tags, hashes.

Args:
tag: The row's tag.
data: The row's data.
source_info: Include the data's source info. A function's in-memory output
names a fresh random record per computation, so a comparison of two
computations leaves it out.
"""
return (
repr(sorted(tag.as_dict().items())),
repr(sorted(data.as_dict().items())),
repr(sorted(tag.system_tags().items())),
tag.content_hash().to_string(),
data.content_hash().to_string(),
repr(sorted(data.source_info().items())),
repr(sorted(data.source_info().items())) if source_info else "",
)


def rows_fingerprint(rows: Sequence[Row]) -> list[tuple[str, ...]]:
def rows_fingerprint(
rows: Sequence[Row], *, source_info: bool = True
) -> list[tuple[str, ...]]:
"""The rows' fingerprints, sorted: row order is not part of it."""
return sorted(row_fingerprint(tag, data) for tag, data in rows)
return sorted(
row_fingerprint(tag, data, source_info=source_info) for tag, data in rows
)


def ordered_rows_fingerprint(rows: Sequence[Row]) -> list[tuple[str, ...]]:
Expand All @@ -256,19 +270,20 @@ def ordered_rows_fingerprint(rows: Sequence[Row]) -> list[tuple[str, ...]]:
)


def fingerprint(stream: StreamProtocol) -> dict[str, Any]:
def fingerprint(stream: StreamProtocol, *, source_info: bool = True) -> dict[str, Any]:
"""What must not depend on the input's arrangement or a set argument's order.

Args:
stream: An operator's result.
source_info: Include each row's source info (see ``row_fingerprint``).

Returns:
The rows (``rows_fingerprint``), the content and pipeline hashes, and the
sorted column names of the tag group (system tags included) and the data group.
"""
tag_keys, data_keys = stream.keys(columns={"system_tags": True})
return {
"rows": rows_fingerprint(list(stream.iter_data())),
"rows": rows_fingerprint(list(stream.iter_data()), source_info=source_info),
"content_hash": stream.content_hash().to_string(),
"pipeline_hash": stream.pipeline_hash().to_string(),
"tag_names": sorted(tag_keys),
Expand Down
Loading
Loading