You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by lz...@apache.org on 2026/03/19 00:50:05 UTC

(paimon) branch master updated: [python] Support partition.default-name to fix read null/empty partition values error (#7472)

This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new cc05f2fd99 [python] Support partition.default-name to fix read null/empty partition values error  (#7472)
cc05f2fd99 is described below

commit cc05f2fd9950a151f3c08ab27af90779af01a443
Author: XiaoHongbo <13...@qq.com>
AuthorDate: Thu Mar 19 08:49:58 2026 +0800

    [python] Support partition.default-name to fix read null/empty partition values error  (#7472)
---
 .../test/java/org/apache/paimon/JavaPyE2ETest.java    | 19 ++++++++++++++++++-
 .../java/org/apache/paimon/JavaPyLanceE2ETest.java    |  5 ++++-
 paimon-python/pypaimon/common/options/core_options.py | 10 ++++++++++
 .../pypaimon/manifest/schema/data_file_meta.py        |  8 ++++++--
 .../read/scanner/data_evolution_split_generator.py    |  3 ++-
 .../pypaimon/read/scanner/split_generator.py          |  6 +++++-
 paimon-python/pypaimon/table/file_store_table.py      |  3 ++-
 .../pypaimon/tests/e2e/java_py_read_write_test.py     |  9 +++++++--
 .../pypaimon/utils/file_store_path_factory.py         | 14 +++++++++++++-
 9 files changed, 67 insertions(+), 10 deletions(-)

diff --git a/paimon-core/src/test/java/org/apache/paimon/JavaPyE2ETest.java b/paimon-core/src/test/java/org/apache/paimon/JavaPyE2ETest.java
index 636d250518..22283fdd11 100644
--- a/paimon-core/src/test/java/org/apache/paimon/JavaPyE2ETest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/JavaPyE2ETest.java
@@ -235,6 +235,22 @@ public class JavaPyE2ETest {
                         createRow7Cols(
                                 6, "Beef", "Meat", 8.0, 1000005L, 2000005L, 6000, "store3", 1006L,
                                 "London", "UK"));
+                // Row with null partition value -> __DEFAULT_PARTITION__
+                write.write(
+                        GenericRow.of(
+                                7,
+                                BinaryString.fromString("Tofu"),
+                                null,
+                                3.0,
+                                org.apache.paimon.data.Timestamp.fromEpochMillis(1000006L),
+                                org.apache.paimon.data.Timestamp.fromEpochMillis(2000006L),
+                                7000,
+                                GenericRow.of(
+                                        BinaryString.fromString("store4"),
+                                        1007L,
+                                        GenericRow.of(
+                                                BinaryString.fromString("Paris"),
+                                                BinaryString.fromString("France")))));
 
                 commit.commit(0, write.prepareCommit(true, 0));
             }
@@ -251,7 +267,8 @@ public class JavaPyE2ETest {
                             "+I[3, Carrot, Vegetable, 0.6, 1970-01-01T00:16:40.002, 1970-01-01T00:33:20.002, 3000, (store2, 1003, (Tokyo, Japan))]",
                             "+I[4, Broccoli, Vegetable, 1.2, 1970-01-01T00:16:40.003, 1970-01-01T00:33:20.003, 4000, (store2, 1004, (Seoul, Korea))]",
                             "+I[5, Chicken, Meat, 5.0, 1970-01-01T00:16:40.004, 1970-01-01T00:33:20.004, 5000, (store3, 1005, (NewYork, USA))]",
-                            "+I[6, Beef, Meat, 8.0, 1970-01-01T00:16:40.005, 1970-01-01T00:33:20.005, 6000, (store3, 1006, (London, UK))]");
+                            "+I[6, Beef, Meat, 8.0, 1970-01-01T00:16:40.005, 1970-01-01T00:33:20.005, 6000, (store3, 1006, (London, UK))]",
+                            "+I[7, Tofu, NULL, 3.0, 1970-01-01T00:16:40.006, 1970-01-01T00:33:20.006, 7000, (store4, 1007, (Paris, France))]");
         }
     }
 
diff --git a/paimon-lance/src/test/java/org/apache/paimon/JavaPyLanceE2ETest.java b/paimon-lance/src/test/java/org/apache/paimon/JavaPyLanceE2ETest.java
index a431657b95..034ba5d3b6 100644
--- a/paimon-lance/src/test/java/org/apache/paimon/JavaPyLanceE2ETest.java
+++ b/paimon-lance/src/test/java/org/apache/paimon/JavaPyLanceE2ETest.java
@@ -237,6 +237,8 @@ public class JavaPyLanceE2ETest {
             write.write(createRow(4, "Broccoli", "Vegetable", 1.2));
             write.write(createRow(5, "Chicken", "Meat", 5.0));
             write.write(createRow(6, "Beef", "Meat", 8.0));
+            // Row with null partition value -> __DEFAULT_PARTITION__
+            write.write(GenericRow.of(7, BinaryString.fromString("Tofu"), null, 3.0));
 
             commit.commit(0, write.prepareCommit(true, 0));
         }
@@ -256,7 +258,8 @@ public class JavaPyLanceE2ETest {
                         "3, Carrot, Vegetable, 0.6",
                         "4, Broccoli, Vegetable, 1.2",
                         "5, Chicken, Meat, 5.0",
-                        "6, Beef, Meat, 8.0");
+                        "6, Beef, Meat, 8.0",
+                        "7, Tofu, NULL, 3.0");
     }
 
     @Test
diff --git a/paimon-python/pypaimon/common/options/core_options.py b/paimon-python/pypaimon/common/options/core_options.py
index 0f954b3de9..9636a58932 100644
--- a/paimon-python/pypaimon/common/options/core_options.py
+++ b/paimon-python/pypaimon/common/options/core_options.py
@@ -404,6 +404,16 @@ class CoreOptions:
         )
     )
 
+    PARTITION_DEFAULT_NAME: ConfigOption[str] = (
+        ConfigOptions.key("partition.default-name")
+        .string_type()
+        .default_value("__DEFAULT_PARTITION__")
+        .with_description(
+            "The default partition name in case the dynamic partition"
+            " column value is null/empty string."
+        )
+    )
+
     def __init__(self, options: Options):
         self.options = options
 
diff --git a/paimon-python/pypaimon/manifest/schema/data_file_meta.py b/paimon-python/pypaimon/manifest/schema/data_file_meta.py
index 01ad241765..870dde7aa7 100644
--- a/paimon-python/pypaimon/manifest/schema/data_file_meta.py
+++ b/paimon-python/pypaimon/manifest/schema/data_file_meta.py
@@ -26,6 +26,7 @@ from pypaimon.data.timestamp import Timestamp
 from pypaimon.manifest.schema.simple_stats import (KEY_STATS_SCHEMA, VALUE_STATS_SCHEMA,
                                                    SimpleStats)
 from pypaimon.table.row.generic_row import GenericRow
+from pypaimon.utils.file_store_path_factory import _is_null_or_whitespace_only
 
 
 @dataclass
@@ -130,11 +131,14 @@ class DataFileMeta:
             file_path=file_path,
         )
 
-    def set_file_path(self, table_path: str, partition: GenericRow, bucket: int):
+    def set_file_path(
+            self, table_path: str, partition: GenericRow, bucket: int,
+            default_part_value: str = "__DEFAULT_PARTITION__"):
         path_builder = table_path.rstrip('/')
         partition_dict = partition.to_dict()
         for field_name, field_value in partition_dict.items():
-            path_builder = f"{path_builder}/{field_name}={str(field_value)}"
+            part_value = default_part_value if _is_null_or_whitespace_only(field_value) else str(field_value)
+            path_builder = f"{path_builder}/{field_name}={part_value}"
         path_builder = f"{path_builder}/bucket-{str(bucket)}/{self.file_name}"
         self.file_path = path_builder
 
diff --git a/paimon-python/pypaimon/read/scanner/data_evolution_split_generator.py b/paimon-python/pypaimon/read/scanner/data_evolution_split_generator.py
index d4c928a22e..81b6420b6e 100644
--- a/paimon-python/pypaimon/read/scanner/data_evolution_split_generator.py
+++ b/paimon-python/pypaimon/read/scanner/data_evolution_split_generator.py
@@ -133,7 +133,8 @@ class DataEvolutionSplitGenerator(AbstractSplitGenerator):
                 data_file.set_file_path(
                     self.table.table_path,
                     file_entries[0].partition,
-                    file_entries[0].bucket
+                    file_entries[0].bucket,
+                    self.default_part_value
                 )
 
             if file_group:
diff --git a/paimon-python/pypaimon/read/scanner/split_generator.py b/paimon-python/pypaimon/read/scanner/split_generator.py
index f11240a8a9..2b934be85f 100644
--- a/paimon-python/pypaimon/read/scanner/split_generator.py
+++ b/paimon-python/pypaimon/read/scanner/split_generator.py
@@ -18,6 +18,7 @@ limitations under the License.
 from abc import ABC, abstractmethod
 from typing import Callable, List, Optional, Dict, Tuple
 
+from pypaimon.common.options.core_options import CoreOptions
 from pypaimon.manifest.schema.data_file_meta import DataFileMeta
 from pypaimon.manifest.schema.manifest_entry import ManifestEntry
 from pypaimon.read.split import Split
@@ -45,6 +46,8 @@ class AbstractSplitGenerator(ABC):
         self.target_split_size = target_split_size
         self.open_file_cost = open_file_cost
         self.deletion_files_map = deletion_files_map or {}
+        self.default_part_value = table.options.options.get(
+            CoreOptions.PARTITION_DEFAULT_NAME, "__DEFAULT_PARTITION__")
         
         # Shard configuration
         self.idx_of_this_subtask = None
@@ -102,7 +105,8 @@ class AbstractSplitGenerator(ABC):
                 data_file.set_file_path(
                     self.table.table_path,
                     file_entries[0].partition,
-                    file_entries[0].bucket
+                    file_entries[0].bucket,
+                    self.default_part_value
                 )
 
             if file_group:
diff --git a/paimon-python/pypaimon/table/file_store_table.py b/paimon-python/pypaimon/table/file_store_table.py
index 7200f857ff..bb9587cc28 100644
--- a/paimon-python/pypaimon/table/file_store_table.py
+++ b/paimon-python/pypaimon/table/file_store_table.py
@@ -299,7 +299,8 @@ class FileStoreTable(Table):
         return FileStorePathFactory(
             root=str(self.table_path),
             partition_keys=self.partition_keys,
-            default_part_value="__DEFAULT_PARTITION__",
+            default_part_value=self.options.options.get(
+                CoreOptions.PARTITION_DEFAULT_NAME, "__DEFAULT_PARTITION__"),
             format_identifier=format_identifier,
             data_file_prefix="data-",
             changelog_file_prefix="changelog-",
diff --git a/paimon-python/pypaimon/tests/e2e/java_py_read_write_test.py b/paimon-python/pypaimon/tests/e2e/java_py_read_write_test.py
index 60a58c752c..f53d244e54 100644
--- a/paimon-python/pypaimon/tests/e2e/java_py_read_write_test.py
+++ b/paimon-python/pypaimon/tests/e2e/java_py_read_write_test.py
@@ -235,7 +235,7 @@ class JavaPyReadWriteTest(unittest.TestCase):
         print(f"Format: {file_format}, Result:\n{res}")
 
         # Verify data
-        self.assertEqual(len(res), 6)
+        self.assertEqual(len(res), 7)
         if file_format != "lance":
             self.assertEqual(table.fields[4].type.type, "TIMESTAMP(6)")
             self.assertEqual(table.fields[5].type.type, "TIMESTAMP(6) WITH LOCAL TIME ZONE")
@@ -250,10 +250,15 @@ class JavaPyReadWriteTest(unittest.TestCase):
             self.assertIsInstance(metadata_fields[2].type, RowType)
         
         # Data order may vary due to partitioning/bucketing, so compare as sets
-        expected_names = {'Apple', 'Banana', 'Carrot', 'Broccoli', 'Chicken', 'Beef'}
+        expected_names = {'Apple', 'Banana', 'Carrot', 'Broccoli', 'Chicken', 'Beef', 'Tofu'}
         actual_names = set(res['name'].tolist())
         self.assertEqual(actual_names, expected_names)
 
+        # Verify null partition value (default partition) is readable
+        tofu_row = res[res['name'] == 'Tofu']
+        self.assertEqual(len(tofu_row), 1)
+        self.assertTrue(pd.isna(tofu_row['category'].iloc[0]))
+
         # Verify metadata column can be read and contains nested structures
         if 'metadata' in res.columns:
             self.assertFalse(res['metadata'].isnull().all())
diff --git a/paimon-python/pypaimon/utils/file_store_path_factory.py b/paimon-python/pypaimon/utils/file_store_path_factory.py
index db2c4c6c11..c5d53c8f52 100644
--- a/paimon-python/pypaimon/utils/file_store_path_factory.py
+++ b/paimon-python/pypaimon/utils/file_store_path_factory.py
@@ -21,6 +21,13 @@ from pypaimon.common.external_path_provider import ExternalPathProvider
 from pypaimon.table.bucket_mode import BucketMode
 
 
+def _is_null_or_whitespace_only(value) -> bool:
+    if value is None:
+        return True
+    s = str(value)
+    return len(s) == 0 or s.isspace()
+
+
 class FileStorePathFactory:
     MANIFEST_PATH = "manifest"
     MANIFEST_PREFIX = "manifest-"
@@ -91,7 +98,12 @@ class FileStorePathFactory:
         if partition:
             partition_parts = []
             for i, field_name in enumerate(self.partition_keys):
-                partition_parts.append(f"{field_name}={partition[i]}")
+                val = partition[i]
+                if _is_null_or_whitespace_only(val):
+                    val = self.default_part_value
+                else:
+                    val = str(val)
+                partition_parts.append(f"{field_name}={val}")
             if partition_parts:
                 relative_parts = partition_parts + relative_parts