Skip to content

[python] Preserve declared primary-key order in merge reads - #9801

Open
wangzhigang1999 wants to merge 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-primary-key-read-order
Open

wangzhigang1999 wants to merge 1 commit into
apache:masterfrom
wangzhigang1999:fix/python-primary-key-read-order

Conversation

@wangzhigang1999

Copy link
Copy Markdown
Contributor

Purpose

Fixes #9800

When a composite primary key is declared in a different order from the table columns, PyPaimon can return both the old and updated row. For example, four orders with PRIMARY KEY (order_id, customer_id) produce five rows after one update when customer_id precedes order_id in the table schema.

Build merge-read key fields from the table's ordered trimmed primary-key fields, matching the writer's sort order. This preserves field IDs, types and the storage format. Regression coverage checks complete merged results, value-only projections, partition-key trimming and a primary-key column position change across schema versions.

Tests

Validation: the new regression tests fail before the fix; all 70 tests in reader_primary_key_test, schema_evolution_pk_read_test, projection_predicate_index_test and test_sequence_field_read pass after it. Flake8 on changed files and git diff --check pass. Local validation used Python 3.12.6 and PyArrow 19.0.1.

Copilot AI lite review requested due to automatic review settings September 14, 2026 04:08

Copilot AI 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.

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

Fixes merge-read deduplication by preserving declared composite primary-key order.

Changes:

  • Builds merge keys from ordered trimmed primary-key fields.
  • Adds coverage for projections, partitions, reordered keys, and schema changes.
File summaries
File Summary
paimon-python/pypaimon/tests/schema_evolution_pk_read_test.py Tests primary-key position changes across schemas.
paimon-python/pypaimon/tests/reader_primary_key_test.py Tests composite-key ordering and projections.
paimon-python/pypaimon/read/split_read.py Aligns merge-key construction with writer sort order.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

[Bug] [python] Duplicate rows when composite primary-key order differs from column order

2 participants