Skip to content

Read the sampled primary key by name in DiskGraph ingest - #424

Merged
aaron-kumo merged 1 commit into
mainfrom
aaron/diskgraph-pk-sample-column
Nov 20, 2026
Merged

aaron-kumo merged 1 commit into
mainfrom
aaron/diskgraph-pk-sample-column

Conversation

@aaron-kumo

@aaron-kumo aaron-kumo commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

Context sampling records each node table's longest primary key. For string and bytes keys, that length picks the PK map's hash: gxhash up to 16 bytes, xxh3 above. The sample read the key from source batches by its position in the ingest config, but Parquet batches keep the file's column order, so a config ordered differently from the file measured another column. Each index stores its hash choice, so existing indexes still load and resolve.

  • Resolve the primary key by name at both sampling sites, the strided Parquet sample and the encode-prefix sample, through a new source_column helper.
  • Use the helper in build_access_cols and the edge-table column loop, which already resolved by name. Its missing-column error names the column.
  • Add test_long_string_pk_sampled_by_name, which reproduces the failure below.
  • Move sample_context_batches's doc comment, which sat on max_binary_value_len.

Why

xxh3 is the fallback for keys gxhash can't separate: above 16 bytes, gxhash collisions are constructible and hold under every seed. A table lost that fallback whenever its file had a shorter or non-string column at the primary key's config position. If two of its keys then collided under gxhash, ingest failed in the PK-map phase with ptrhash construction failed, after encode had finished. Every retry failed the same way.

kumo-pytorch hits the mismatch by default, because _compile_diskgraph_config lists each table's columns sorted by name, whatever the file's order. For example, a Parquet table written as label, id with primary key id compiles to a config listing id, label, so sampling measured label. With the two strings from ptr_hash::hash::gxhash_twins() as its id values, the ingest fails. The new test is this repro.

No setting forces the fallback hash. The only workaround was to rewrite the source files so the primary key sits at its config position. For kumo-pytorch, that means writing each table's declared columns in name order.

Change map

File-by-file change map.

Context sampling indexed source batches by the primary key's position
in the ingest config. Parquet batches keep the file's column order, so
when the orders differ the sample measured another column. For a long
string key, that can choose gxhash for the PK map, where twin keys fail
the MPHF build. kumo-pytorch sorts config columns by name, so its
configs rarely match the file's order.

Resolve the key by name at both sampling sites through a source_column
helper, which build_access_cols and the edge-table loop also use.

Also move sample_context_batches's doc comment off max_binary_value_len.
@aaron-kumo
aaron-kumo temporarily deployed to gha-kumo-workflow-tests November 20, 2026 00:29 — with GitHub Actions Inactive
@aaron-kumo

Copy link
Copy Markdown
Collaborator Author

Change map

File Function / scope What changed Why
packages/diskgraph/diskgraph-ingest/src/lib.rs source_column, build_temp_shards PK sampling, build_access_cols, build_temp_edge_batches, sample_context_batches doc PK sampled by name through new helper; by-name lookups share it; doc comment moved to its function Batches keep file column order
packages/diskgraph/diskgraph-ingest/tests/ingest_pk_extraction.rs test_long_string_pk_sampled_by_name Reordered Parquet keyed by gxhash twins Fails on main

Verified: new test fails on main and passes with the fix.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Ingestion code now retrieves configured source columns by name in primary-key sampling, edge-table extraction, and access-column construction. The sampling documentation describes strided per-file sampling. An x86_64 test checks primary-key extraction when the Parquet column order differs from the configured order.

Merge Risk: Minimal · up to 4a60d

Ingest now selects configured columns by name, so Parquet files whose column order differs from the configuration pick the correct primary-key hash. No actionable merge risk was found.

Security architecture risk: Minimal · up to 4a60d

Primary-key sampling now follows the configured column name, matching existing encoding behavior. The inspected change establishes no introduced risk to access controls, index compatibility, or failure containment.

Pre-merge checks: Passed 3

Check name Status Explanation
Change Map Design Review Passed The change-map comment (issuecomment-7026370065, marker <!-- kumo-pr-change-map -->) describes a sound design. The core change is necessary and placed at the right layer. Its gaps are documentation …
Pr Size Passed The PR changes 2 files, below the threshold of 40. The changed-file inventory from git diff --name-status refs/coderabbit/pre-merge-check/base refs/coderabbit/pre-merge-check/head lists: - M package…
Public Resource Access Passed The check applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. I inspected the reviewed diff range (base to head). It chan…
Full details: Change Map Design Review

Explanation

The change-map comment (issuecomment-7026370065, marker &lt;!-- kumo-pr-change-map --&gt;) describes a sound design. The core change is necessary and placed at the right layer. Its gaps are documentation refinements, not design defects. Necessity (verified in code). The base code sampled the primary key with pk_col_index, a config-order index, and then read batch.column(col). That is a positional lookup. Parquet batches keep file column order, and the ingest read path does not reorder them. So a config order that differs from the file order sampled the wrong column. The change now resolves the key by name through source_column at both sampling sites (build_temp_shards, around lines 7620 and 7661). It also uses the helper in build_access_cols (line 16425) and in the edge loop of build_temp_edge_batches (line 9273). I checked each function name in the map against the outline, and they are correct. Smallest sufficient change. The helper is a small private function. The other positional .column( calls in lib.rs (lines 12883, 17432) already resolve by name, so the PK path is the only positional gap. No public API changes. Behavior preserved. The missing-column error is now raised at sampling. In that path, build_access_cols raises the same error on the same batch right after, so no new failure mode appears. The Parquet read path has no projection that would reorder columns. Misleading or omitted items (non-blocking, optional): - The comment does not name the observed failure in its "Why" column. The PR body gives it: ptrhash construction failed in the PK-map phase. The test row says only "Fails on main." - The comment has no stopping condition. It does not say that other by-name lookups (validate_source_batch_values, line 17426, and the text sample, line 12879) stay as they are. Consolidating them would be a separate, optional refinement. - The test gating is not stated. test_long_string_pk_sampled_by_name runs only when target_arch = "x86_64" and pkhash128 is off. The comment's "Verified" line does not mention that scope. - The comment does not mention the change in hash selection. Re-ingesting a table whose file order differs from its config can now pick xxh3 where gxhash was picked before. The PR body covers this, and existing indexes keep their stored hash. - "Verified: new test fails on main and passes with the fix" could not be re-run here. Build tooling is unavailable, so I treat it as a contributor claim. Suggested corrections (optional): Add the observed ptrhash construction failed symptom to the lib.rs "Why" cell. Add the x86_64 / !pkhash128 gating to the test row. Add one line on the re-ingest hash-choice effect.

Full details: Pr Size

Explanation

The PR changes 2 files, below the threshold of 40. The changed-file inventory from git diff --name-status refs/coderabbit/pre-merge-check/base refs/coderabbit/pre-merge-check/head lists: - M packages/diskgraph/diskgraph-ingest/src/lib.rs - M packages/diskgraph/diskgraph-ingest/tests/ingest_pk_extraction.rs The check counts files only and ignores line counts. The count of 2 does not exceed 40, so the check passes.

Full details: Public Resource Access

Explanation

The check applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. I inspected the reviewed diff range (base to head). It changes two files: packages/diskgraph/diskgraph-ingest/src/lib.rs and packages/diskgraph/diskgraph-ingest/tests/ingest_pk_extraction.rs. No manifest, lockfile, or package-source file changed. I searched every added diff line for URLs, git/registry references, and package-source markers (https?://, git@, github.com, crates.io, pypi, npm, docs.rs, git =, path =). The only hits were local filesystem paths in the test (input_root.join("accounts.parquet"), dir.path().join("config.json"), output_root.join("index_metadata.json")). These are local test fixtures and are excluded. The added doc comments and test code mention kumo-pytorch, ptr_hash::hash::gxhash_twins(), and pkhash128. These are a repository name and Rust API identifiers, not URLs or resource locations. The PR description links to a GitHub comment, but the description is not part of the code change, and the check covers the reviewed change. No added or modified external resource reference requires public-access verification, so the check passes.

  • 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 99b0015 and 4a60d35.

Files selected for processing: 2

  • packages/diskgraph/diskgraph-ingest/src/lib.rs
  • packages/diskgraph/diskgraph-ingest/tests/ingest_pk_extraction.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.

@aaron-kumo aaron-kumo self-assigned this Nov 20, 2026
@aaron-kumo
aaron-kumo merged commit 40e4df1 into main Nov 20, 2026
129 checks passed
@aaron-kumo
aaron-kumo deleted the aaron/diskgraph-pk-sample-column branch November 20, 2026 01:06

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — 4a60d351 Deployed Nov 20, 2026 by aaron-kumo via import #2732
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.

2 participants