Skip to content

Allow keyless tables in temporal queries - #184

Merged
bberger62 merged 3 commits into
mainfrom
feat/keyless-temporal
Nov 6, 2026
Merged

bberger62 merged 3 commits into
mainfrom
feat/keyless-temporal

Conversation

@bberger62

@bberger62 bberger62 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Allow SamplerEngine.query_temporal to return sequences and aggregates from tables that have foreign keys but no primary key, using the native node IDs that DiskGraph already assigns to those rows.

For example, events(user_id FK → users.id, time, value) needs no event PK to be ingested or sampled through users → events. Today, a temporal query over that same relation fails with table "events" has no primary key metadata. This PR removes that extra requirement from temporal frame materialization.

Where support is missing today

query_temporal calls temporal_query::execute, which builds a shared frame for its sequence and aggregate consumers. In materialize_frame, relation traversal has already found the destination node IDs, and distinct has already removed repeated visits by node ID. The function then unconditionally requires table.primary_key_map() and raises the missing-PK error above.

It subsequently adds the PK column to the row projection and reads its values as the secondary ordering key for rows with equal timestamps. That ordering/projection assumption blocks every materialized frame over an FK-only destination, including count-only queries that need no event attributes. Both sequences and aggregates fail at this shared step.

The separate query_temporal_lengths / count_frame path already traverses and counts native node IDs without requiring destination PK metadata.

How this follows the existing engine

DiskGraph distinguishes a stored row's native identity from its optional external primary key:

This PR uses that same native identity in the temporal materializer. It does not introduce another row-ID scheme or generate a source PK.

Changes

  • Make destination PK metadata optional. Project and decode the declared PK only when present; preserve the existing PK-based tie ordering for keyed tables.
  • For an FK-only destination, use the native node ID already returned by traversal as the secondary ordering key. Keep the existing temporal sort, window filtering, sequence limits, reducers, and node_ids output. This follows the graph engine's identity convention; it does not change the graph sampler's ordering algorithm.
  • Preserve each source occurrence as its own node, including identical event rows. Existing distinct behavior continues to remove repeated visits to one node, rather than collapsing different rows with equal values. IDs remain local to the index.
  • Preserve Arrow row counts in table_rows and take_batch when the projection is empty. Previously the mandatory PK guaranteed at least one projected column. With an optional PK, a static count-only frame can legitimately have zero columns and still contain rows. These frames decode no rowpack values and report zero rows decoded.

PK lookup and FK validation retain their existing requirements. RDL entity selection still requires a declared PK; an FK-only table can supply related events without becoming an entity table. The companion rdl-platform#139 enables that distinction in RDL and depends on this native change.

Testing Done

  • 354 native temporal tests passed, including 16 new FK-only cases across one/three shards and both output formats. Coverage includes identical rows, cutoff boundaries, windows, bounded sequences, empty histories and anchors, length queries, deferred columns, and zero-column counts.
  • The duplicate-event fixture has times 9, 9, 10, 11 and values 2, 2, 3, 100: cutoff 10 returns three distinct native nodes, count 3, and sum 7. An empty history returns zero. The missing-PK failure was reproduced with the previous native binary.
  • 17 sampling regression tests passed; the unrelated Rust benchmark test was deselected. Python lint/format, whitespace checks, and local binding-crate Clippy passed. Full-workspace CI Clippy passed.
  • Quick CPU benchmark of the full native dependency update (567f6cab → 232aec03): 65,536 events, 256 roots, one thread, fixed CPU core, three alternating runs per revision. Keyed output hashes matched. Median bounded-sequence time was 7.96 → 7.96 ms (+0.04%); shared sequence/aggregate time was 22.19 → 22.33 ms (+0.63%). This measured query execution; ingestion, training, and GPU execution were not timed.

Change map

File-by-file change map.

@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@bberger62
bberger62 temporarily deployed to gha-kumo-workflow-tests November 4, 2026 00:12 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Temporal queries now support destination tables without primary-key metadata. Frame sorting uses the primary-key value when available and otherwise uses the native node ID. Zero-column Arrow batches preserve row counts, while empty projections do not increase the decoded-row count. The README documents keyless-table node ID behavior, and tests cover temporal queries across one- and three-shard graphs.

Merge Risk: Low · previous review 232ae

An invalid root can be counted as a real row in the empty-path count-only case; validate roots before constructing the empty batch.

Pre-merge checks: Passed 2 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Change Map Design Review Inconclusive The required PR conversation comment is unavailable. The checkout contains only the marker in the template and review guidance, not the PR's marked change-map comment. The description's linked URL and… Provide the actual author or authorized-bot conversation comment beginning with <!-- kumo-pr-change-map -->, or make it available to this review. It must cover all three changed files and state the observed failure or release requirement,…
Passed Passed checks: 2 passed

Check name Status Explanation
Pr Size Passed The pull request changes 3 files. This does not exceed the 40-file limit.
Public Resource Access Passed The pull request adds no external resource reference. The README additions describe behavior only, and the new test paths point to local temporary Parquet fixtures, which this check excludes. Existing…
Full details: Public Resource Access

Explanation

The pull request adds no external resource reference. The README additions describe behavior only, and the new test paths point to local temporary Parquet fixtures, which this check excludes. Existing README URLs and repository references are unchanged.

Full details: Change Map Design Review

Explanation

The required PR conversation comment is unavailable. The checkout contains only the marker in the template and review guidance, not the PR's marked change-map comment. The description's linked URL and summary do not provide the same-comment evidence required for the observed failure, existing behavior, smallest sufficient change, focused verification, and stopping condition. The reviewed diff is available and shows a focused three-file change, including optional primary-key handling in materialize_frame, native node-ID ordering, zero-column Arrow row counts, tests, and README text, but that cannot establish whether the proposed design map is necessary and correctly scoped.

Resolution

Provide the actual author or authorized-bot conversation comment beginning with &lt;!-- kumo-pr-change-map --&gt;, or make it available to this review. It must cover all three changed files and state the observed failure or release requirement, existing behavior, smallest sufficient change, focused verification, stopping condition, and any optional refinements.

  • 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 3b59a35 and 232aec0.

Files selected for processing: 1

  • packages/diskgraph/diskgraph-pybind/src/temporal_query.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@bberger62

bberger62 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Change map

Observed failure: query_temporal traverses an FK-only destination successfully, then materialize_frame rejects its missing PK metadata while preparing the row projection and tie key. Native ingestion, graph sampling, and length-only temporal queries already use native node IDs without requiring a destination PK. Make the projection optional and use those same IDs for temporal ties. Completion means sequences and aggregates work for FK-only destinations, preserve distinct source occurrences, and retain existing keyed behavior. Verification: 354 temporal tests (including 16 new cases), 17 sampling tests, and local/full-workspace CI Clippy passed. The README is restored to the base version and is absent from the PR diff.

File Function / scope What changed Why
packages/diskgraph/diskgraph-pybind/src/temporal_query.rs materialize_frame, table_rows, take_batch Optional PK projection and tie key; use the existing native node ID when no PK is declared; retain zero-column Arrow row counts and accurate decode counters. Remove the materializer's extra PK requirement using DiskGraph's existing row identity, including count-only frames that need no projected attributes.
packages/diskgraph/diskgraph-pybind/python/tests/test_keyless_temporal.py FK-only temporal integration fixtures and tests Duplicate occurrences, both output formats, one/three shards, windows, empty results, bounded sequences, length queries, deferred columns, zero-column counts and counters. Verify FK-only destinations across temporal execution paths while preserving native node identity and row multiplicity.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1
packages/diskgraph/diskgraph-pybind/src/temporal_query.rs: 1

458-459: Minor · Functional Correctness · Quick win

Validate node IDs before returning an empty projection.

For a keyless root table with path: [], an out-of-range root ID reaches this branch without a traversal. A count-only query then returns 1 for a nonexistent row. The normal path rejects that ID in TableReader::edges_for_node. (raw.githubusercontent.com)

Validate the root IDs without decoding rowpack data before constructing the batch.

Nitpick comments: 1
packages/diskgraph/diskgraph-pybind/python/tests/test_keyless_temporal.py: 1

111-124: Trivial · Functional Correctness · Quick win

Pin the native node-ID order for keyless time ties.

The PR documents that keyless temporal ties use the native node ID. sort_frame_rows applies that tie order through stable_sort_key. No test in the keyless or duplicate-row path asserts the order of node_ids for equal timestamps. A change that reverses or ignores this tie-breaker keeps the current assertions passing. Add an assertion that the two time-9 IDs appear in the documented native-ID order. Confirm the U64 comparison in stable_sort_key before choosing the expected direction.

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 83d87f7 and 3b59a35.

Files selected for processing: 3
  • packages/diskgraph/diskgraph-pybind/README.md
  • packages/diskgraph/diskgraph-pybind/python/tests/test_keyless_temporal.py
  • packages/diskgraph/diskgraph-pybind/src/temporal_query.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@bberger62
bberger62 temporarily deployed to gha-kumo-workflow-tests November 4, 2026 00:24 — with GitHub Actions Inactive
@bberger62
bberger62 temporarily deployed to gha-kumo-workflow-tests November 5, 2026 15:37 — with GitHub Actions Inactive
@bberger62

bberger62 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

/ok to test 3e7be45

@bberger62
bberger62 requested a review from Vedaant-J November 5, 2026 19:38
@bberger62

Copy link
Copy Markdown
Contributor Author

/ok to test 3e7be45

@bberger62
bberger62 merged commit 6819a29 into main Nov 6, 2026
123 of 125 checks passed
@bberger62
bberger62 deleted the feat/keyless-temporal branch November 6, 2026 18:12
bberger62 added a commit that referenced this pull request Nov 12, 2026
## Summary

Allow non-entity tables without primary keys in `kumo.pytorch`,
following DiskGraph's existing row identity. For example, `events(owner
FK → users.id, at, amount)` can supply histories, aggregates and graph
neighbors without an artificial event key. Entity/root and candidate
entity declarations still require a PK.

This ports
[rdl-platform#139](kumo-ai/rdl-platform#139)
into the API's new home at `packages/experimental/kumo-pytorch`,
introduced by #244. The API implementation, tests and agreed examples
are retained under the `kumo.pytorch` namespace. The standalone
dependency-pin changes are omitted: this package already uses the
workspace DiskGraph, including merged native support from #184.

## Where support is missing

The current `TableSpec` constructor rejects `primary_key=None` with
`table name and primary key must be non-empty`, before the table reaches
ingestion. Downstream API paths also assume every table has a PK: native
ingestion configuration always declares one, temporal sequences project
it, graph output reads it for identity, and serving requires it for row
uniqueness and fetching.

DiskGraph already stores and traverses rows without PKs. Ingestion
assigns native node IDs; graph sampling and temporal queries use those
IDs to address individual occurrences. External PK lookup is a separate
requirement for choosing entities. This change carries that existing
distinction through the API.

## Implementation and intended behavior

- Accept `TableSpec(..., primary_key=None)` and `build.Table(...,
key=None)`. A shared declaration check rejects PK-less sample/candidate
entities before binding, type inference or source access.
- Omit absent PK metadata and projections in the DiskGraph adapter. Use
returned native node IDs for temporal and graph identity. Constant-only
sequences project their existing clock to satisfy the native sequence
API.
- Use private source-occurrence ordinals in the in-memory test/serving
paths. Keep separate source occurrences distinct, including equal-valued
rows and aliases of the same input mapping. Repeated visits reuse an
occurrence; `distinct=True` removes repeated visits rather than
collapsing equal values.
- Validate key presence/uniqueness and request PK columns in `rows_spec`
only for keyed tables. Update authored documentation and regenerate the
public API reference.

No source key generation, additional identity column or persistent
identity inventory is introduced. Existing keyed ordering, entity
lookup, source cleanup and unsupported-operation checks retain their
behavior. Native source, workspace packaging and dependencies are
unchanged by this PR.

The new `G-KEYLESS-001` guarantee has two hand-calculated examples:

| Case | Input | Required answer |
| --- | --- | --- |
| C-KEYLESS-001 | Identical amount-2 events at time 9, amount 3 at 10,
and future amount 100 at 11. | Cutoff 9: count 2, sum 4. Cutoff 10:
count 3, sum 7. Recent `(9,10]` count 1. Empty history: count/sum 0. |
| C-KEYLESS-002 | Two links revisit the same two identical eligible
facts. | Distinct count 2 / sum 4; repeated count 4 / sum 8. Future
facts excluded. |

Keyless IDs remain opaque and local to an index or prepared serving
dataset. Reordering, repartitioning or serving subsets can change tied
selections and floating reduction rounding. Occurrence multiplicity and
integer reductions remain exact; stable cross-preparation identity
requires a declared PK.

## Testing Done

- **Full CPU suite: 1,926 passed**, 3 GPU skips and 47 opt-in
end-to-end/notebook checks deselected.
- **Complete conformance: 705 passed**, with no skipped or deselected
obligations, including DiskGraph and the in-memory differential checks.
- **Installed wheels: 41 passed** for keyless/entity behavior and the
README quick start, followed by **all 3 example notebooks passing** with
exact committed-file comparisons.
- Fresh independent adversarial review: 26 focused keyless tests, four
case/engine golden checks, and additional alias, NULL-FK,
repeated-visit, multi-file/shard, graph and serving probes passed.
- Source/wheel builds, Ruff 0.17.3 lint/format, generated
API/limitations freshness, whitespace checks and the repository-wide
SPDX check passed.

Validation uses Python 3.12 on CPU, with DiskGraph built from this
branch's in-tree source. The editable package is `kumo.pytorch`; the old
`rdl-pytorch` editable install was removed. Installed-wheel checks use a
separate environment and staged tests/docs/examples without `src/`; both
API and engine imports were verified to come from the installed wheels.

From `packages/experimental/kumo-pytorch`:

```bash
CUDA_VISIBLE_DEVICES='' python -m pytest -q --require-imports
CUDA_VISIBLE_DEVICES='' python -m conformance --engine all
python -m tests.api_reference
python -m tests.limitations_reference
python -m ruff check .
python -m ruff format --check .
```

Both the source distribution and its wheel build successfully. The
installed-wheel gate also exercises the README, keyless/entity tests and
example notebooks. Ruff uses the CI pin, 0.17.3. Native compilation used
the existing Rust 1.98 compiler; CI uses the repository's pinned
toolchain. No GPU or live-service validation is claimed.

Earlier standalone benchmarks measured roughly 4% additional in-memory
test-engine time and 6.3% retained source heap. Those historical
measurements were not repeated for this monorepo port.

## Migration and review

All 26 existing touched files matched the imported base after namespace
conversion; the four new guarantee/test files had no collisions. This is
the same RDL feature moved into the monorepo, with no additional
behavior or altered golden answers. The new package's existing CPU,
DiskGraph, notebooks and installed-wheel workflows cover the changed
paths.

Independent adversarial review found no actionable issues. It executed
all 26 focused keyless cases and four golden case/engine combinations,
plus multi-file/shard, NULL-FK, aliased-row, repeated-visit, graph and
serving probes. It also checked namespace coexistence and verified that
all 67 Python modules in the built wheel match source byte-for-byte.

## Change map

[File-by-file change
map](#267 (comment)).

Reviewed at: e7a75e6

Co-authored-by: Codex <[email protected]>

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — 3e7be459 Deployed Nov 5, 2026 by bberger62 via import #1564
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.

3 participants