Skip to content

feat(databases): the codec of a SpiralDB store table (ITL-1446) - #545

Closed
eywalker wants to merge 3 commits into
mainfrom
eywalker/itl-1446-spiral-codec
Closed

eywalker wants to merge 3 commits into
mainfrom
eywalker/itl-1446-spiral-codec

Conversation

@eywalker

@eywalker eywalker commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of ITL-1446: PR 2 of the SpiralDB store design (#542 at 3526f026, sections 3.1 to 3.3, 3.7 and 11). The codec of a store table, as pure functions in one new module, orcapod/databases/spiral_store.py.

Nothing calls it, it imports no pyspiral, and no existing code changes. No hash, stored path, layout or golden value moves (generate_golden_hashes.py --check is clean); the manifest digest is in the hash site inventory, "in a name". No changelog fragment: nothing is visible to users yet.

Decisions this rests on

Implemented as recommended; the developer reviews them later.

# Decision Where it is
S1 names and types are mapped in the store the whole module
S3 no row order nothing is stored for it
S4 two manifests stop read_manifest: two headers are refused, also when they agree
S6 null structs refused per batch NULL_STRUCT, raised by encode_rows
S8 the 8 KiB entry is not part of this not touched
S15 nothing writes a store table outside tests on the fake nothing calls the module

What it does

  • Names: encode_name (injective). Nothing decodes a name: decode_rows looks for exactly the stored names the manifest lists, at every depth, and refuses a missing, extra or repeated one. Names that are not UTF-8 and repeated siblings are refused.
  • Types: zone-aware timestamps keep their integers; a logical type is kept by its identifier over its storage; struct fields are restored by name in the recorded order; nullability is checked on write and read; the key is never null.
  • Manifest: one a table, chunks then header. A read checks the digest, the chunk count and order, the format and version, both schemas and the record path. empty_rows is what a table with a manifest and no value columns reads as. require_stored_schema serves the read-back of a first commit.
  • Refusals: all in one table, REFUSALS, each with its reason; lifting a type is moving one entry to _NATIVE.

Live evidence used

Reported by the live worker (P1 and P3); this PR ran no live SpiralDB. It goes beyond the design text at 3526f026, which still refuses several of these.

  • Native, measured bit for bit: booleans, integers, float16/32/64 (-0.0 and NaN payloads included), decimal128/256, date32/64, text, binary, a null column, lists, fixed-size lists, maps, structs, and these nested in one another. Names differing in case or normal form stay apart, so no folding rule or escape is added.
  • Timestamps and times are written as integers: the service refuses a whole write that holds a timestamp after 9999-12-30 22:00 UTC (so datetime.max) or a time outside one day.
  • decimal32/64 are written as the decimal128 the service gives back, and restored; a map's keys_sorted and struct field order are restored from the manifest.
  • Refused because the service or client refuses or panics: fixed_size_binary, duration, intervals, a struct with no fields, a null struct, a write of no rows. Substitutes that held and are not used yet: large_binary, int64. NUL, ., $ and a leading __ are escaped.
  • Refused because not measured: a null fixed-size list of structs.

Held

The second review holds the persisted manifest format. The format tag here is orcapod.spiral_store.draft, version 0: no table may be written with it outside tests; version 1 is fixed with the creation and recovery rules (PR 6).

Held as a draft: the move to spiral-sdk

Orcapod moves to spiral-sdk, to be tested first (developer, 2026-11-24). What rests on pyspiral or the service as measured through it, and must be measured again:

Part Depends on the client or service Independent of it
Names which names need escaping (_NOT_PLAIN, _ESCAPED, the __ prefix); the key column may start with __; no folding; no length limit the encoding's form and injectivity; UTF-8 and sibling checks; reading by the manifest's names
Types _NATIVE; the entries of REFUSALS whose reason is the service or client; integers for timestamps and times; decimal128 for decimal32/64; all physical fields nullable; large variants and other list item names on read; struct fields matched by name the logical schema, identifiers, views refused, nested logical types refused, null and key checks, rebuilding nested values, restoring the recorded schema
Manifest a table's key-value metadata exists and is bounded (_MAX_ENTRIES, _MAX_PAIR_BYTES, so _CHUNK_BYTES); chunks and header can be written in two calls the payload, digest, count, path and schema checks, one header, the marked extension keys, the comparison

The module imports no client; each dependence above is one constant, table or branch.

Choices the design leaves open

  1. The order of top-level columns is no schema difference (ITL-1112); struct field order is. Schema metadata is compared.
  2. ARROW:extension:* keys are written behind a mark (orcapod:key:) in the recorded schema. Otherwise reading a manifest builds whatever extension type is registered, and fails on one that refuses its storage.
  3. String and binary views are refused; Orcapod's tables hold the large variants.

Tests

tests/test_databases/test_spiral_store.py, 355 tests: 210,000 adversarial names; every row of the type matrix; each kept type at each nesting depth, over slices, chunks, column orders, sorted struct fields and small or large variants.

Review finding Test
Read by the manifest's stored names test_a_stored_name_never_matches_a_logical_name, test_the_key_is_not_a_value_column_of_the_same_name, test_stored_names_come_from_the_manifest_not_from_the_rule
Missing, extra, repeated or retyped stored columns test_rows_that_are_not_what_was_written_are_refused
Names that are not UTF-8, path components test_a_lone_surrogate_is_refused, test_a_name_that_is_not_utf8_is_refused_at_every_depth, test_a_path_component_the_store_cannot_name_is_refused
Duplicate siblings, through lists and extension storage test_duplicate_sibling_names_are_refused_at_every_depth
Parent validity, key nullability test_a_struct_parent_must_be_valid_also_in_a_logical_types_storage, test_a_null_key_is_refused_whatever_the_schema_says
Manifest integrity, chunks, path, one header test_a_manifest_that_cannot_be_read_in_full_is_an_error, test_chunks_in_another_order_are_refused, test_a_manifest_of_another_path_is_refused, test_two_headers_are_refused_also_when_they_agree
A manifest without value columns test_a_table_with_a_manifest_and_no_rows_reads_as_no_rows
Folding: kept apart test_names_that_differ_only_in_case_or_normal_form_are_kept_apart
Values the service refuses, writes of no rows test_datetime_max_and_min_are_kept, test_every_time32_is_kept, test_every_time64_is_kept, test_no_rows_are_never_written
Custom list-item names and metadata, extension storage test_every_type_at_every_nesting_depth, test_a_logical_type_is_kept_by_its_identifier

🤖 Generated with Claude Code

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

Names, physical types and the manifest, with no pyspiral; nothing calls it yet.

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

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

  • 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 3 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 105 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 7a2248b and d68750c.

Files selected for processing: 3

  • docs/reference/hashing.md
  • src/orcapod/databases/spiral_store.py
  • tests/test_databases/test_spiral_store.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

… codec (ITL-1446)

Sibling names are compared as stored, with a hook for probe P1; tests for the
review findings.

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

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.80695% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/orcapod/databases/spiral_store.py 99.80% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/orcapod/databases/spiral_store.py 99.80% <99.80%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ed types (ITL-1446)

One refusal table; timestamps and times as integers; a draft format tag.

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

eywalker commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing: this codec was moved to spiral-sdk and continued in PR #590 (src/orcapod/databases/spiral_store.py, tests/test_databases/test_spiral_store.py); it is now being carried onto current main in ITL-1837. Tracked in ITL-1497.

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

@eywalker eywalker closed this Dec 1, 2026
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