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 cc016196dfbf9d127c2f31bf79b177bfc09e33d5
Author: xiaohongbo <[email protected]>
AuthorDate: Tue Nov 17 15:06:41 2026 +0800

    [python] Preserve hidden NULL children during row updates
---
 .../read/reader/nested_leaf_batch_reader.py        |  5 ++-
 .../pypaimon/tests/runtime_read_schema_test.py     | 43 ++++++++++++++++++++++
 .../pypaimon/write/table_update_by_row_id.py       | 30 +++++++--------
 3 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/paimon-python/pypaimon/read/reader/nested_leaf_batch_reader.py 
b/paimon-python/pypaimon/read/reader/nested_leaf_batch_reader.py
index cb4c4f81c4..c28e285816 100644
--- a/paimon-python/pypaimon/read/reader/nested_leaf_batch_reader.py
+++ b/paimon-python/pypaimon/read/reader/nested_leaf_batch_reader.py
@@ -28,7 +28,8 @@ from pypaimon.read.reader.data_file_batch_reader import \
 from pypaimon.read.reader.field_indices import (
     blob_field_indices, descriptor_field_indices, vector_field_indices)
 from pypaimon.read.reader.iface.record_batch_reader import RecordBatchReader
-from pypaimon.schema.data_types import DataField, PyarrowFieldParser
+from pypaimon.schema.arrow_schema import read_arrow_schema
+from pypaimon.schema.data_types import DataField
 from pypaimon.utils.arrow_utils import as_blob_data, is_blob_data
 
 
@@ -61,7 +62,7 @@ class NestedLeafBatchReader(RecordBatchReader):
                     len(name_paths), len(output_fields)))
         self._inner = inner
         self._paths = name_paths
-        self._schema = PyarrowFieldParser.from_paimon_schema(output_fields)
+        self._schema = read_arrow_schema(output_fields)
         self.file_io = inner.file_io
         self.blob_field_indices = blob_field_indices(output_fields)
         self.descriptor_field_indices = descriptor_field_indices(
diff --git a/paimon-python/pypaimon/tests/runtime_read_schema_test.py 
b/paimon-python/pypaimon/tests/runtime_read_schema_test.py
index ab5a5d5d5d..1b5733e3c2 100644
--- a/paimon-python/pypaimon/tests/runtime_read_schema_test.py
+++ b/paimon-python/pypaimon/tests/runtime_read_schema_test.py
@@ -181,3 +181,46 @@ def 
test_de_column_group_merge_uses_runtime_nested_schema(tmp_path, native_write
         assert result['value'].to_pylist() == values
         assert result['untouched'].to_pylist() == [10, 11, 12, 13]
         assert table.fields[1].to_dict() == field_before
+
+
[email protected]('native_write', [False, True])
+def test_partial_row_update_preserves_hidden_null_children(tmp_path, 
native_write):
+    pytest.importorskip('pypaimon_rust.data')
+    from pypaimon.tests.native_nested_update_test import _table
+    data_type = pa.struct([pa.field('value', pa.int32(), nullable=False)])
+    table, _ = _table(tmp_path, data_type, native_write)
+    seed = table.new_batch_write_builder()
+    writer, commit = seed.new_write(), seed.new_commit()
+    try:
+        writer.write_arrow(pa.Table.from_pylist(
+            [{'id': i, 'value': None, 'untouched': i + 10} for i in range(4, 
8)],
+            schema=read_arrow_schema(table.fields)))
+        commit.commit(writer.prepare_commit())
+    finally:
+        writer.close()
+        commit.close()
+    fields_before = [field.to_dict() for field in table.fields]
+    builder = table.new_batch_write_builder()
+    updater = builder.new_update().with_update_type(['value'])
+    changes = pa.table({'_ROW_ID': pa.array([5], type=pa.int64()),
+                        'value': pa.array([{'value': 7}], type=data_type)})
+    messages = updater.update_by_arrow_with_row_id(changes)
+    commit = builder.new_commit()
+    try:
+        commit.commit(messages)
+    finally:
+        commit.close()
+    for native_read in (False, True):
+        copy = table.copy({'read.native.enabled': str(native_read).lower(),
+                           'scan.native-plan.enabled': 
str(native_read).lower()})
+        reader = copy.new_read_builder()
+        result = 
reader.new_read().to_arrow(reader.new_scan().plan().splits()).sort_by('id')
+        assert result['value'].to_pylist() == [None] * 5 + [{'value': 7}, 
None, None]
+        assert result['untouched'].to_pylist() == list(range(10, 18))
+    assert [field.to_dict() for field in table.fields] == fields_before
+    snapshot = table.snapshot_manager().get_latest_snapshot().id
+    bad = pa.table({'_ROW_ID': pa.array([5], type=pa.int64()),
+                    'value': pa.array([{'value': None}], 
type=pa.struct([('value', pa.int32())]))})
+    with pytest.raises((ValueError, TypeError), match='[Nn]ull'):
+        
table.new_batch_write_builder().new_update().with_update_type(['value']).update_by_arrow_with_row_id(bad)
+    assert table.snapshot_manager().get_latest_snapshot().id == snapshot
diff --git a/paimon-python/pypaimon/write/table_update_by_row_id.py 
b/paimon-python/pypaimon/write/table_update_by_row_id.py
index f8735566f7..acfda44911 100644
--- a/paimon-python/pypaimon/write/table_update_by_row_id.py
+++ b/paimon-python/pypaimon/write/table_update_by_row_id.py
@@ -667,25 +667,23 @@ class TableUpdateByRowId:
         return merged_table, blob_columns
 
     def _normalize_write_data(self, data):
-        # DE reads relax nested nullability. Restore and validate the declared
-        # write types at the writer boundary, including untouched input 
batches.
         write_schema = PyarrowFieldParser.from_paimon_schema(
             [self.table.field_dict[name] for name in data.schema.names])
-        normalized = normalize_arrow_write_nullability(data, write_schema)
-        # Reads relax field nullability for schema evolution. A projected
-        # update must still enforce the declared write type, as Java's
-        # TableWrite.withWriteType does for every selected output column.
-        for field, column in zip(write_schema, normalized.columns):
+        # Validate visible children against the declared write constraints.
+        # Keep the input nested types for Parquet: hidden NULL children under
+        # a NULL parent are legal and still need nullable transport fields.
+        normalize_arrow_write_nullability(data, write_schema)
+        for field, column in zip(write_schema, data.columns):
             self._check_write_not_null(field.name, column.null_count > 0)
-        if any(actual.nullable != expected.nullable
-               for actual, expected in zip(normalized.schema, write_schema)):
-            fields = [actual.with_nullable(expected.nullable)
-                      for actual, expected in zip(normalized.schema, 
write_schema)]
-            schema = pa.schema(fields, metadata=normalized.schema.metadata)
-            if isinstance(normalized, pa.RecordBatch):
-                return pa.RecordBatch.from_arrays(normalized.columns, 
schema=schema)
-            return pa.Table.from_arrays(normalized.columns, schema=schema)
-        return normalized
+        fields = [pa.field(actual.name, actual.type, 
nullable=expected.nullable,
+                           metadata=expected.metadata)
+                  for actual, expected in zip(data.schema, write_schema)]
+        schema = pa.schema(fields, metadata=write_schema.metadata)
+        if data.schema.equals(schema, check_metadata=True):
+            return data
+        if isinstance(data, pa.RecordBatch):
+            return pa.RecordBatch.from_arrays(data.columns, schema=schema)
+        return pa.Table.from_arrays(data.columns, schema=schema)
 
     def _check_write_not_null(self, column_name, has_null):
         if not self.table.field_dict[column_name].type.nullable and has_null:

Reply via email to