Skip to content

[python] Preserve sequence.field bindings across column renames - #11634

Open
taoran92 wants to merge 2 commits into
apache:masterfrom
taoran92:fix/python-sequence-field-column-rename
Open

taoran92 wants to merge 2 commits into
apache:masterfrom
taoran92:fix/python-sequence-field-column-rename

Conversation

@taoran92

@taoran92 taoran92 commented Dec 2, 2026

Copy link
Copy Markdown
Member

Purpose

Fixes #11633

With sequence.field='t0, ts', renaming ts to stamp in PyPaimon's filesystem catalog can leave the option pointing to ts. Reads fail if the old name disappears and can select the wrong row version if another column takes that name.

Resolve sequence fields in their configured order and follow their field IDs through the ALTER batch. In this example, the catalog stores t0,stamp and keeps the original ts column as the tie-breaker, even if another column becomes ts. A SET that changes the option text resolves names against the schema at that point in the batch. Repeating the same text preserves the existing binding. A rename to an empty column name stores that sequence entry as a single space. If the option is t0, and an existing empty-named column is renamed to stamp, the catalog stores t0,stamp to preserve the SQLContext ordering.

Tests

  • Added regressions for padded and unpadded sequence options, name reuse and repeated renames within an ALTER batch, SET behavior, trailing separators, and empty or control-character column names.
  • The SQLContext suite and a native-plan sequence-ordering test passed with pypaimon-rust 0.5.0 (19 tests).
  • The sequence-field read and write, schema manager, and primary-key schema evolution suites passed in Python execution mode (170 tests).

@taoran92
taoran92 marked this pull request as ready for review December 2, 2026 13:19

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve an existing Java-readable sequence binding across Python ALTER

The rewrite resolves sequence entries through Python's strip(), but Java uses String.trim(). I created a primary-key table with columns named ts and \u00a0ts (leading non-breaking space), configured sequence.field=t0,\u00a0ts, wrote two versions, and renamed the latter column to stamp through the PyPaimon filesystem catalog.

The base implementation stored t0,stamp and the Java reader returned amount 100. This head leaves t0,\u00a0ts even though that exact column is gone, and a Java read of the actual table fails with “Sequence field … can not be found in table schema.” Please preserve a valid exact binding or reject an ambiguous cross-engine rename before publishing metadata, with a regression that reads the resulting table in Java.

The 170 pure Python and 18 Rust SQLContext tests passed. This case differs from the previously reported control-character cases because the base Java read succeeds.

@taoran92

taoran92 commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

[P2] Preserve an existing Java-readable sequence binding across Python ALTER

The rewrite resolves sequence entries through Python's strip(), but Java uses String.trim(). I created a primary-key table with columns named ts and \u00a0ts (leading non-breaking space), configured sequence.field=t0,\u00a0ts, wrote two versions, and renamed the latter column to stamp through the PyPaimon filesystem catalog.

The base implementation stored t0,stamp and the Java reader returned amount 100. This head leaves t0,\u00a0ts even though that exact column is gone, and a Java read of the actual table fails with “Sequence field … can not be found in table schema.” Please preserve a valid exact binding or reject an ambiguous cross-engine rename before publishing metadata, with a regression that reads the resulting table in Java.

The 170 pure Python and 18 Rust SQLContext tests passed. This case differs from the previously reported control-character cases because the base Java read succeeds.

Thanks for the reviewing & reproduction. PyPaimon now preserves the existing Java sequence field binding by field ID when rewriting sequence.field during a column rename. In your example, renaming \u00a0ts to stamp stores t0,stamp, and Java reads amount=100.

I added an end-to-end regression that writes and alters the table in PyPaimon, then reads it through the Java reader. It checks that Java returns amount=100 after renaming either the NBSP-prefixed column or the plain ts column. Both cases fail on the previous PR head and pass with this fix.

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] Renaming a sequence field can break PyPaimon reads or select the wrong row version

3 participants