Skip to content

feat(condition): a boolean column is a condition; ~col(c) is its negation - #673

Merged
eywalker merged 2 commits into
mainfrom
eywalker/bool-column-filter
Nov 30, 2026
Merged

eywalker merged 2 commits into
mainfrom
eywalker/bool-column-filter

Conversation

@eywalker

@eywalker eywalker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes ITL-1777

What

stream.filter(col("flag")) keeps the rows where the boolean column flag is true, and stream.filter(~col("flag")) the rows where it is false. A null is neither true nor false, so a row with a null is kept by neither, as conditions already state (Kleene logic).

Design: no new condition kind

A bare reference given where a condition is taken is the existing equality:

Written Is the condition
col("flag") (or col("flag").is_true()) col("flag") == True
~col("flag") col("flag") == False
  • Identity. The Filter identity is ("Filter", condition.canonical_form()), as before. filter(col("flag")), filter(col("flag") == True) and filter(flag=True) are one condition with one hash. ~col("flag") is filter(flag=False), so it differs from the plain form. No new tree node, canonical form or saved form exists. The order of &/| operands and of arguments never counts, because the existing canonical form sorts them (tested).
  • Saved form. {"flag": true} / {"flag": false}, or the tree form when combined. It reads back as the same condition.
  • Combining. ColumnRef gains __invert__, __and__/__rand__ and __or__/__ror__, and Condition.__and__/__or__ accept a ColumnRef. Condition.of (so filter, Filter and where) accepts a bare ColumnRef positionally. Anything else (& True, | "x") is still refused. not col(c) and col(a) and col(b) still raise (no truth value).
  • Refusal. A column that is not boolean is refused when the condition meets the stream (at graph build for a Filter, from the stream's Python schema; for a struct field, when applied; at where() for SpiralDB). The existing value-type error gains a hint: "A bare col(c) stands for col(c) == True and ~col(c) for col(c) == False: both take a boolean column only". The type is never known when col() is built, so validation time is the earliest point.
  • SpiralDB where. The two forms are the equalities flag == True / flag == False that check_restriction already accepts. The connector already sends them as sp.eq(column, literal(bool)), which keeps no null row. That is exactly Orcapod's rule, so the push-down is exact. | and a negation of a condition stay refused by where, as before.

One existing test changed: tests/test_types_condition_tree.py::test_and_with_something_else_is_refused asserted that condition | col("u") is refused. That combination is now the feature, so the test uses | "u" instead.

Proof (tests/test_core/operators/test_filter_boolean_column.py)

  • Rows: true, false and null rows on a data column, a tag column, a data-tag and a struct field.
  • Several boolean columns combined with each other and with comparisons and equalities through &, |, ~ and separate arguments or keywords. Each runs in both operand orders, on two tag orders and two table layouts.
  • Refusals: int and string columns (data and tag) and a non-bool struct field are refused, naming the remedy. The truth test is still refused.
  • Identity: bare equals == True and flag=True (condition, content hash, pipeline hash, identity_structure). ~ equals == False. The negation differs from the plain form. Equal conditions written in different orders give equal canonical forms, saved forms and hashes.
  • Sync and async: a job run on the sync and the async orchestrator.
  • A saved and loaded job using such a filter gives the same hashes, condition and stored rows.
  • SpiralDB (fake SDK, unit level): the scan receives flag == True / flag == False. Rows match filter, two boolean columns work in both orders, the restriction keeps the source identity, a non-bool column is refused, and | stays refused.

Checks

  • generate_golden_hashes.py --check: every golden value matches; no entry added.
  • ruff check, ruff format --check, basedpyright (exit 0), design_issues.py --check, assemble_changelog.py --check.
  • Targeted tests: filter, condition, SpiralDB where, async/sync equivalence, several-items, order invariance and the operators doc sample.

Docs: a "boolean column" row and an executed example in the Filter section of docs/concepts/operators.md. Changelog: changelog.d/ITL-1777.md.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Use boolean columns directly in filters: col("flag") keeps true rows, while ~col("flag") keeps false rows. Combine these conditions with AND and OR.
    • Supported in stream filters, condition builders, and SpiralDB where clauses.
  • Behavior
    • Null values match neither condition. Non-boolean columns are rejected when evaluated by a stream.

eywalker and others added 2 commits November 29, 2026 16:24
…tion (ITL-1769)

filter(col("flag")) keeps the rows where flag is true and filter(~col("flag"))
the rows where it is false. A bare reference stands for col(c) == True and its
negation for col(c) == False, so the identity, saved form and SpiralDB
push-down are those of the existing equalities: no new condition kind and no
hash moves. A null is kept by neither. A bare column combines through & and |
and is accepted by filter, Filter, Condition.of and SpiralDB where. A column
that is not boolean is refused when the condition meets the stream, with a hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a8c808e and f8cd9dc.

Files selected for processing: 9

  • changelog.d/ITL-1777.md
  • docs/concepts/operators.md
  • src/orcapod/core/operators/filter.py
  • src/orcapod/core/sources/spiraldb_table_source.py
  • src/orcapod/core/streams/base.py
  • src/orcapod/protocols/core_protocols/streams.py
  • src/orcapod/types/condition.py
  • tests/test_core/operators/test_filter_boolean_column.py
  • tests/test_types_condition_tree.py

Limit details: You’ve used the included review currently available. Your 101 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Recent review details

Context from checks skipped due to timeout: 1

  • GitHub Check: CodeRabbit
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 2

Source excerpt: Every fenced `python` block in `README.md`, `docs/index.md`, `docs/getting-started.md`, `docs/troubleshooting.md`, `docs/concepts/`, `docs/reference/` and `docs/tutorial/` is executed by `tests/test_docs/test_doc_samples.py`...

CodeRabbit inference engine (CLAUDE.md)

Files:

  • docs/concepts/operators.md
Source excerpt: The file holds only the text that would have gone under the release heading in `CHANGELOG.md`: the same category headings `CHANGELOG.md` uses (`### Breaking changes and migration`, `### Added`, `### Changed`, `### Fixed`, `#...

CodeRabbit inference engine (CLAUDE.md)

Files:

  • changelog.d/ITL-1777.md
Learnings: 5

Learning: 2026-11-29T00:08:10.975Z

Learnt from: CR
Repo: metamorphic-labs/orcapod-python PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-29T00:08:10.975Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python

## Testing conventions

**Order never counts, except where you give it** (developer, November 18, 2026, ITL-1271):
no operator result and no stream depends on the order of the tags or columns fed into it
(declared `tag_columns`, table layout, which tags are data-tags), on the order of the items
of an argument that names a set (names, mapping entries, keywords, predicates), or on the
order of the inputs of a commutative operator or a function pod. "If any operations COULD
vary output by tag order, then explicit ordering of tags to be used should be an explicit
input into the function/operator." Nothing that enters a hash, an identity, a stored path or
a stored value may follow such an order: hold a set of names sorted (or as a dict), and
place columns by an explicit argument or by name. The places where order is meant to count
are listed once, `ORDER_EXCEPTIONS` in `tests/test_core/order_rules.py`, each with its
reason, and ...

Applied to files:

  • src/orcapod/types/condition.py
  • tests/test_core/operators/test_filter_boolean_column.py
Learning: 2026-11-28T04:58:22.410Z

Learnt from: CR
Repo: metamorphic-labs/orcapod-python PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-28T04:58:22.410Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python

## No message-only parameters

Never pass a value into a function only so that the function can put it in an error or log
message (developer, November 11, 2026). If the function does not use the value to do its job,
it must not receive it: the function raises what it knows, and the caller, which has the
context, catches and wraps or annotates the error (path, row, column, node label). A helper
whose job is to report or record (log a suppressed failure, attach a note) legitimately takes
the label and context it records.

Applied to files:

  • src/orcapod/types/condition.py
Learning: 2026-11-29T06:05:09.412Z

Learnt from: CR
Repo: metamorphic-labs/orcapod-python PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-29T06:05:09.412Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python

## Testing conventions

Tests and golden fixtures that build a source with tag columns pass `tag_only_columns=True`
unless the test is about the default (developer, November 16, 2026, ITL-1159). This covers the
sources that take the option (the table, file and database sources); `ListSource`,
`DerivedSource`, `CachedSource` and `PollingSource` do not take it.

Applied to files:

  • tests/test_core/operators/test_filter_boolean_column.py
Learning: 2026-11-29T18:30:55.991Z

Learnt from: CR
Repo: metamorphic-labs/orcapod-python PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-29T18:30:55.991Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python

## Testing conventions

Every argument or input that can take several items (column names, a mapping, keywords,
input streams, sources to bind, output keys) is tested (developer, November 17, 2026,
ITL-1236): with two or more items; in more than one order, asserting what the order does or
must not change (rows, column order, content hash, pipeline hash, system-tag column names);
in each role it accepts (plain tag, data, data-tag: build the role you test, whatever the
`tag_only_columns` default above says); on inputs with two or more tag columns AND two or
more data columns, in more than one arrangement (tag order, table layout); and on the sync
and the async path. A test whose streams have one tag and one data column does not test an
operator. The shared family of such inputs is `tests/test_core/operators/several_items.py`;
the inventory is `docs/dev/specs/itl-1236-several-item-test-audit.md`. The docs show the
several-item...

Applied to files:

  • tests/test_core/operators/test_filter_boolean_column.py
Learning: 2026-11-29T02:07:56.706Z

Learnt from: CR
Repo: metamorphic-labs/orcapod-python PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-29T02:07:56.706Z
Learning: Source excerpt:
# Claude Code instructions for orcapod-python

## Testing conventions

Tests use the **public interface** wherever possible (developer, November 10, 2026): drive an
operator by calling it, `op(stream)`, and read the result through the stream's public methods.
Use a non-public entry point (`unary_static_process`, `static_process`,
`binary_static_process`, `_private` helpers) only when the test is specifically about that
entry point. The standing exception is verifying a schema prediction, which must compare
against `static_process(...).output_schema(...)`; see "Important implementation details".

Applied to files:

  • tests/test_types_condition_tree.py
Additional comments: 9

src/orcapod/types/condition.py: 1

492-492: LGTM!

Also applies to: 531-545, 735-735, 890-890, 1125-1173, 1195-1204, 1213-1216, 1330-1330, 1339-1340, 1375-1378, 1533-1537, 1539-1539, 1541-1541, 1543-1545, 1547-1547

tests/test_types_condition_tree.py: 1

164-164: LGTM!

Also applies to: 166-166

src/orcapod/core/operators/filter.py: 1

29-29: LGTM!

Also applies to: 70-71, 91-91

src/orcapod/core/streams/base.py: 1

60-60: LGTM!

Also applies to: 1126-1126, 1140-1142

src/orcapod/protocols/core_protocols/streams.py: 1

20-20: LGTM!

Also applies to: 499-499

tests/test_core/operators/test_filter_boolean_column.py: 1

1-377: LGTM!

docs/concepts/operators.md: 1

775-775: LGTM!

Also applies to: 810-853

changelog.d/ITL-1777.md: 1

1-11: LGTM!

src/orcapod/core/sources/spiraldb_table_source.py: 1

544-544: Functional Correctness

The integer-column case is rejected. Python's bool type is not int under the exact-type check used here, so True does not pass for an integer column.

Walkthrough

Bare boolean column references now act as true conditions, and their negations act as false conditions. Filter APIs accept these references, and SpiralDB where translates them to equality predicates. Null rows match neither condition.

Changes: Boolean Column Filters

Layer / File(s) Summary
Boolean condition semantics
src/orcapod/types/condition.py, tests/test_types_condition_tree.py
ColumnRef supports true and false conditions and composition with & and |. Condition.of and condition operators accept references. Tests cover invalid operands and type guidance.
Stream filter integration
src/orcapod/core/operators/filter.py, src/orcapod/core/streams/base.py, src/orcapod/protocols/core_protocols/streams.py, tests/test_core/operators/test_filter_boolean_column.py, docs/concepts/operators.md, changelog.d/ITL-1777.md
Filter APIs accept ColumnRef conditions. Tests cover row selection, null handling, condition identity and saved forms, and sync and async execution. Documentation and the changelog describe the shorthand.
SpiralDB where integration
src/orcapod/core/sources/spiraldb_table_source.py, tests/test_core/operators/test_filter_boolean_column.py
SpiralDBTableSource.where accepts column references. Tests verify translation to equality predicates and rejection of non-boolean columns and OR conditions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Possibly related PRs

Merge Risk: Minimal · up to f8cd9

Bare boolean columns now work as filter and where conditions. The change is additive, reuses existing equality semantics, and no concrete merge-blocking risk was identified.

Security architecture risk: Minimal · up to f8cd9

The new syntax expresses boolean filters that callers could already write. It keeps the same validation, saved representation, and database access scope. No material security or rollback regression was identified in the reviewed change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The additional caller input can select the same rows as an explicit boolean equality on the already selected stream or table. It does not select a new table, change the configured client, or grant new read authority.

Trust Boundaries and Controls

  • observed — At the SpiralDB read boundary, the connector refuses unsupported term shapes and builds equality from a column expression and a typed literal. The scan still runs through the existing read service call for the resolved table.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a bare boolean column becomes a filter condition, and ~col(c) is its negation. The changeset adds ColumnRef support in Condition.of, Filter, StreamBase.filter, and Spi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a bare boolean column becomes a filter condition, and ~col(c) is its negation. The changeset adds ColumnRef support in Condition.of, Filter, StreamBase.filter, and SpiralDB where, plus the boolean-column shorthand and its negation. The title is specific and matches the primary change. It uses the conventional feat(condition) prefix and stays under one sentence.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

@eywalker
eywalker merged commit c43240e into main Nov 30, 2026
12 checks passed
@eywalker
eywalker deleted the eywalker/bool-column-filter branch November 30, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant