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
dfa0ede
docs(specs): design a range restriction for SpiralDBTableSource (ITL-…
eywalker Nov 25, 2026
066b284
docs(specs): record the range conformance probe and the decisions (IT…
eywalker Nov 25, 2026
f45de63
docs(specs): record the decisions, the float probe and the plan (ITL-…
eywalker Nov 26, 2026
f35f6b7
Merge remote-tracking branch 'origin/main' into eywalker/itl-998-spir…
eywalker Nov 26, 2026
de64ef2
test(spiraldb): ranges in a source's where, and the canonical saved o…
eywalker Nov 26, 2026
1adf709
feat(spiraldb): restrict a SpiralDBTableSource read to a range of a c…
eywalker Nov 26, 2026
939a145
docs(spiraldb): ranges in where, findings and the changelog fragment …
eywalker Nov 26, 2026
4970d7a
Merge remote-tracking branch 'origin/main' into eywalker/itl-998-spir…
eywalker Nov 26, 2026
d411519
fix(spiraldb): no truth test of a condition; a chained comparison in …
eywalker Nov 26, 2026
77d75ed
fix(spiraldb): where refuses a float equality to -0.0 or NaN (ITL-998)
eywalker Nov 26, 2026
b707743
fix(spiraldb): every column name as a where keyword, exact timestamp …
eywalker Nov 26, 2026
a89fc9d
test(spiraldb): the fake keeps a timestamp literal as its count (ITL-…
eywalker Nov 26, 2026
c98b010
fix(spiraldb): every equality compared locally holds; live unit is th…
eywalker Nov 26, 2026
ca5378b
fix(spiraldb): reject inexact float equality values (ITL-1480)
eywalker Nov 26, 2026
95a0d42
fix(spiraldb): preserve logical float restriction types
eywalker Nov 26, 2026
c4b4ad7
docs(spiraldb): clarify range bounds and float equality
eywalker Nov 26, 2026
259c52f
docs(spiraldb): record provisional where API and float decisions (ITL…
eywalker Nov 27, 2026
476381d
docs(spiraldb): merge provisional where guidance from PR 574
eywalker Nov 27, 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
12 changes: 8 additions & 4 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1486,11 +1486,15 @@ data. The rules:
not; never Python's ==, which ignores fold within one tzinfo), with a consistent hash.
That equality decides whether two restrictions are one, never which rows a source returns:
a condition is pushed down as column == value and the table system's equality decides
(developer, November 19, 2026: a NaN, an infinity or a signed zero is accepted, pushed down
and documented, never filtered on the client or refused; a NaN or infinite value is saved
as {"float": "nan" | "inf" | "-inf"}); text()/str, and
(developer, November 19, 2026: an infinity or a zero is accepted, pushed down and
documented, never filtered on the client; a NaN or infinite value is saved as
{"float": "nan" | "inf" | "-inf"}). For now, SpiralDB where refuses equality to -0.0 or a NaN
(developer, November 27, 2026), checked on the arguments as given, before merging. SpiralDB
matches them by their bits, so the rows read would depend on which of two equal values was
kept. Float ranges are also refused for now (ITL-1477). Revisit the float refusals in
ITL-1480. The condition has text()/str and
to_config/from_config (the saved where mapping). Internally terms (column, operator,
value), equality only today; the public surface names no operator. Never add a second
value), including equalities and supported ranges. Never add a second
restriction class: a limit stays the source's own (limit=). Today only
SpiralDBTableSource.where(mapping=None, /, **columns) exists: Condition.of, then the
source checks it against its table (unknown column, the column's exact Python type and
Expand Down
12 changes: 8 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1534,11 +1534,15 @@ data. The rules:
not; never Python's `==`, which ignores `fold` within one tzinfo), with a consistent hash.
That equality decides whether two restrictions are one, never which rows a source returns:
a condition is pushed down as `column == value` and the table system's equality decides
(developer, November 19, 2026: a NaN, an infinity or a signed zero is accepted, pushed down
and documented, never filtered on the client or refused; a NaN or infinite value is saved
as `{"float": "nan" | "inf" | "-inf"}`); `text()`/`str`, and
(developer, November 19, 2026: an infinity or a zero is accepted, pushed down and
documented, never filtered on the client; a NaN or infinite value is saved as
`{"float": "nan" | "inf" | "-inf"}`). For now, SpiralDB where refuses equality to -0.0 or a NaN
(developer, November 27, 2026), checked on the arguments as given, before merging. SpiralDB
matches them by their bits, so the rows read would depend on which of two equal values was
kept. Float ranges are also refused for now (ITL-1477). Revisit the float refusals in
ITL-1480. The condition has `text()`/`str` and
`to_config`/`from_config` (the saved `where` mapping). Internally terms (column, operator,
value), equality only today; the public surface names no operator. Never add a second
value), including equalities and supported ranges. Never add a second
restriction class: a limit stays the source's own (`limit=`). Today only
`SpiralDBTableSource.where(mapping=None, /, **columns)` exists: `Condition.of`, then the
source checks it against its table (unknown column, the column's exact Python type and
Expand Down
6 changes: 6 additions & 0 deletions changelog.d/ITL-1480.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Fixed

- For now, SpiralDB table restrictions reject equality values that a float column
cannot hold exactly when `where()` is called. For example, a `float32` equality to
`0.1` raises `TypeError` at the call. ITL-1480 tracks revisiting this refusal. The
SpiralDB test fake now matches NaNs by their bit patterns, as the service does.
29 changes: 29 additions & 0 deletions changelog.d/ITL-998.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Added

- `SpiralDBTableSource.where(...)` and `where=` take ranges of integer, timestamp and date
columns, written with `col` as in `filter`: `events.where(col("timestamp") >= start,
col("timestamp") < stop)`, and `col(c).between(a, b)` (both ends included). SpiralDB
applies them in the scan, with any equalities; all must hold. A range is a restriction:
no hash, source id, schema or record id changes. Bounds are checked like equality values
and never converted, rounded or clamped. Ranges of string, binary and boolean columns
are refused. Float ranges are refused for now (ITL-1477). Use `filter` for these ranges.
Source range restrictions are available only on `SpiralDBTableSource` (ITL-1219).
- `SpiralDBTableSource.where` takes several conditions as positional arguments, as `filter`
and `Condition.of` do: mappings and conditions, plus keywords.

### Changed

- A condition made only of equalities (a source's `where`, a `Filter`) is saved with its
columns in canonical order, as a condition with other terms already was: `where(b=1,
a=2)` and `where(a=2, b=1)` save the same bytes. Saved jobs and configs written before
load to the same condition; their bytes change only when two or more columns had been
given out of that order. No hash, stored path or identity reads a saved condition.
- The `where` parameter of `SpiralDBConnector.scan_batches` is PROVISIONAL and takes a
`Condition` (equalities and ranges). To pass a mapping, wrap it in `Condition.of(...)`.
- For now, `SpiralDBTableSource.where(...)` and `where=` refuse an equality of a float
column to `-0.0` or a NaN (`TypeError`, pointing to `filter`). SpiralDB matches them by their bits,
while Orcapod counts `-0.0` equal to `0.0` and NaN equal to NaN, so the rows read could
depend on which of two equal values a condition kept. ITL-1480 tracks revisiting the float
refusals.
- A condition that requires two different values of one column in `where` now raises
`ValueError` ("already restricted"), as across chained calls, rather than `TypeError`.
12 changes: 3 additions & 9 deletions docs/concepts/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,15 +880,9 @@ print(recorded.filter(col("t") >= 1.0).head(3).as_table().num_rows)
# 2
```

**`where` and `filter`.** A source that can restrict what it reads (`where`, see
[Restricting a source](sources.md#restricting-a-source-versus-filtering-in-the-pipeline)) takes the same equalities. The two give the
same rows, except on a float column for a NaN or a signed zero (`where` uses the table
system's equality, `filter` Orcapod's: a NaN may match no row under `where` and matches the
NaN rows under `filter`) and on a source with a `limit` (the limit then counts the matching
rows). `where` is not a step of the pipeline: it changes no hash, while `filter` is a
node whose condition enters the identity of every step after it. Explore with `where`; keep
the selection with `filter` when it becomes part of what the pipeline computes. `where`
takes only equalities today and refuses any other condition, pointing to `filter`.
**`where` and `filter`.** `SpiralDBTableSource.where` restricts the rows read from the source.
`filter` adds a pipeline node whose condition enters the identity of every step after it.
For supported equalities and ranges, see [Restricting a source](sources.md#restricting-a-source-versus-filtering-in-the-pipeline).

**What is read, and what is applied after reading.** `stream.explain()` (new in this
release) says, for every source a stream reads, what the source applies itself (its `where`
Expand Down
122 changes: 83 additions & 39 deletions docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ print(first.row_count_estimate) # rows in the whole table; reads every key to c

- `limit=n` reads the first `n` rows in key order.
- `where={column: value, ...}` reads the rows in which every named column equals its value
(`source.where(...)` adds conditions to a built source; see
(`source.where(...)` adds conditions to a built source, and also takes ranges of integer,
timestamp and date columns, such as a window of time; see
[Restricting a source versus filtering in the pipeline](#restricting-a-source-versus-filtering-in-the-pipeline)).
- `asof=` reads the table as of an earlier version, and keeps reading it. Without it, a
source reads the version the table had when the source was built, in every read, until a
Expand Down Expand Up @@ -444,8 +445,45 @@ same rows. The conditions are a `Condition` (`orcapod.types`): `where(...)` buil
given instead (`events.where(Condition.of(unit_id=106, session_index=2))`). A source
restricted by a condition, a `limit=`, or both is **restricted**. Every source states its
restriction through two read-only properties: `condition` (the empty `Condition` when it
reads every row) and `row_limit` (`None` without a limit). A restriction is not an
operator:
reads every row) and `row_limit` (`None` without a limit).

**Ranges.** Source range restrictions are available only on `SpiralDBTableSource` (other
sources are tracked in ITL-1219). `where` takes a range of an integer, timestamp or date
column, written with `col` as in `filter`. A half-open window, `>= start` and `< stop`, lets
adjacent windows meet without gaps or overlaps. `col(c).between(a, b)` includes both ends.

The `timestamp` column in this example stores microsecond counts as `uint64`. An Arrow
timestamp column takes `datetime` bounds, aware when the column has a time zone and naive
when it has none.

<!-- docs-test: skip -->
```python
from orcapod import col

hour = 3_600_000_000
first_hour = events.where(col("timestamp") >= 0, col("timestamp") < hour)
second_hour = events.where(col("timestamp") >= hour, col("timestamp") < 2 * hour)
one_unit = first_hour.where(unit_id=106) # a range and an equality
```

Ranges and equalities all must hold, on one column or several, given in one call or across
chained calls in any order: the order never changes the rows, the condition or how it is
saved. Ranges that cannot all hold are kept and read no row. A null meets no range. SpiralDB
applies a range in the scan, so only the window's rows are transferred, and the row cap
counts them. A bound is checked as an equality value is: exactly of the column's Python type
(`int`, `datetime`, `date`), held exactly by its Arrow type (`-1` is refused for an unsigned
column, a microsecond for `timestamp[s]`, a naive `datetime` for a zoned column), never
converted, rounded or clamped. Ranges of strings, binary values, booleans and other
unsupported types are refused, as are conditions such as `is_in`, null tests, `!=`,
comparisons between columns, `|`, and `~`.

Use `filter` for float ranges. Orcapod evaluates `filter` after the read, treating `0.0` and
`-0.0` as equal and all NaNs as one value ordered after every number. `where` pushes the
condition into SpiralDB, whose IEEE 754 total order puts `-0.0` below `0.0`. For example,
`filter(col("x") >= 0.0)` keeps rows with `-0.0`. SpiralDB would drop those rows if it
applied the same condition. `where` refuses float ranges for now (ITL-1477).

A restriction is not an operator:

- An operator (`Filter`, `SemiJoin`, `PolarsFilter`) is a step of the pipeline. It is a node of the
graph and part of the pipeline's identity: a pipeline with a filter computes something
Expand All @@ -465,9 +503,11 @@ identities and reused by the full run. Use an operator when selecting rows is pa
the pipeline computes. Restrict on tag (key) columns where you can; a condition on a data
column is allowed.

`where` and `stream.filter` take the same equalities, written the same way, and keep the same
rows (for a float column, `where` uses the table system's own equality for NaN and `-0.0`,
`filter` Orcapod's: see [Filter](operators.md#filter)). One spelling differs: `filter` takes
`where` and `stream.filter` accept the same equality syntax. For float columns, `where`
uses SpiralDB's equality and, for now, refuses a value the column cannot hold exactly.
`where(x=0.0)` selects positive zero only. For now, `where` also refuses `-0.0` and NaN.
ITL-1480 tracks revisiting these refusals. See [Filter](operators.md#filter) for
Orcapod's equality rules. `filter` takes
`label=` (the step's label, as every stream method does), so a column named `label` is written
`filter({"label": "x"})` or `filter(col("label") == "x")`, while `where(label="x")` restricts
that column. Neither takes `None` as a value: both raise `ValueError` and point to
Expand All @@ -484,7 +524,7 @@ explore = events.where(unit_id=106, session_index=2)
# The pipeline: the same selection as a step, part of every downstream identity.
kept = events.filter(unit_id=106, session_index=2)

# Anything but equality is a filter; where refuses it and points to filter.
# Use a filter for conditions such as is_in that where cannot apply.
late = events.filter(col("spike_time_us") >= 1_000_000, col("unit_id").is_in([106, 107]))
```

Expand All @@ -497,10 +537,9 @@ timestamp columns, on a source without a `limit`. With a `limit` it does not: th
reads the first rows that match the `where`, so the `filter` sees other rows than it would
over the source alone (with `limit=2` and unit ids `[1, 2, 2]`, `filter(unit_id=2)` alone
keeps one row, the `where` and the `filter` together keep two). On a float column it does
not either when the value is a NaN or a signed zero:
`where` matches by the table system's equality (a NaN may match no row), `filter` by
Orcapod's (a NaN matches the NaN rows), so `where` can drop rows the `filter` alone would
keep. For such a value, filter without the `where`.
not either when the value is `0.0`: `where` matches by the table system's equality (`0.0`
does not match `-0.0`), `filter` by Orcapod's (it does), so `where` can drop rows the `filter`
alone would keep. For such a value, use `filter` on its own.

<!-- docs-test: skip -->
```python
Expand Down Expand Up @@ -561,40 +600,45 @@ print(Condition.of(day=day, started=started, recorded=recorded))

- **One mechanism.** `where()` adds to the conditions given with `where=` (a mapping or a
`Condition`) when the source was built (`Condition.combined`), and SpiralDB applies them
in the scan. A column already restricted to another value
is refused, as is a column the table does not have, `None` (a null equals nothing) and
in the scan. If you call `SpiralDBConnector.scan_batches` directly, its PROVISIONAL
`where` parameter takes a `Condition`. Use `Condition.of(...)` to wrap a mapping.
A column already restricted to another value is refused, as is a column the table
does not have, `None` (a null equals nothing) and
`where()` with no condition. Everything else of the source is carried over: the pinned
table version, `limit`, `max_rows`, the tags and data-tags, `tags_as_data`, the key
columns, the source id and the label. The original source is not changed.
- **No conversion.** A value must be exactly of its column's Python type: an `int` for an
integer column (not `True`, not `1.0`, not a NumPy scalar: use `.item()`), a `float` for a
float column, a `datetime.date` for a date column and a `datetime.datetime` for a timestamp
column (not a string; see below), and it must fit the column's Arrow type. A timestamp
column with a time zone takes an aware `datetime`, one without a zone a naive `datetime`.
Anything else raises `TypeError`, naming the column and both types. Columns of other types
(lists, structs) take no condition.
- **Exact values.** An integer column takes a Python `int`, a float column takes a Python
`float`, a date column takes a `datetime.date`, and a timestamp column takes a
`datetime.datetime`. A float column without a logical type also takes a Python `int`.
A timestamp column with a time zone takes an aware `datetime`.
A timestamp column without a zone takes a naive `datetime`. To use a NumPy scalar,
call `.item()` first. For float equality, `where()` currently raises `TypeError` at the
call if the column's Arrow type cannot hold the value exactly. For example, on a
`float32` column, `where(x=0.5)` is valid and `where(x=0.1)` raises. ITL-1480 tracks
revisiting this refusal. Lists and structs take no condition.
- **The table system's equality.** Each condition is sent to SpiralDB as `column == value`,
and which rows it selects is SpiralDB's own equality, not Orcapod's. For a float column, NaN
selects the NaN rows and `0.0` does not select the `-0.0` rows (seen on the service, not
documented by it). A value that no `float32` is exactly, such as `0.1`, selects no row of a
`float32` column. SpiralDB cannot compare a `float16` column, so Orcapod reads the rows the
and which rows it selects is SpiralDB's own equality, not Orcapod's. For a float column,
`0.0` does not select the `-0.0` rows (seen on the service, not documented by it). An
equality to `-0.0` or a NaN raises `TypeError` for now and points to `filter`. SpiralDB matches
them by their bits, while Orcapod counts `-0.0` equal to `0.0` and NaN equal to NaN, so
the rows read would depend on which of two equal values a condition kept. ITL-1480 tracks
revisiting the float refusals. SpiralDB cannot compare a `float16` column, so Orcapod reads the rows the
other conditions select and compares them itself, by the same rule and before `limit`. To
select rows by such values as Orcapod matches them, filter
inside the pipeline (`PolarsFilter`). A NaN or infinite value is saved as
`{"float": "nan"}`, `{"float": "inf"}` or `{"float": "-inf"}`, since JSON has no such number.
- **One restriction per table in a pipeline.** A restricted source has the unrestricted
source's identity, so a pipeline holds one restriction (or none) per source: building a
pipeline in which one table is read with two different restrictions (or with and without
one) raises `ValueError` instead of silently reading one of them, whatever streams lead to
the table: different column selections or operator chains, streams built before the
pipeline, a `CachedSource` or a `SourceProxy` bound to it. It is checked from what each
stream reads at that moment: when the pipeline is built, when it is compiled, by `bind`
before it binds (a slot bound to a stream over a table another slot reads) and when a run
starts. Use one restriction per pipeline, or build separate pipelines.
inside the pipeline (`PolarsFilter`). An infinite value is saved as `{"float": "inf"}` or
`{"float": "-inf"}`, since JSON has no such number.
- **One restriction per source identity in a pipeline.** Restrictions are equal by statement.
On an integer column, `t >= 3` and `t > 2` select the same rows but count as two
restrictions. A restriction leaves the `source_id` and `content_hash` unchanged, so reading
one table under two windows with the same source identity in one pipeline raises
`ValueError`. Give each window its own `source_id` to use both in the same pipeline. The
same check covers restricted and unrestricted reads of one source identity, including
reads through projections, operator chains, and source wrappers. It runs at pipeline
construction, compilation, binding, and the start of each run.
- **With `limit=`.** A source built with `limit=n` reads the first `n` rows that match, in
key order: the conditions are applied first.
- **Conditions as values.** Two conditions are equal when they require the same columns to
equal the same values, in any order. Values of different types differ (`1`, `True` and
- **Conditions as values.** Equality compares the columns, operators and values in any
order. Values of different types differ (`1`, `True` and
`1.0`); floats compare as Orcapod matches them (`0.0` equals `-0.0`, NaN equals NaN); an
aware `datetime` is its instant, so one instant written in two zones is one value, and the
two 01:30 of a daylight-saving overlap (`fold`) are two. This equality decides whether two
Expand Down Expand Up @@ -637,8 +681,8 @@ print(Condition.of(day=day, started=started, recorded=recorded))
- **Stored rows stay.** A run over a restricted source deletes nothing: a job node shows the
rows of its current run, and `node.as_source()` shows everything stored for it.

`where()` is a copy of the source with the restriction applied to the copy; a later version
offers the two steps on their own, and restrictions on other kinds of source.
`where()` copies the source and applies the restriction to the copy. ITL-1219 tracks exposing
the two steps separately and extending restrictions to other source types.

**Running again.** A run first checks the source: when the table has a newer version (rows
added since the source was built or last checked), the source reads that version from then
Expand Down
Loading
Loading