Skip to content

feat(spiraldb): send a key range to the scan when a where fixes a key prefix (ITL-1775) - #677

Open
eywalker wants to merge 4 commits into
mainfrom
eywalker/itl-1775-spiraldb-source-send-key-ranges-to-the
Open

eywalker wants to merge 4 commits into
mainfrom
eywalker/itl-1775-spiraldb-source-send-key-ranges-to-the

Conversation

@eywalker

@eywalker eywalker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes ITL-1775

SpiralDB sends a key range only for string and integer key columns. Timestamps, dates and other key types use the filter alone until their key order can be verified.

Summary by CodeRabbit

  • New Features
    • SpiralDB scans can now use key ranges when conditions match supported leading-key patterns, reducing the amount of table data scanned. All matching rows still pass through the full filter.
    • Conditions that do not meet the supported patterns continue to use filtering without key-range scans.
  • Documentation
    • Updated source documentation to describe when key-range scans apply and which key-column types are supported.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

  • Run on-demand review

This review includes 5 billable files and costs up to $1.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 10 minutes for your next included review.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8638ec9 and e15652e.

Files selected for processing: 5

  • changelog.d/ITL-1775.md
  • docs/concepts/sources.md
  • src/orcapod/databases/spiraldb_connector.py
  • tests/test_databases/fake_spiral_sdk.py
  • tests/test_databases/test_spiraldb_key_ranges.py

No actionable comments were generated in the recent review.

Walkthrough

SpiralDB scans now pass key ranges for eligible leading-key equality prefixes, optionally followed by a range on the next key. The full filter remains in place. Tests cover planning, scan behavior, and synchronous and asynchronous reads.

Changes: SpiralDB Key-Range Pushdown

Layer / File(s) Summary
Plan eligible key bounds
src/orcapod/databases/spiraldb_connector.py, tests/test_databases/fake_spiral_sdk.py, tests/test_databases/test_spiraldb_key_ranges.py
key_range_plan accepts supported leading-key equality prefixes and optional bounds on the next key column. It rejects unsupported or conflicting conditions and converts accepted plans to SDK key bounds. Planner tests cover accepted and rejected conditions.
Pass bounds through scans
src/orcapod/databases/spiraldb_connector.py, tests/test_databases/fake_spiral_sdk.py, tests/test_databases/test_spiraldb_key_ranges.py, docs/concepts/sources.md, changelog.d/ITL-1775.md
scan_batches passes planned key ranges to table.scan and retains the full filter. The fake SDK applies and records key ranges. Scan tests compare results with filter-only reads, including synchronous and asynchronous reads. The documentation and changelog describe the behavior.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Source as SpiralDBTable.scan_batches
  participant Planner as key_range_plan
  participant Table as table.scan
  Source->>Planner: terms, key columns, and column types
  Planner-->>Source: key-range plan or None
  Source->>Table: key ranges and full filter
  Table-->>Source: batches matching the ranges and filter
Loading

Possibly related PRs

Merge Risk: Minimal · previous review 8638e

SpiralDB scans now send a key range when conditions fix a leading key prefix, and the full filter still decides which rows match. Results should match a filter-only scan. No concrete defect was established in the changed code, so merge risk is minimal.

Security architecture risk: Minimal · up to 8638e

The change narrows reads on the same table and version while keeping all existing filter checks. The review found no introduced access expansion or weakened control. Compatibility with the deployed database was not independently validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Within the inspected path, condition values can influence the scan bounds on an already-resolved table and version. The change does not provide a route to another table, tenant, or credential context.

Trust Boundaries and Controls

  • observed — The scan remains within the existing connector read wrapper. The SDK predicate is still passed with the range, and Python-only equalities still run before batches are yielded, with the matching-row limit applied after those local checks.

Resilience and Maintainability Implications

  • observed — The new planning step does not write shared state. Once the scan opens a reader, the existing finally block still closes it on completion or interruption.

Hardening Proposals

  • proposed — Record an equivalence check against the pinned SDK that compares bounded scans with filter-only scans for composite prefixes and one-sided and exclusive endpoints. Include a scan with no eligible range, since the new argument is also passed on that path.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: SpiralDB scans now receive a key range when a where clause fixes a key prefix. The changeset adds key_range_plan, KeyRangePlan, scan-time key range passing, fake SDK r…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: SpiralDB scans now receive a key range when a where clause fixes a key prefix. The changeset adds key_range_plan, KeyRangePlan, scan-time key range passing, fake SDK range support, tests, docs, and a changelog entry, all matching this title. The ITL-1775 reference matches the changelog file name and the linked objective. The title is 87 characters, slightly long but within normal limits for a conventional commit title.

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c43240e and 8638ec9.

Files selected for processing: 5

  • changelog.d/ITL-1775.md
  • docs/concepts/sources.md
  • src/orcapod/databases/spiraldb_connector.py
  • tests/test_databases/fake_spiral_sdk.py
  • tests/test_databases/test_spiraldb_key_ranges.py

Limit details: You’ve used the included review currently available. Your 99 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 comments: 2

src/orcapod/databases/spiraldb_connector.py: 1

574-574: Functional Correctness

The planned key range keeps every row that satisfies the equality prefix and the optional range term. For each endpoint, the bound uses the prefix and the range literal, with inclusivity taken from the operator. Absent endpoints use the whole-prefix bound. Under the bound contract documented at src/orcapod/databases/spiraldb_connector.py:557-559, no accepted prefix/range combination excludes a matching row. The comment does not identify a failing input, and no defect in _key_range is established.

tests/test_databases/fake_spiral_sdk.py: 1

759-759: Functional Correctness

The sandbox cannot observe the claim-critical premise. PyArrow is not installed under either available interpreter, so the empty-table rows.filter call cannot be run. The repository source does not define how PyArrow handles a zero-length mask with null type, and no supported contract in the checkout settles it.

Whether an untyped pa.array([]) mask raises in Table.filter remains undecided. The explicit pa.bool_() mask at lines 785-789 is an existing pattern. Use it for the key-range mask too if the authors want the masks consistent. Do not treat that consistency as proof of a runtime failure.

@eywalker

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Posted by a Claude Code agent on behalf of @eywalker.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch has not been deployed

No deployments
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