Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 14 additions & 1 deletion .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ data. The rules:
to large_list, recursively). Width, nullability and logical (extension) types are never
changed; int8 stays int8, and null stays null (operators and the type converter pass
keep_null=True; only Data maps null to large_string, the function's default). An
operator that round-trips through Polars casts its columns back
operator that round-trips its columns through Polars casts them back
to the normalized input types (arrow_utils.restore_column_types, or
restore_schema_nullability when nullability is restored too).
This holds for every operator, also one that passes its rows through unchanged (select,
Expand Down Expand Up @@ -1200,6 +1200,19 @@ data. The rules:
- DerivedSource over a job node with nothing stored → presents zero rows with the origin's columns
(no computed records; no error), in the plain form and with tags_as_data.
- Join requires non-overlapping data columns; raises InputValidationError on collision.
- `Join` and `SemiJoin` give Polars only their key columns and row numbers (ITL-1284): Polars
decides which rows match, and every output column is taken from the input tables by row
number (`take`), so every value is the input's, bit for bit (they used to carry every column
through Polars: a `date64` off midnight came back at midnight, a `decimal256` made Polars
panic). Keys are prepared in one place, `core/operators/arrow_keys.py` (`polars_ready`: a
logical type as its storage, a dictionary decoded, a temporal value as its integer, `float16`
as `float32`, a view as its large variant, `decimal256` as four 64-bit limbs, through lists,
fixed-size lists and structs; `part_without_rule` says what may reach Polars). A key whose
type has no rule (a map, an interval, a union, a list view) is refused with
`InputValidationError` naming the column (`base.require_matchable_key`) on both paths,
before rows are matched (never at validation, which would derive every input's zero-row
table on each graph build). `GroupBy` keeps its own copy of the preparation until ITL-1281, which also
moves `MergeJoin` off its round trip.
- MergeJoin requires colliding data columns to have identical Python types; merges into sorted
large_list<T> with source columns reordered to match, where T is the large-normalized input
Arrow type; inputs whose Arrow types still differ after normalization raise
Expand Down
15 changes: 14 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ data. The rules:
to `large_list`, recursively). Width, nullability and logical (extension) types are never
changed; `int8` stays `int8`, and `null` stays `null` (operators and the type converter pass
`keep_null=True`; only `Data` maps `null` to `large_string`, the function's default). An
operator that round-trips through Polars casts its columns back
operator that round-trips its columns through Polars casts them back
to the normalized input types (`arrow_utils.restore_column_types`, or
`restore_schema_nullability` when nullability is restored too).
This holds for every operator, also one that passes its rows through unchanged (select,
Expand Down Expand Up @@ -1244,6 +1244,19 @@ data. The rules:
- `DerivedSource` over a job node with nothing stored → presents zero rows with the origin's columns
(no computed records; no error), in the plain form and with `tags_as_data`.
- Join requires non-overlapping data columns; raises `InputValidationError` on collision.
- `Join` and `SemiJoin` give Polars only their key columns and row numbers (ITL-1284): Polars
decides which rows match, and every output column is taken from the input tables by row
number (`take`), so every value is the input's, bit for bit (they used to carry every column
through Polars: a `date64` off midnight came back at midnight, a `decimal256` made Polars
panic). Keys are prepared in one place, `core/operators/arrow_keys.py` (`polars_ready`: a
logical type as its storage, a dictionary decoded, a temporal value as its integer, `float16`
as `float32`, a view as its large variant, `decimal256` as four 64-bit limbs, through lists,
fixed-size lists and structs; `part_without_rule` says what may reach Polars). A key whose
type has no rule (a map, an interval, a union, a list view) is refused with
`InputValidationError` naming the column (`base.require_matchable_key`) on both paths,
before rows are matched (never at validation, which would derive every input's zero-row
table on each graph build). `GroupBy` keeps its own copy of the preparation until ITL-1281, which also
moves `MergeJoin` off its round trip.
- MergeJoin requires colliding data columns to have identical Python types; merges into sorted
`large_list<T>` with source columns reordered to match, where `T` is the large-normalized input
Arrow type; inputs whose Arrow types still differ after normalization raise
Expand Down
19 changes: 19 additions & 0 deletions changelog.d/ITL-1284.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Breaking changes and migration

- **`Join` and `SemiJoin` refuse a join key whose type has no rule for matching** (a map,
an interval, a union, a list view, or a list or struct holding one) with
`InputValidationError` naming the column, on both the sync and the async path (when
rows are matched; also by `head()` of a stream with no rows). Before, the sync path
failed with an error from Polars or Arrow, while the async path matched such keys. Join
on other tags (drop the tag from one input, `drop_tag_columns`). (ITL-1284)

### Fixed

- **`Join` and `SemiJoin` emit every value exactly on the sync path.** Polars now only
decides which rows match, from the prepared join keys and row numbers; every output
column is taken from the input's Arrow tables. Before, every column went through Polars
and back: a `date64` value off midnight came back at midnight (as data and as a key, in
a list and in a struct), and a `decimal256` column made Polars panic, ending the process;
a map or interval data column failed. The sync path now agrees with the async path for
these types. Results change only for inputs holding such values; no golden value moves.
(ITL-1284)
12 changes: 10 additions & 2 deletions docs/concepts/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ Takes one or more streams. Used for `Join`, which performs an N-ary inner join.
N-ary inner join on shared tag columns. Requires that input streams have non-overlapping
data columns (raises `InputValidationError` on collision). Join is **commutative** -- the
order of input streams does not affect the result. Like every operator, Join drops its
inputs' meta (`__`-prefixed) columns, so they never collide. Rows match on equality of every shared tag column, whatever
its type (lists and structs compare element by element). A row with a null in any shared tag
inputs' meta (`__`-prefixed) columns, so they never collide. Rows match on equality of every shared tag column
(lists and structs compare element by element). A row with a null in any shared tag
column matches nothing, a null list or struct included, and rows with null on both sides do
not match each other (the SQL convention for nulls; `MergeJoin` and `SemiJoin` follow it too, on the sync and the async path, while `GroupBy` is the exception by design and puts null keys in one group); a null *inside* a list or struct is an ordinary element that equals
another null, an empty list is not a null, and NaN equals NaN. The async path gives the same
rows.

`Join` and `SemiJoin` keep every value exactly: each output column is taken from the inputs
as it is, bit for bit (a `time64[ns]` keeps its nanoseconds, a `date64` its time of day, a
`decimal256` its 76 digits), and a data column of any Arrow type passes through. A shared tag
column must be a type they can compare: an integer, float, decimal, boolean, string, binary,
date, time, timestamp or duration, a logical type stored as one, or a list or struct of
those. A key that holds a map, an interval or a union is refused with `InputValidationError`
naming the column; drop it from one input (`drop_tag_columns`) to join on the other tags.

Because a null key matches nothing, a shared tag column may differ between the inputs in
nullability alone: `T` in one input and `T | None` in another is accepted by `Join`, `MergeJoin`
and `SemiJoin`. In the output of `Join` and `MergeJoin` the column is `T` when any input has it
Expand Down
30 changes: 30 additions & 0 deletions docs/dev/design_issues/ITL-1284-SJ4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## `src/orcapod/core/operators/semijoin.py` — nested columns and string/large_string keys

### SJ4 — `Join` and `SemiJoin` (sync) changed values by carrying every column through Polars
**Status:** resolved
**Severity:** critical
**Issue:** ITL-1284 (related: ITL-1250, ITL-1281)

The sync paths of `Join` (`static_process`) and `SemiJoin` (`binary_static_process`)
joined `pl.DataFrame(table)` with the other input and converted the result back to Arrow,
then cast it to the input types. Every column went through Polars, and Polars changes or
refuses some Arrow types on the way: a `date64` value off midnight came back at midnight
(1 ms became 0 ms), as data and as a key, in a list and in a struct; a `decimal256` column,
at the top level or nested, made Polars panic ("operator does not support primitive
`Int256`"), which no caller can catch; a map or interval column, even as data only, failed.
Key matching was correct. The async paths do not use Polars and were exact, so the two
paths disagreed for these types.

**Fix:** Polars only decides which rows match. It is given the key columns, prepared by
`core/operators/arrow_keys.py` (the one place: a logical type as its storage, a dictionary
decoded, a temporal value as its integer, `float16` as `float32`, a view as its large
variant, `decimal256` as four 64-bit limbs, through lists, fixed-size lists and structs),
and row numbers; every output column is taken from the input tables by those row numbers
(`take`), so every value is the input's, bit for bit, and a data column of any type passes
through. A key whose type has no rule there (a map, an interval, a union, a list view) is
refused with `InputValidationError` naming the column (`base.require_matchable_key`) on
both paths, before rows are matched, never passed to Polars. Output layout, row order, system
tags, key nullability and the type-disagreement refusals are unchanged; no golden value
moves. Tests: `tests/test_core/operators/test_join_arrow_values.py` and the
`*_exact_values` cases of `test_async_sync_equivalence.py`. `GroupBy` keeps its own copy
of the preparation until ITL-1281; `MergeJoin` is ITL-1281.
Loading
Loading