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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-12266-7dd9f12d7410dfa9b55d97d650eb1d9f16cc5ad6
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit d1efb23dc1fbb0046d61fc9ab816a50f8ee0bba9
Author: Bharadwaj Pendyala <[email protected]>
AuthorDate: Mon Nov 16 14:43:53 2026 +0000

    fix(parquet): accept empty Thrift lists regardless of declared element type 
(#12266)
    
    # Which issue does this PR close?
    
    - Closes #12265.
    
    # Rationale for this change
    
    fastparquet writes the empty `row_groups` list of a 0-row file as a
    single `0x00` header. #8827 made `read_list_begin` accept that header,
    but the element type check added in #9924 still rejects it. These files
    fail to open with "Expected list element type of Struct but got Byte".
    
    # What changes are included in this PR?
    
    `validate_list_type` skips the element type check when the list is
    empty. Every caller loops over `size`. An empty list therefore decodes
    no elements, while non-empty lists are checked as before.
    
    This accepts any empty list header, not only `0x00`, as suggested in the
    issue. The narrower alternative is to accept only the `Byte` placeholder
    that `read_list_begin` returns for `0x00`.
    
    # Are these changes tested?
    
    Yes. `test_file_reader_empty_row_groups_with_zero_list_header` writes a
    0-row file, patches the `row_groups` list header in the footer from
    `0x0C` to `0x00`, and opens it. `test_read_empty_list_with_zero_header`
    covers `read_thrift_vec` directly. Both fail on main with the error from
    the issue.
    
    # Are there any significant user-facing changes?
    
    No.
    
    # AI usage disclosure
    
    I used Claude to write the fix, the tests and this description. I
    reproduced the failure and ran the parquet test suite locally before
    opening the PR.
---
 parquet/src/file/serialized_reader.rs | 23 +++++++++++++++++++++++
 parquet/src/parquet_thrift.rs         | 12 +++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/parquet/src/file/serialized_reader.rs 
b/parquet/src/file/serialized_reader.rs
index a7b8206f94..79ca64f37c 100644
--- a/parquet/src/file/serialized_reader.rs
+++ b/parquet/src/file/serialized_reader.rs
@@ -2222,6 +2222,29 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_file_reader_empty_row_groups_with_zero_list_header() {
+        let schema = parse_message_type("message test_schema { OPTIONAL INT32 
k; }").unwrap();
+        let mut out = Vec::new();
+        SerializedFileWriter::new(&mut out, Arc::new(schema), 
Default::default())
+            .unwrap()
+            .close()
+            .unwrap();
+
+        // fastparquet writes the empty row_groups list header as 0x00 instead
+        // of 0x0C (size 0, struct). Patch the footer to match: num_rows = 0
+        // (field 3, i64) followed by the row_groups field header and list 
header.
+        let pos = out
+            .windows(4)
+            .position(|w| w == [0x16, 0x00, 0x19, 0x0C])
+            .expect("empty row_groups list header not found in footer");
+        out[pos + 3] = 0x00;
+
+        let reader = SerializedFileReader::new(Bytes::from(out)).unwrap();
+        assert_eq!(reader.metadata().num_row_groups(), 0);
+        assert_eq!(reader.metadata().file_metadata().num_rows(), 0);
+    }
+
     #[test]
     // Use java parquet-tools get below pageIndex info
     // !```
diff --git a/parquet/src/parquet_thrift.rs b/parquet/src/parquet_thrift.rs
index 91402b84d0..88d773b731 100644
--- a/parquet/src/parquet_thrift.rs
+++ b/parquet/src/parquet_thrift.rs
@@ -774,7 +774,9 @@ where
 }
 
 pub(crate) fn validate_list_type(expected: ElementType, got: &ListIdentifier) 
-> Result<()> {
-    if got.element_type != expected {
+    // An empty list decodes no elements, and some writers (e.g. fastparquet)
+    // encode it as a bare 0x00 header with no meaningful element type.
+    if got.element_type != expected && got.size != 0 {
         return Err(general_err!(
             "Expected list element type of {:?} but got {:?}",
             expected,
@@ -1340,6 +1342,14 @@ pub(crate) mod tests {
         assert_eq!(header.element_type, ElementType::Byte);
     }
 
+    #[test]
+    fn test_read_empty_list_with_zero_header() {
+        let data = [0u8];
+        let mut prot = ThriftSliceInputProtocol::new(&data);
+        let result = read_thrift_vec::<i32, ThriftSliceInputProtocol>(&mut 
prot).unwrap();
+        assert!(result.is_empty());
+    }
+
     /// A Thrift list header whose `size` varint decodes above `i32::MAX`
     /// must be rejected at the protocol layer rather than wrapping into a
     /// negative `i32` and being smuggled into downstream allocation code.

Reply via email to