Skip to content

Read multi-file views by each file's struct-list layout; document DuckDB on relayouted files - #382

Merged
ypriverol merged 8 commits into
devfrom
claude/qpx-issue-377-review-dfv5gg
Nov 13, 2026
Merged

ypriverol merged 8 commits into
devfrom
claude/qpx-issue-377-review-dfv5gg

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #376 and #377. It fixes one bug in qpx's reader and documents how relayouted files behave in DuckDB. The findings are summarised in #377.

Bug: a view over several files restored every row with one file's layout

restore_items read qpx.struct_lists from one footer (parquet_kv_metadata … LIMIT 1) and applied it to the whole unioned view. It also took a list<struct> type (STRUCT(...)[]) for a struct. This affects dataset shards (register_parquet_files), S3 globs and Hive directories. Measured on real data:

  • Converted file plus relayouted file: Dataset skipped the structure with a warning (Binder Error: … struct_extract(STRUCT(...)[] …), or queries failed later with ConversionException.
  • Relayouted files from two tools (PD + OpenMS pg, DIA-NN + Spectronaut feature): the second file's rows came back under the first file's score names with null values, with no error. Their own scores disappeared, and qpxc validate crashed.

Fix (qpx/core/struct_lists.py, qpx/core/engine.py)

  • layout_groups groups the files of a view by three things: the layouts their footers declare, the stored type of each struct leaf, and any struct-list columns held as structs without a layout. Without the type check, a FLOAT cv_params term read next to a DOUBLE one was widened, so 52.822754 read 52.82275390625.
  • One group (the normal case): the same single read_parquet view as before.
  • Several groups: one read_parquet per group, each restored by its own layout, then UNION ALL BY NAME. Rows follow the groups rather than the file order.
  • A struct with no layout next to other groups (e.g. a file rewritten by DuckDB COPY) is refused with a ValueError that names the file. Previously it gave wrong values or a late error.
  • A view that cannot be restored is dropped instead of being left registered unrestored.
  • Hive partitions are now read with union_by_name=true, like shards. Without it, a DOUBLE in a later partition was read as the first partition's FLOAT.
  • A single file still reads only its own footer layout, and only once DESCRIBE shows a struct. An exact S3 path keeps this fast path; only a glob is grouped. Opening a converted (list) file got cheaper, because the old startswith("STRUCT") check matched list types too.

Docs

docs/spec/serialization.md:

  • Raw DuckDB SQL on struct lists, including quoted names and the footer query for higher_better.
  • A column's form depends on the file's rows: the same PD converter gave a struct for PXD046576 psm and a list for PXD081613 psm.
  • union_by_name = true for several files, and list and struct files can't be read in one read_parquet.
  • Ordinal ids collide across datasets and change with the input.
  • Exact matches on rounded values stop matching: a PXD081613 psm–feature join on rt went from 43,121 to 336 matches.
  • Row order after the sort.
  • The DuckDB versions checked: 1.1.3, 1.4.4, 1.5.0, 1.5.6 and 2.0.0, all bit-identical to PyArrow. DuckDB doesn't use the page index.

Also:

  • transform.md named --memory-limit/--temp-directory, which relayout doesn't have; it now names --duckdb-memory/--temp-dir.
  • The view pages and scores.md link to the struct form.

Also in this branch

d197ecf: relayout states identity_source=provided for fragment, whose ids keep their values but were hashed from the old feature_id.

783be8d (drop the scores a typed q-value column repeats) changes what the writers store, so it is reverted here and moved to #386. The struct-field example in serialization.md now uses diann_cscore, which is correct whichever of the two PRs merges first.

Tests

  • 14 new tests in tests/integration/test_struct_lists.py: converted + relayouted shards, different layouts (2 and 3 files), an S3-style glob, Hive partitions with different layouts, the same layout stored as different types, union_by_name on Hive, the single-read path for one layout, no footer read for a plain file, only the declared layout read for one relayouted file, qpxc validate without a traceback, the refusal, and the view drop.
  • Against the old code, 11 of the first 13 fail. Each test of a review fix also fails with that fix reverted.
  • Full suite: pytest tests -n 8 gives 2,788 passed on DuckDB 2.0.0 and 2,788 passed on DuckDB 1.5.0. ruff check and ruff format --check are clean, and mkdocs build passes.
  • Real data: 28 mixed folders (PD, OpenMS, DIA-NN, Spectronaut, MaxQuant, FragPipe; shard, S3-glob and Hive routes). Every view matches its files read alone on both DuckDB versions. DatasetCollection is unchanged.

Limits

  • S3 itself was not tested live, only a local glob. glob() and parquet_kv_metadata use the same file list. If their names ever differed, registration fails with a clear error rather than reading wrong values.
  • A view over many files now reads every footer instead of one: 200 Hive partitions took 47 ms instead of 25 ms to register.
  • A shard whose file name contains * or ? is expanded as a glob, as before.

Generated by Claude Code

…s their features

fragment hashes fragment_id from feature_id. relayout renumbers the
feature ids and rewrites fragment.feature_id, but kept the fragment
footer's identity_source "derived", so `qpxc validate --check-identity`
(and --conformance) reported every fragment id as stale and the dataset
as invalid. The links themselves were intact.

A view whose identity composite holds a reference relayout rewrites now
states identity_source "provided", as merge() already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0149aXmZfe47GqaXBnt9DAWK
…st layout

A view over several files (dataset shards, an S3 glob, Hive partitions)
took the qpx.struct_lists layout of one footer (LIMIT 1) and applied it
to every row, and took a list<struct> type for a struct. A converted
file next to a relayouted one made the view unreadable; relayouted files
of different tools read the second file's rows under the first file's
score names, with null values and no error, and qpxc validate crashed.

The files of a view are now grouped by declared layout, the stored type
of each struct leaf, and struct columns without a layout. One group is
read as before with one read_parquet; several groups are read apart and
unioned by name, each restored by its own layout. A struct without a
layout next to other groups is refused, and a view that cannot be
restored is dropped rather than left unrestored. Hive partitions are
unioned by name, like shards. A single file reads only its own layout,
as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0149aXmZfe47GqaXBnt9DAWK
Struct-list SQL and the footer query for higher_better, when a column
becomes a struct, union_by_name for several files, ids that collide
across relayouted datasets and change with their input, exact matches
on rounded values, row order, and the DuckDB versions checked. Fix the
relayout memory options in the transform guide and point the view pages
to the struct form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0149aXmZfe47GqaXBnt9DAWK
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 215d72d7-67eb-45b6-86f3-57d7f695a7da

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@codacy-production

codacy-production Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 35 complexity · 0 duplication

Metric Results
Complexity 35
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@ypriverol
ypriverol requested a review from Shen-YuFei November 9, 2026 16:43
@ypriverol
ypriverol merged commit 778b8f3 into dev Nov 13, 2026
9 checks passed
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.

4 participants