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

JingsongLi 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 1828251ea0 [python] Raise format table read and listing errors (#11005)
1828251ea0 is described below

commit 1828251ea0b3e106bbd071a5bdc93fe1666cf853
Author: Jiajia Li <[email protected]>
AuthorDate: Fri Nov 6 23:56:45 2026 +0800

    [python] Raise format table read and listing errors (#11005)
---
 .../execution/python/read/format_table_read.py     | 17 ++++---
 .../execution/python/read/format_table_scan.py     |  3 +-
 .../pypaimon/tests/format_write_execution_test.py  | 55 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/paimon-python/pypaimon/execution/python/read/format_table_read.py 
b/paimon-python/pypaimon/execution/python/read/format_table_read.py
index 2d2b6e9863..2186fe56b7 100644
--- a/paimon-python/pypaimon/execution/python/read/format_table_read.py
+++ b/paimon-python/pypaimon/execution/python/read/format_table_read.py
@@ -67,7 +67,8 @@ def _read_file_to_arrow(
     except Exception as e:
         raise RuntimeError(f"Failed to read {path}") from e
 
-    if not data or len(data) == 0:
+    if not data and fmt != Format.PARQUET:
+        # Java's ORC reader reads a zero-byte file as empty, as Hive writes 
them.
         return pyarrow.table({})
 
     if fmt == Format.PARQUET:
@@ -76,12 +77,10 @@ def _read_file_to_arrow(
         data = (
             bytes(data) if not isinstance(data, bytes) else data
         )
-        if len(data) < 4 or data[:4] != b"PAR1":
-            return pyarrow.table({})
         try:
             tbl = pq.read_table(io.BytesIO(data))
-        except pyarrow.ArrowInvalid:
-            return pyarrow.table({})
+        except (pyarrow.ArrowException, OSError) as e:
+            raise RuntimeError(f"Failed to read {path}") from e
     elif fmt == Format.CSV:
         import pyarrow.csv as csv
         try:
@@ -89,8 +88,8 @@ def _read_file_to_arrow(
                 pyarrow.BufferReader(data),
                 read_options=csv_read_options,
             )
-        except Exception:
-            return pyarrow.table({})
+        except (pyarrow.ArrowException, OSError) as e:
+            raise RuntimeError(f"Failed to read {path}") from e
     elif fmt == Format.JSON:
         import json
         text = data.decode("utf-8") if isinstance(data, bytes) else data
@@ -108,8 +107,8 @@ def _read_file_to_arrow(
         data = bytes(data) if not isinstance(data, bytes) else data
         try:
             tbl = orc.read_table(io.BytesIO(data))
-        except Exception:
-            return pyarrow.table({})
+        except (pyarrow.ArrowException, OSError) as e:
+            raise RuntimeError(f"Failed to read {path}") from e
     elif fmt == Format.TEXT:
         text = data.decode("utf-8") if isinstance(data, bytes) else data
         lines = (
diff --git a/paimon-python/pypaimon/execution/python/read/format_table_scan.py 
b/paimon-python/pypaimon/execution/python/read/format_table_scan.py
index 71c8dbba5a..d36501273e 100644
--- a/paimon-python/pypaimon/execution/python/read/format_table_scan.py
+++ b/paimon-python/pypaimon/execution/python/read/format_table_scan.py
@@ -51,7 +51,8 @@ def _list_data_files_recursive(
     rel_path_parts = rel_path_parts or []
     try:
         infos = file_io.list_status(path)
-    except Exception:
+    except FileNotFoundError:
+        # The directory vanished after its parent listed it.
         return splits
     if not infos:
         return splits
diff --git a/paimon-python/pypaimon/tests/format_write_execution_test.py 
b/paimon-python/pypaimon/tests/format_write_execution_test.py
index 49822f922a..0b09d2441f 100644
--- a/paimon-python/pypaimon/tests/format_write_execution_test.py
+++ b/paimon-python/pypaimon/tests/format_write_execution_test.py
@@ -197,3 +197,58 @@ def 
test_format_batch_write_public_overrides_are_honored(tmp_path, input_method,
     assert batches[0].to_pydict() == data.to_pydict()
     assert _rows(writer.prepare_commit()[0].written_paths) == [1, 2]
     writer.close()
+
+
[email protected]('file_format, content', [
+    (Format.PARQUET, b'not a data file'), (Format.ORC, b'not a data file'), 
(Format.CSV, b'a,b\n1,2,3\n')])
+def test_format_read_raises_on_unreadable_file(tmp_path, file_format, content):
+    table = _table(tmp_path)
+    table._format = file_format
+    directory = Path(table.location()) / 'pt=a'
+    directory.mkdir(parents=True)
+    (directory / ('bad.' + file_format.value)).write_bytes(content)
+    reader = table.new_read_builder()
+    with pytest.raises(RuntimeError, match='Failed to read .*bad'):
+        reader.new_read().to_arrow(reader.new_scan().plan().splits())
+
+
[email protected]('file_format, readable', [(Format.PARQUET, False), 
(Format.ORC, True), (Format.CSV, True)])
+def test_format_reads_zero_byte_files_like_java(tmp_path, file_format, 
readable):
+    table = _table(tmp_path)
+    table._format = file_format
+    directory = Path(table.location()) / 'pt=a'
+    directory.mkdir(parents=True)
+    (directory / ('empty.' + file_format.value)).write_bytes(b'')
+    reader = table.new_read_builder()
+    splits = reader.new_scan().plan().splits()
+    if readable:
+        assert reader.new_read().to_arrow(splits).num_rows == 0
+    else:
+        with pytest.raises(RuntimeError, match='Failed to read .*empty'):
+            reader.new_read().to_arrow(splits)
+
+
+def test_format_scan_raises_listing_errors(tmp_path):
+    table = _table(tmp_path)
+    with patch.object(type(table.file_io), 'list_status', 
side_effect=OSError('connection reset')):
+        with pytest.raises(OSError, match='connection reset'):
+            table.new_read_builder().new_scan().plan()
+
+
+def test_format_scan_skips_directory_that_vanishes_after_listing(tmp_path):
+    table = _table(tmp_path)
+    for pt in ('a', 'b'):
+        directory = Path(table.location()) / f'pt={pt}'
+        directory.mkdir(parents=True)
+        pq.write_table(pa.table({'id': [1]}), str(directory / 'data.parquet'))
+    file_io_type = type(table.file_io)
+    list_status = file_io_type.list_status
+
+    def list_status_while_pt_b_vanishes(self, path):
+        if path.rstrip('/').endswith('pt=b'):
+            raise FileNotFoundError(path)
+        return list_status(self, path)
+
+    with patch.object(file_io_type, 'list_status', 
list_status_while_pt_b_vanishes):
+        splits = table.new_read_builder().new_scan().plan().splits()
+    assert [split.partition for split in splits] == [{'pt': 'a'}]

Reply via email to