This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 3486c67b [core] Treat zero-byte ORC files as empty in Format Tables
(#1529)
3486c67b is described below
commit 3486c67b643bf0349888417f1fe421a98c8d00f3
Author: Jingsong Lee <[email protected]>
AuthorDate: Tue Nov 24 16:18:09 2026 +0800
[core] Treat zero-byte ORC files as empty in Format Tables (#1529)
---
.../datafusion/tests/rest_format_partition_sql.rs | 34 ++++++++++++++++++++
crates/paimon/src/arrow/format/mod.rs | 2 ++
crates/paimon/src/table/format_table_scan.rs | 5 +++
.../paimon/src/table/format_table_write_tests.rs | 37 ++++++++++++++++++++++
4 files changed, 78 insertions(+)
diff --git a/crates/integrations/datafusion/tests/rest_format_partition_sql.rs
b/crates/integrations/datafusion/tests/rest_format_partition_sql.rs
index 800d3265..3a02cc12 100644
--- a/crates/integrations/datafusion/tests/rest_format_partition_sql.rs
+++ b/crates/integrations/datafusion/tests/rest_format_partition_sql.rs
@@ -906,6 +906,40 @@ async fn
test_analyze_and_scan_count_only_the_files_a_reader_returns() {
);
}
+#[cfg(not(windows))]
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn test_analyze_counts_empty_orc_files_as_zero_rows() {
+ let temp_dir = tempfile::tempdir().unwrap();
+ let schema = Schema::builder()
+ .column("dt", varchar())
+ .column("id", DataType::BigInt(BigIntType::new()))
+ .partition_keys(["dt"])
+ .option("type", "format-table")
+ .option("file.format", "orc")
+ .option("metastore.partitioned-table", "true")
+ .build()
+ .unwrap();
+ let (server, context) = setup_rest_table(&temp_dir, schema).await;
+ common::exec(
+ &context,
+ &format!("ALTER TABLE {TABLE_NAME} ADD PARTITION (dt = 'a')"),
+ )
+ .await;
+ common::exec(
+ &context,
+ &format!("INSERT INTO {TABLE_NAME} (dt, id) VALUES ('a', 1), ('a',
2)"),
+ )
+ .await;
+ std::fs::write(temp_dir.path().join("dt=a/empty.orc"), b"").unwrap();
+
+ common::exec(
+ &context,
+ &format!("ANALYZE TABLE {TABLE_NAME} COMPUTE STATISTICS"),
+ )
+ .await;
+ assert_eq!(counts(&partition_statistics(&server)["dt=a"]), (2, 2));
+}
+
#[cfg(not(windows))]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_analyze_leaves_a_row_count_unknown_rather_than_short() {
diff --git a/crates/paimon/src/arrow/format/mod.rs
b/crates/paimon/src/arrow/format/mod.rs
index 2d1fbe2e..85571fd1 100644
--- a/crates/paimon/src/arrow/format/mod.rs
+++ b/crates/paimon/src/arrow/format/mod.rs
@@ -364,6 +364,8 @@ pub(crate) async fn read_file_row_count(
.await
.map(Some)
}
+ // Hive's zero-byte ORC outputs contain no rows, as in Format Table
scans.
+ "orc" if file_size == 0 => Ok(Some(0)),
"orc" => {
let reader = file_io.new_input(path)?.reader().await?;
orc::read_row_count(Box::new(reader), file_size)
diff --git a/crates/paimon/src/table/format_table_scan.rs
b/crates/paimon/src/table/format_table_scan.rs
index 79c2790d..87205220 100644
--- a/crates/paimon/src/table/format_table_scan.rs
+++ b/crates/paimon/src/table/format_table_scan.rs
@@ -123,6 +123,11 @@ impl<'a> FormatTableScan<'a> {
.await?;
let mut splits = Vec::new();
for status in files {
+ // Java ORC treats Hive's zero-byte outputs as empty files.
+ // The listing helper has already statted entries with a
reported size of zero.
+ if format_extension == ".orc" && status.size == 0 {
+ continue;
+ }
if let Some(split) = self.status_to_split(
status,
table_path,
diff --git a/crates/paimon/src/table/format_table_write_tests.rs
b/crates/paimon/src/table/format_table_write_tests.rs
index 94baa8e8..4a3515ac 100644
--- a/crates/paimon/src/table/format_table_write_tests.rs
+++ b/crates/paimon/src/table/format_table_write_tests.rs
@@ -1146,6 +1146,43 @@ async fn java_format_table_formats_round_trip() {
}
}
+#[tokio::test]
+async fn orc_format_table_reads_hive_empty_files_as_empty() {
+ let table = memory_table("format_orc_hive_empty", true, &[("file.format",
"orc")]);
+ append(&table, &batch(&[("a", 1), ("b", 2)])).await;
+ table
+ .file_io()
+ .new_output(&format!("{}/dt=a/empty.orc", table.location()))
+ .unwrap()
+ .write(Bytes::new())
+ .await
+ .unwrap();
+ assert_eq!(ids(&table).await, [1, 2]);
+}
+
+#[tokio::test]
+async fn orc_format_table_reports_corrupt_nonempty_files() {
+ let table = memory_table("format_orc_corrupt", false, &[("file.format",
"orc")]);
+ table
+ .file_io()
+ .new_output(&format!("{}/corrupt.orc", table.location()))
+ .unwrap()
+ .write(Bytes::from_static(b"invalid ORC data"))
+ .await
+ .unwrap();
+ let reader = table.new_read_builder();
+ let plan = reader.new_scan().plan().await.unwrap();
+ let error = reader
+ .new_read()
+ .unwrap()
+ .to_arrow(plan.splits())
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap_err();
+ assert!(error.to_string().contains("Failed to open ORC file"));
+}
+
#[tokio::test]
async fn csv_and_json_format_tables_read_unterminated_final_rows() {
for format in ["csv", "json"] {