Repository navigation
feat(schema): mandatory identity ids (feature_id/psm_id/pg_id) + optional cross-refs - #232
Conversation
…onal cross-refs Every feature/psm/pg row now carries a single required int64 identity column that is the primary key of its view. The writer derives it as an opaque BLAKE2b hash of a footer-declared identity_composite of existing columns (or keeps a producer-supplied id), and stamps primary_key + identity_composite into the parquet footer so each file self-describes its key. Primary-key uniqueness validation catches any hash collision. - qpx/core/data/identity.py: derive_id() + canonical serialization - feature/psm/pg schemas (+ docs/spec mirror): id column as sole PK, identity_composite, and optional cross-ref columns feature.psm_ids / feature.pg_ids / psm.feature_id - writers/base.py: derive the id on the records / table / dataframe paths; footer stamp - loader/schema: parse + expose identity_composite - diann/dataset: null-fill the new columns on their table/SQL build paths - tests: tests/unit/test_identity.py + updates; full suite green (806 passed) Implements the agreed design in #229 (cross-refs optional; producer-specific identity_composite tuples to follow as their columns land, e.g. #230).
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 162 |
| Duplication | 0 |
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.
…ce count Adds Writer(override_provided_ids=True): when a producer supplies an id, re-derive the library id from the identity_composite and preserve the original as a provided_<id> cv_param, incrementing overridden_id_count so the converter can record the override in provenance (intended for consensusXML once it reads OpenMS UniqueIds). Default off — provided ids are kept. PK clashes stay warning-level in non-strict validation (during/after conversion). Adds override tests; suite 808 passed.
… + referential validation Completes the #229 identity design: PART 1 — per-converter feature identity_composite (Yufei's measured keys, existing columns only), passed to FeatureWriter and stamped in the footer: openms-consensus: [peptidoform,charge,run_file_name,rt,scan,observed_mz] maxquant: [peptidoform,charge,run_file_name,rt_start,rt_stop,scan] diann/spectronaut/cdap: [peptidoform,charge,run_file_name] fragpipe: schema default (needs compensation_voltage/quantification_unit_id, #230) openms -out_qpx: n/a (enriches existing feature.parquet, no FeatureWriter) PART 2 — openms-consensus populates feature.psm_ids (list) and psm.feature_id via deterministic derive_id over the same composites the writers use, in both the in-memory and single-pass streaming paths (equivalence preserved). PART 3 — dataset-level referential validation: non-null psm.feature_id must resolve to a feature.feature_id and each feature.psm_ids element to a psm.psm_id; unresolved refs are warnings (not errors), per the agreed design. Skipped gracefully on files lacking the columns. Full suite 812 passed; ruff clean. Resolves the hard-coded feature<->psm link (#182).
…lse positive) - ViewSchema: expose public primary_key property; writer uses it instead of _primary_key - rename BaseWriter._align_table_to_schema -> align_table_to_schema (called from dataset.py) - identity.py: build FIELD_SEP/NULL_TOKEN via chr() to avoid the 'hardcoded password' heuristic - CHANGELOG: blank line before the Changed list (MD032)
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
…, docs) Addresses the code-review findings on this PR: - identity.canonical(): sort list-valued composite fields (grouped_runs, scan) so order does not change the derived id — restores the order-insensitive identity the composite PK had; two rows differing only in list order now collide as duplicate_pk. - writers/base._fill_identity_table(): honor override_provided_ids on the write_table/write_dataframe path too (re-derive + stash provided id as cv_param + count), matching the record path. - writers/base.write_dataframe(): only backfill nullable columns (+ the derived id), so a genuinely missing required column errors clearly instead of deferring. - openms_consensus: pass _PSM_IDENTITY_COMPOSITE explicitly to PsmWriter (both paths) so the converter is the single source, not implicit schema-default coupling. - pg.py: update stale module docstring (pg PK is now the derived pg_id). Adds tests for list-order aliasing and table-path override. Suite 815 passed.
Addresses the Codex adversarial-review findings on PR #232: - [high] Deterministic ids across write paths: derive from persisted (Arrow-cast) values in one place (_fill_identity_table). write_batch/write_table/write_dataframe now yield identical ids for the same row (float32 rt no longer diverges record vs table path). Regression test test_ids_agree_across_write_paths. - [high] write_dataframe / align_table_to_schema derive the id BEFORE the non-nullable cast (relaxed nullable-id schema), so a frame/table without a precomputed id no longer fails casting a null id to non-nullable. Single derivation point avoids double-stash in override mode. - [medium] Injective canonical encoding: JSON (quoted/escaped) instead of a delimiter join, so list elements/fields containing commas/brackets cannot alias (['a,b','c'] vs ['a','b,c']). Order-insensitivity preserved. Test test_canonical_is_injective_json. - [medium] Referential validation flags reciprocal feature<->psm desync (warning), only where the opposite direction is populated. Test test_feature_psm_reciprocal_desync_is_warning. Not changed (intentional, per the agreed #229 design): producer-supplied ids are kept by default (not force-verified), and PK clashes are warnings in non-strict validation. Full suite 817 passed; ruff clean.
Summary
Implements the agreed identity design from #229: every
feature,psm, andpgrow carries a single mandatoryint64identity column —feature_id/psm_id/pg_id— that is the primary key of its view. The id is derived by the writer as an opaque hash of a footer-declaredidentity_compositeof existing columns (or kept as-is when a producer supplies its own). Converters are essentially unchanged — they emit the composite fields and the writer computes the id.How it works
qpx/core/data/identity.py—derive_id(values)= signed 64-bit BLAKE2b of a canonical serialization of the composite (unit-separator joined, NUL sentinel for null). Opaque; uniqueness is guaranteed by the PK validator, not by construction.feature/psm/pg, +docs/specmirror): id column added as the soleprimary_key; newidentity_compositekey declares the derivation input:[peptidoform, charge, run_file_name, rt][peptidoform, charge, run_file_name, scan][anchor_protein, grouped_runs, label]writers/base.py): derives the id on all three write paths (records /pa.Table/ DataFrame) only when absent (producer-supplied ids preserved), and stampsprimary_key+identity_compositeinto the parquet footer so each file self-describes its key. Views without anidentity_composite(mz/run/sample/…) are untouched.Optional cross-reference columns
Added (nullable, unpopulated by default):
feature.psm_ids(list<int64>),feature.pg_ids(list<int64>),psm.feature_id(int64). These let the views reference each other by id (feature ↔ PSM ↔ protein group), resolving the hard-coded feature↔PSM link in #182; a converter populates them where it can resolve the mapping.Scope / follow-ups
identity_compositetuples (Yufei's measured keys —observed_mz,compensation_voltage,quantification_unit_id) will be swapped in per converter as those columns land (e.g. feature: capture MBR match-metadata columns so match-transfer / co-eluting features stay distinguishable #230). The mechanism already supports it — only the declared composite changes.peptidoform-null → required-id rule is designed but not enabled here.Verification
tests/unit/test_identity.py).ruff check .+ruff format --check .clean.feature_id == derive_id(composite), cross-ref columns present, footer stampsprimary_key/identity_composite, validation passes.Related: #229 (design), #230 (MBR columns), #182 (feature↔PSM link), #231 (mzTab removal).