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 e4b7ddd4e7909ce574bd47d40444c64aea3c6dda
Author: xiaohongbo <[email protected]>
AuthorDate: Tue Nov 17 11:57:09 2026 +0800

    [python] Support public Rust commit-user builder APIs on release-2.1
---
 .../pypaimon/tests/native_builder_compat_test.py   | 46 ++++++++++++++++++++++
 paimon-python/pypaimon/write/native_commit.py      | 11 +++++-
 paimon-python/pypaimon/write/native_update.py      | 17 ++++----
 paimon-python/pypaimon/write/native_write.py       |  6 +--
 4 files changed, 65 insertions(+), 15 deletions(-)

diff --git a/paimon-python/pypaimon/tests/native_builder_compat_test.py 
b/paimon-python/pypaimon/tests/native_builder_compat_test.py
new file mode 100644
index 0000000000..cb25205925
--- /dev/null
+++ b/paimon-python/pypaimon/tests/native_builder_compat_test.py
@@ -0,0 +1,46 @@
+# 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 91716cc357..ecef9e44cc 100644
--- a/paimon-python/pypaimon/write/native_commit.py
+++ b/paimon-python/pypaimon/write/native_commit.py
@@ -29,6 +29,14 @@ 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:
@@ -64,8 +72,7 @@ def create_native_commit(table, commit_user, 
overwrite_partition=None):
     if native_table is None:
         return None
     if overwrite_partition is not None:
-        return (native_table.new_batch_write_builder()
-                ._with_commit_user(commit_user)
+        return 
(with_native_commit_user(native_table.new_batch_write_builder(), 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_update.py 
b/paimon-python/pypaimon/write/native_update.py
index 3175d30226..2ccc3495d2 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,
+    create_native_write_table, from_native_commit_messages, 
with_native_commit_user,
 )
 from pypaimon.write.native_write import native_write_available, 
_native_partition_types_supported
 from pypaimon.write.table_update_by_row_id import TableUpdateByRowId
@@ -58,8 +58,7 @@ def create_native_update(table, commit_user, columns):
     native_table = _native_row_id_table(table)
     if native_table is None:
         return None
-    writer = (native_table.new_batch_write_builder()
-              ._with_commit_user(commit_user)
+    writer = (with_native_commit_user(native_table.new_batch_write_builder(), 
commit_user)
               .new_update())
     if columns is not None:
         writer.with_update_type(columns)
@@ -77,7 +76,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 = 
(native_table.new_batch_write_builder()._with_commit_user(commit_user)
+        writer = 
(with_native_commit_user(native_table.new_batch_write_builder(), commit_user)
                   .new_update().new_update_by_row_id())
     else:
         writer = 
(native_table.new_stream_write_builder().with_commit_user(commit_user)
@@ -153,8 +152,7 @@ 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 = (native_table.new_batch_write_builder()
-              ._with_commit_user(commit_user)
+    writer = (with_native_commit_user(native_table.new_batch_write_builder(), 
commit_user)
               .new_update()
               .with_update_type(columns))
     return NativeTableUpsert(table, writer, keys, data)
@@ -173,8 +171,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 = (native_table.new_batch_write_builder()
-              ._with_commit_user(commit_user).new_update())
+    writer = (with_native_commit_user(native_table.new_batch_write_builder(), 
commit_user)
+              .new_update())
     return NativePredicateTableUpdate(table, writer, native_predicate)
 
 
@@ -203,8 +201,7 @@ def create_native_delete(table, commit_user):
     native_table = _native_row_id_table(table)
     if native_table is None:
         return None
-    writer = (native_table.new_batch_write_builder()
-              ._with_commit_user(commit_user)
+    writer = (with_native_commit_user(native_table.new_batch_write_builder(), 
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 bdc7a98518..0555c06206 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,
+    create_native_write_table, from_native_commit_messages, 
with_native_commit_user,
 )
 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 = 
native_table.new_postpone_fixed_bucket_write_builder()._with_commit_user(commit_user)
+        builder = 
with_native_commit_user(native_table.new_postpone_fixed_bucket_write_builder(), 
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 = 
native_table.new_batch_write_builder()._with_commit_user(commit_user)
+        builder = 
with_native_commit_user(native_table.new_batch_write_builder(), commit_user)
         if static_partition is not None:
             builder = builder.with_overwrite(static_partition)
     if restore_snapshot_id is not None:

Reply via email to