This is an automated email from the ASF dual-hosted git repository. XiaoHongbo-Hope pushed a commit to branch codex/release-2.1-rust-writer-compat in repository https://gitbox.apache.org/repos/asf/paimon.git
commit 4556746e47ab02edadde7003155d62e8b91f4afe Author: xiaohongbo <[email protected]> AuthorDate: Tue Nov 17 12:07:04 2026 +0800 [python] Align release-2.1 native APIs and CI with Rust 0.5.0 --- .github/workflows/ci-python.yml | 11 ++---- .../pypaimon/tests/native_builder_compat_test.py | 46 ---------------------- paimon-python/pypaimon/write/native_commit.py | 11 +----- paimon-python/pypaimon/write/native_merge_into.py | 24 ++++++----- paimon-python/pypaimon/write/native_update.py | 17 ++++---- paimon-python/pypaimon/write/native_write.py | 6 +-- paimon-python/pyproject.toml | 2 +- 7 files changed, 35 insertions(+), 82 deletions(-) diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml index 84f41a09d6..b1a8d92695 100644 --- a/.github/workflows/ci-python.yml +++ b/.github/workflows/ci-python.yml @@ -165,11 +165,10 @@ jobs: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal echo "$HOME/.cargo/bin" >> $GITHUB_PATH - - name: Build paimon-rust from the verified 2.1 revision + - name: Install paimon-rust 0.5.0 run: | python -m pip install --upgrade pip - # Keep the release branch on the revision verified by Native CI on 2026-10-08. - python -m pip install --upgrade "git+https://github.com/apache/paimon-rust.git@ae62495d275ccf3811c38128788be8cf7e144177#subdirectory=bindings/python" + python -m pip install "pypaimon-rust==0.5.0" - name: Install Python test dependencies run: | @@ -181,14 +180,12 @@ jobs: run: | python - <<'PY' import importlib.metadata as metadata - import json import pypaimon_rust.datafusion distribution = metadata.distribution('pypaimon-rust') - source = json.loads(distribution.read_text('direct_url.json')) - print('pypaimon-rust', distribution.version, - 'commit', source['vcs_info']['commit_id']) + assert distribution.version == '0.5.0' + print('pypaimon-rust', distribution.version) PY - name: Run Python tests with native planning, reading, writing, updating and committing diff --git a/paimon-python/pypaimon/tests/native_builder_compat_test.py b/paimon-python/pypaimon/tests/native_builder_compat_test.py deleted file mode 100644 index cb25205925..0000000000 --- a/paimon-python/pypaimon/tests/native_builder_compat_test.py +++ /dev/null @@ -1,46 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -"""Compatibility with old and public Rust builder APIs.""" - -import unittest -from unittest.mock import Mock - -from pypaimon.write.native_commit import with_native_commit_user - - -class NativeBuilderCompatTest(unittest.TestCase): - - def test_public_api_is_preferred(self): - builder = Mock(spec=['with_commit_user', '_with_commit_user']) - result = with_native_commit_user(builder, 'writer-id') - self.assertIs(result, builder.with_commit_user.return_value) - builder.with_commit_user.assert_called_once_with('writer-id') - builder._with_commit_user.assert_not_called() - - def test_legacy_api_is_supported(self): - builder = Mock(spec=['_with_commit_user']) - result = with_native_commit_user(builder, 'writer-id') - self.assertIs(result, builder._with_commit_user.return_value) - builder._with_commit_user.assert_called_once_with('writer-id') - - def test_public_api_errors_are_not_hidden_by_legacy_fallback(self): - builder = Mock(spec=['with_commit_user', '_with_commit_user']) - builder.with_commit_user.side_effect = AttributeError('failure inside builder') - with self.assertRaisesRegex(AttributeError, 'failure inside builder'): - with_native_commit_user(builder, 'writer-id') - builder._with_commit_user.assert_not_called() diff --git a/paimon-python/pypaimon/write/native_commit.py b/paimon-python/pypaimon/write/native_commit.py index ecef9e44cc..12548de66c 100644 --- a/paimon-python/pypaimon/write/native_commit.py +++ b/paimon-python/pypaimon/write/native_commit.py @@ -29,14 +29,6 @@ from pypaimon.write.commit_message_serializer import ( ) -def with_native_commit_user(builder, commit_user): - """Support public Rust builder APIs and the revision pinned by release-2.1.""" - method = getattr(builder, 'with_commit_user', None) - if method is None: - method = builder._with_commit_user - return method(commit_user) - - def native_commit_available() -> bool: """Whether the optional Rust bindings are installed.""" try: @@ -72,7 +64,8 @@ def create_native_commit(table, commit_user, overwrite_partition=None): if native_table is None: return None if overwrite_partition is not None: - return (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + return (native_table.new_batch_write_builder() + .with_commit_user(commit_user) .with_overwrite(overwrite_partition).new_commit()) # Append commits use the stream committer with the Python writer's identity; # Python enforces each mode's lifecycle and empty-commit rules. diff --git a/paimon-python/pypaimon/write/native_merge_into.py b/paimon-python/pypaimon/write/native_merge_into.py index 8652079f15..cd1e8c5d44 100644 --- a/paimon-python/pypaimon/write/native_merge_into.py +++ b/paimon-python/pypaimon/write/native_merge_into.py @@ -79,25 +79,31 @@ def create_native_merge_into(table, source, on, matched, not_matched, commit_use if source_type != target_type or not _supported_upsert_key_type(target_type): return None - def encode(clause): - values = [] + from pypaimon_rust.datafusion import MergeAssignment, WhenMatched, WhenNotMatched + + def encode(clause, not_matched=False): + values = {} for name, value in clause.spec.items(): if isinstance(value, SourceColumnRef): - values.append((name, 'source', value.column)) + values[name] = MergeAssignment.source_column(value.column) elif isinstance(value, TargetColumnRef): - values.append((name, 'target', value.column)) + values[name] = MergeAssignment.target_column(value.column) elif isinstance(value, LiteralValue): - values.append((name, 'literal', value.value)) + values[name] = MergeAssignment.literal(value.value) else: return None - condition = None if clause.condition is None else dict(sql=rewrite_condition(clause.condition)) - return dict(assignments=values, condition=condition, delete=clause.delete) + condition = None if clause.condition is None else rewrite_condition(clause.condition) + if not_matched: + return WhenNotMatched(values, condition) + if clause.delete: + return WhenMatched.delete(condition) + return WhenMatched.update(values, condition) encoded_matched = [encode(clause) for clause in matched] - encoded_not_matched = [encode(clause) for clause in not_matched] + encoded_not_matched = [encode(clause, not_matched=True) for clause in not_matched] if any(clause is None for clause in encoded_matched + encoded_not_matched): return None - builder = (native_table.new_batch_write_builder()._with_commit_user(commit_user) + builder = (native_table.new_batch_write_builder().with_commit_user(commit_user) if commit_identifier == BATCH_COMMIT_IDENTIFIER else native_table.new_stream_write_builder().with_commit_user(commit_user)) writer = builder.new_update() diff --git a/paimon-python/pypaimon/write/native_update.py b/paimon-python/pypaimon/write/native_update.py index 2ccc3495d2..1d80af544c 100644 --- a/paimon-python/pypaimon/write/native_update.py +++ b/paimon-python/pypaimon/write/native_update.py @@ -25,7 +25,7 @@ from pypaimon.snapshot.snapshot import BATCH_COMMIT_IDENTIFIER from pypaimon.snapshot.time_travel_util import SCAN_KEYS from pypaimon.table.file_store_table import FileStoreTable from pypaimon.write.native_commit import ( - create_native_write_table, from_native_commit_messages, with_native_commit_user, + create_native_write_table, from_native_commit_messages, ) from pypaimon.write.native_write import native_write_available, _native_partition_types_supported from pypaimon.write.table_update_by_row_id import TableUpdateByRowId @@ -58,7 +58,8 @@ def create_native_update(table, commit_user, columns): native_table = _native_row_id_table(table) if native_table is None: return None - writer = (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + writer = (native_table.new_batch_write_builder() + .with_commit_user(commit_user) .new_update()) if columns is not None: writer.with_update_type(columns) @@ -76,7 +77,7 @@ def create_native_update_by_row_id(table, commit_user, commit_identifier): if native_table is None: return None if commit_identifier == BATCH_COMMIT_IDENTIFIER: - writer = (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + writer = (native_table.new_batch_write_builder().with_commit_user(commit_user) .new_update().new_update_by_row_id()) else: writer = (native_table.new_stream_write_builder().with_commit_user(commit_user) @@ -152,7 +153,8 @@ def create_native_upsert(table, commit_user, data, keys, columns): or any(data.schema.field(name).type != schema.field(name).type for name in data.column_names)): return None - writer = (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + writer = (native_table.new_batch_write_builder() + .with_commit_user(commit_user) .new_update() .with_update_type(columns)) return NativeTableUpsert(table, writer, keys, data) @@ -171,8 +173,8 @@ def create_native_predicate_update(table, commit_user, predicate, columns=None): # Check predicate translation while fallback is still safe. Planning, # reading and callback execution belong to the core operation below. native_table.new_read_builder().with_filter(native_predicate) - writer = (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) - .new_update()) + writer = (native_table.new_batch_write_builder() + .with_commit_user(commit_user).new_update()) return NativePredicateTableUpdate(table, writer, native_predicate) @@ -201,7 +203,8 @@ def create_native_delete(table, commit_user): native_table = _native_row_id_table(table) if native_table is None: return None - writer = (with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + writer = (native_table.new_batch_write_builder() + .with_commit_user(commit_user) .new_update()) return NativeBatchTableUpdate(table, writer) diff --git a/paimon-python/pypaimon/write/native_write.py b/paimon-python/pypaimon/write/native_write.py index 0555c06206..f7166381f8 100644 --- a/paimon-python/pypaimon/write/native_write.py +++ b/paimon-python/pypaimon/write/native_write.py @@ -25,7 +25,7 @@ from pypaimon.schema.arrow_schema import arrow_schemas_compatible, normalize_arr from pypaimon.schema.data_types import PyarrowFieldParser, is_blob_file_field from pypaimon.table.bucket_mode import BucketMode from pypaimon.write.native_commit import ( - create_native_write_table, from_native_commit_messages, with_native_commit_user, + create_native_write_table, from_native_commit_messages, ) from pypaimon.write.row_utils import row_to_named_values, row_values_to_arrow_table @@ -70,7 +70,7 @@ def create_native_write(table, commit_user, static_partition=None, stream=False, if native_table is None: return None if fixed_bucket: - builder = with_native_commit_user(native_table.new_postpone_fixed_bucket_write_builder(), commit_user) + builder = native_table.new_postpone_fixed_bucket_write_builder().with_commit_user(commit_user) if bucket_plan is not None: builder = builder.with_bucket_plan(bucket_plan.to_arrow(table)) if static_partition is not None: @@ -80,7 +80,7 @@ def create_native_write(table, commit_user, static_partition=None, stream=False, if stream: builder = native_table.new_stream_write_builder().with_commit_user(commit_user) else: - builder = with_native_commit_user(native_table.new_batch_write_builder(), commit_user) + builder = native_table.new_batch_write_builder().with_commit_user(commit_user) if static_partition is not None: builder = builder.with_overwrite(static_partition) if restore_snapshot_id is not None: diff --git a/paimon-python/pyproject.toml b/paimon-python/pyproject.toml index 45a9602370..f8e97020f1 100644 --- a/paimon-python/pyproject.toml +++ b/paimon-python/pyproject.toml @@ -163,7 +163,7 @@ datafusion = [ ] sql = [ "pypaimon[datafusion]; python_version >= '3.10'", - "pypaimon-rust>=0.3.0; python_version >= '3.10'", + "pypaimon-rust>=0.5.0; python_version >= '3.10'", ] hdfs = [ "hdfs-native>=0.13,<1; python_version >= '3.10' and platform_system != 'Windows'",
