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
8 changes: 8 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,14 @@ data. The rules:
key that is a list of any kind (a fixed-size list included) is refused as list-valued. `Batch` and `MergeJoin` still rebuild their lists from Python
(ITL-1281). The stance on `0.0`/`-0.0` and NaN for the whole library (match by value, as
Polars does; show the smallest bit pattern; rewrite nothing) is ITL-1251.
- The presentation order (`arrow_utils.sort_by_tag_columns`: `as_table(columns={"sort_by_tags": True})`,
`head().sort_by_tags()`, the preview) is ascending by the tags, then the system tags, nulls
last at every depth: a null list element or struct field after the values beside it, as
`GroupBy` orders a list and Arrow a struct (ITL-1295). Arrow sorts when it can; for a list
tag (or a struct holding one) Polars orders the prepared keys only
(`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
Expand Down
8 changes: 8 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,14 @@ data. The rules:
key that is a list of any kind (a fixed-size list included) is refused as list-valued. `Batch` and `MergeJoin` still rebuild their lists from Python
(ITL-1281). The stance on `0.0`/`-0.0` and NaN for the whole library (match by value, as
Polars does; show the smallest bit pattern; rewrite nothing) is ITL-1251.
- The presentation order (`arrow_utils.sort_by_tag_columns`: `as_table(columns={"sort_by_tags": True})`,
`head().sort_by_tags()`, the preview) is ascending by the tags, then the system tags, nulls
last at every depth: a null list element or struct field after the values beside it, as
`GroupBy` orders a list and Arrow a struct (ITL-1295). Arrow sorts when it can; for a list
tag (or a struct holding one) Polars orders the prepared keys only
(`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
Expand Down
8 changes: 8 additions & 0 deletions changelog.d/ITL-1295.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@
`decimal256` tag, the second run crashing the process. Now only the bookkeeping columns
pass through Polars, and every value is taken from the stored tables. No hash, entry id
or stored table changes. (ITL-1295)
- **A read sorted by tags shows every value as it is.** When a tag is a list (or a struct
holding one), `as_table(columns={"sort_by_tags": True})` and `head().sort_by_tags()`
sorted the whole table with Polars, so a `date64` value showed at midnight and a
`decimal256` value crashed the process. Now only the tags are compared and every value is
the stream's own. The notebook preview orders its rows the same way, but it still renders
them through Polars, so a `decimal256` column it shows still crashes it (ITL-1302). A null inside a list or a struct now sorts after the values beside it,
as a null tag sorts last (it used to sort first), so rows with such tags can appear in
another order. (ITL-1295)
12 changes: 11 additions & 1 deletion docs/concepts/streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ only what is readily available, never compute, poll or deliver a row (they read
code (a function, a predicate, a side effect) and never write to a database. `run()` computes
(see "Computing a stream outside a job" below).

Tag order is ascending by the tag columns, in the stream's tag order. Rows with equal tags
are ordered by their system tags (their source ids and record ids) by a read that has them:
`as_table(columns={"sort_by_tags": True})`, `head(n, columns={"sort_by_tags": True})` and
the preview. `head().sort_by_tags()` and a view's `sort_by_tags()` have no system tags, so
they keep such rows in the order the view holds them (see "Computing a stream outside a job" below).
A null goes last, and so does a null inside a list or a struct: a list tag is ordered
element by element (a shorter list first when it is the start of a longer one), a struct
field by field. Sorting moves whole rows and never changes a value: every value shown is
the stream's own, whatever its Arrow type.

With no rows to show, a head still has the columns and Arrow types the rows would have. To
learn them it applies each operator to empty (zero-row) tables, which processes no data: a
chain of N operators applies up to N operators to empty tables (about 60 ms for 20). A filter
Expand Down Expand Up @@ -237,7 +247,7 @@ What each kind of object shows:
sorting included, and applies it to the rows it has before taking the first `n`. The default
does not sort, as `as_table()` does not, so `head()` shows rows in the order the stream
holds them. The notebook preview asks for the sorted head, so it shows the same rows
whatever order they were computed in. With `sort_by_tags=True`, or `all_info=True`, rows are
whatever order they were computed in. With `columns={"sort_by_tags": True}`, or `all_info=True`, rows are
sorted by tag first (nulls last; rows with equal tags are ordered by their system tags):

```python
Expand Down
21 changes: 16 additions & 5 deletions docs/dev/design_issues/ITL-1295-FN3.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ also names takes `_right`), and the rows of a cross-session ephemeral miss are r
the pipeline table. For every type Polars held exactly the result is what it was:
columns, order, names, types, nullability, rows (`docs/dev/scripts/itl_1295/dump_reads.py`
compares two checkouts). No hash, entry id, stored path or column moves. Tests:
`tests/test_pipeline/test_function_node_stored_values.py`. Remaining: the sort fallback of
`arrow_utils.sort_by_tag_columns` (list and struct tags, `as_table(sort_by_tags=True)`,
`head().sort_by_tags()`) still sorts through Polars; it needs the key preparation of
`core/operators/arrow_keys.py` (ITL-1284) and is the second part of ITL-1295 (strict
expected failures name it).
`tests/test_pipeline/test_function_node_stored_values.py`.

**Fix (part 2):** the sort every presentation uses (`arrow_utils.sort_by_tag_columns`:
`as_table(columns={"sort_by_tags": True})`, `head().sort_by_tags()`, the notebook preview) fell back to
sorting the whole table with Polars when Arrow could not sort it (a list tag, or a struct
holding one), with the same losses. Now Polars orders only the prepared tag columns and row
numbers (`arrow_keys.polars_key_frame`, `arrow_keys.sort_key`) and the rows are taken from
the table. Nulls go last at every depth: a null list element or struct field after the
values beside it, as `GroupBy` orders a list and as Arrow orders a struct (so a struct tag
orders the same with or without a list tag beside it); before, Polars put them first. That
is the only order that moves (`docs/dev/scripts/itl_1295/compare_sort_fallback.py`
compares main's order with the new one). A tag type with no rule (a map, an interval, a
union, a list view) raises `TypeError` naming the column instead of a Polars error. Tests:
`tests/test_core/streams/test_sort_by_tags_values.py`. Not fixed here: the notebook
preview renders its rows through Polars, which panics on a `decimal256` column whatever
the sort (strict expected failures in that file).
Loading
Loading