Skip to content

[python] Reject an empty sequence.field on CREATE and ALTER SET - #11640

Open
taoran92 wants to merge 1 commit into
apache:masterfrom
taoran92:fix/python-empty-sequence-field
Open

taoran92 wants to merge 1 commit into
apache:masterfrom
taoran92:fix/python-empty-sequence-field

Conversation

@taoran92

@taoran92 taoran92 commented Dec 2, 2026

Copy link
Copy Markdown
Member

Purpose

Fixes #11639

PyPaimon accepts and saves an empty sequence.field on CREATE and ALTER SET. On a table ordered by ts, setting the option to an empty string can change which row is returned without writing any new data because pure Python reads fall back to the default record ordering.

Reject the explicit empty string before publishing the schema. A rejected ALTER preserves the previous schema and ordering. Users can omit or remove the option to use the default record ordering.

Tests

  • Added regressions for CREATE and ALTER SET rejection, preservation of the previous schema, and removal of an empty option from existing table metadata.
  • Ran the schema manager, filesystem catalog, primary-key schema evolution, and sequence-field read and write suites in pure Python execution mode. All 194 tests passed.
  • Verified that a rejected ALTER on a populated table preserves the selected row and that removing the empty option from an affected table restores DataFusion reads.

@taoran92
taoran92 marked this pull request as ready for review December 2, 2026 15:14
raise ValueError(
f"Option '{sequence_field_key}' must not be empty. "
"Omit or remove it to use the default record ordering."
)

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.

In CoreOptions.sequence_field() (pypaimon/common/options/core_options.py:1645-1647), trailing empty segments are stripped via:

segments = raw.split(",")
while segments and segments[-1] == "":
    segments.pop()
return [name.strip() for name in segments]

Because of that loop, a comma-only value like "," (or ",,,") also evaluates core_options.sequence_field() to [], reproducing the exact same issue as "" (accepted on CREATE / ALTER SET, treated as omitted by pure Python reads, and rejected by DataFusion with Sequence field '' not found in table schema). Similarly, whitespace-only values like " " pass == "" at schema commit time and only fail later on read.

Since core_options = CoreOptions(Options(options)) is already constructed right below on line 811, consider checking not str(options.get(sequence_field_key)).strip() or not core_options.sequence_field() when sequence_field_key in options:

    core_options = CoreOptions(Options(options))
    sequence_field_key = CoreOptions.SEQUENCE_FIELD.key()
    if sequence_field_key in options and (
        not str(options[sequence_field_key]).strip()
        or not core_options.sequence_field()
    ):
        raise ValueError(
            f"Option '{sequence_field_key}' must not be empty. "
            "Omit or remove it to use the default record ordering."
        )

@taoran92 taoran92 Dec 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing out these cases. I checked both CREATE and ALTER SET on a primary-key table (id INT, ts INT) with bucket=1 and merge-engine=partial-update. For ALTER SET, the table started with sequence.field='ts'. Each result below applies to both operations.

sequence.field Java FileSystemCatalog PyPaimon before this PR PyPaimon with this PR DataFusion (pypaimon-rust 0.5.0)
'' Rejects Accepts Rejects Rejects
',' Accepts Accepts Accepts Rejects
' ' Rejects Accepts Accepts Rejects

For example, after writing (1, 10) and then (1, 9) in separate commits, the table ordered by ts returns 10. Before this PR, setting sequence.field='' makes PyPaimon return 9 without any new writes. With this PR, the ALTER is rejected and the next read still returns 10. That is the behavior #11639 addresses.

Rejecting ',' in PyPaimon would introduce a difference from Java. Whitespace-only values are a good follow-up. I also checked the proposed guard against an existing table with ' ' and found that it blocks an ALTER that only changes the table comment.

So I’d keep this PR and its regression tests focused on the literal empty string.

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] PyPaimon accepts an empty sequence.field on CREATE and ALTER SET

2 participants