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

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new d1ec77065c DeltaBitPackEncoderConversion: Fix panic message on invalid 
type (#9552)
d1ec77065c is described below

commit d1ec77065c6b606bce97b7acd51b2079182822ad
Author: Val Lorentz <[email protected]>
AuthorDate: Tue Mar 17 20:00:09 2026 +0100

    DeltaBitPackEncoderConversion: Fix panic message on invalid type (#9552)
    
    # Which issue does this PR close?
    
    - Closes #9551.
    
    # Rationale for this change
    
    DeltaBitPackDecoder supports Int32Type, UInt32Type, Int64Type, and
    UInt64Type; but the error message claimed it supported only Int32Type
    and Int64Type
    
    # What changes are included in this PR?
    
    * changed the error message
    * deduplicated the string
    * extended `ensure_phys_ty!()` to allow anything `panic!()` does
    
    # Are these changes tested?
    
    no
    
    # Are there any user-facing changes?
    
    only the panic message
    
    ---------
    
    Co-authored-by: DaniĆ«l Heres <[email protected]>
    Co-authored-by: Andrew Lamb <[email protected]>
---
 parquet/Cargo.toml                    |  5 ++++
 parquet/src/data_type.rs              |  4 +--
 parquet/src/encodings/encoding/mod.rs | 16 +++++------
 parquet/tests/arrow_writer.rs         | 50 +++++++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 11 deletions(-)

diff --git a/parquet/Cargo.toml b/parquet/Cargo.toml
index 9ab59f4e7e..4be7793024 100644
--- a/parquet/Cargo.toml
+++ b/parquet/Cargo.toml
@@ -165,6 +165,11 @@ name = "arrow_reader"
 required-features = ["arrow"]
 path = "./tests/arrow_reader/mod.rs"
 
+[[test]]
+name = "arrow_writer"
+required-features = ["arrow"]
+path = "./tests/arrow_writer.rs"
+
 [[test]]
 name = "encryption"
 required-features = ["arrow"]
diff --git a/parquet/src/data_type.rs b/parquet/src/data_type.rs
index df5702d1bb..d8c7b92013 100644
--- a/parquet/src/data_type.rs
+++ b/parquet/src/data_type.rs
@@ -1331,10 +1331,10 @@ impl AsRef<[u8]> for FixedLenByteArray {
 
 /// Macro to reduce repetition in making type assertions on the physical type 
against `T`
 macro_rules! ensure_phys_ty {
-    ($($ty:pat_param)|+ , $err: literal) => {
+    ($($ty:pat_param)|+ , $($arg:tt)*) => {
         match T::get_physical_type() {
             $($ty => (),)*
-            _ => panic!($err),
+            _ => panic!($($arg)*),
         };
     }
 }
diff --git a/parquet/src/encodings/encoding/mod.rs 
b/parquet/src/encodings/encoding/mod.rs
index e5e74ac53f..eeabcf4ba5 100644
--- a/parquet/src/encodings/encoding/mod.rs
+++ b/parquet/src/encodings/encoding/mod.rs
@@ -522,20 +522,18 @@ trait DeltaBitPackEncoderConversion<T: DataType> {
     fn subtract_u64(&self, left: i64, right: i64) -> u64;
 }
 
+const DELTA_BIT_PACK_TYPE_ERROR: &str =
+    "DeltaBitPackDecoder only supports Int32Type, UInt32Type, Int64Type, and 
UInt64Type";
+
 impl<T: DataType> DeltaBitPackEncoderConversion<T> for DeltaBitPackEncoder<T> {
     #[inline]
     fn assert_supported_type() {
-        ensure_phys_ty!(
-            Type::INT32 | Type::INT64,
-            "DeltaBitPackDecoder only supports Int32Type and Int64Type"
-        );
+        ensure_phys_ty!(Type::INT32 | Type::INT64, "{}", 
DELTA_BIT_PACK_TYPE_ERROR);
     }
 
     #[inline]
     fn as_i64(&self, values: &[T::T], index: usize) -> i64 {
-        values[index]
-            .as_i64()
-            .expect("DeltaBitPackDecoder only supports Int32Type and 
Int64Type")
+        values[index].as_i64().expect(DELTA_BIT_PACK_TYPE_ERROR)
     }
 
     #[inline]
@@ -544,7 +542,7 @@ impl<T: DataType> DeltaBitPackEncoderConversion<T> for 
DeltaBitPackEncoder<T> {
         match T::get_physical_type() {
             Type::INT32 => (left as i32).wrapping_sub(right as i32) as i64,
             Type::INT64 => left.wrapping_sub(right),
-            _ => panic!("DeltaBitPackDecoder only supports Int32Type and 
Int64Type"),
+            _ => panic!("{}", DELTA_BIT_PACK_TYPE_ERROR),
         }
     }
 
@@ -554,7 +552,7 @@ impl<T: DataType> DeltaBitPackEncoderConversion<T> for 
DeltaBitPackEncoder<T> {
             // Conversion of i32 -> u32 -> u64 is to avoid non-zero left most 
bytes in int repr
             Type::INT32 => (left as i32).wrapping_sub(right as i32) as u32 as 
u64,
             Type::INT64 => left.wrapping_sub(right) as u64,
-            _ => panic!("DeltaBitPackDecoder only supports Int32Type and 
Int64Type"),
+            _ => panic!("{}", DELTA_BIT_PACK_TYPE_ERROR),
         }
     }
 }
diff --git a/parquet/tests/arrow_writer.rs b/parquet/tests/arrow_writer.rs
new file mode 100644
index 0000000000..020b4c6267
--- /dev/null
+++ b/parquet/tests/arrow_writer.rs
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Tests for [`ArrowWriter`]
+
+use arrow::array::Float64Array;
+use arrow::datatypes::{DataType, Field, Schema};
+use arrow::record_batch::RecordBatch;
+use parquet::arrow::ArrowWriter;
+use parquet::basic::Encoding;
+use parquet::file::properties::WriterProperties;
+use std::sync::Arc;
+
+#[test]
+#[should_panic(
+    expected = "DeltaBitPackDecoder only supports Int32Type, UInt32Type, 
Int64Type, and UInt64Type"
+)]
+fn test_delta_bit_pack_type() {
+    let props = WriterProperties::builder()
+        .set_column_encoding("col".into(), Encoding::DELTA_BINARY_PACKED)
+        .build();
+
+    let record_batch = RecordBatch::try_new(
+        Arc::new(Schema::new(vec![Field::new(
+            "col",
+            DataType::Float64,
+            false,
+        )])),
+        vec![Arc::new(Float64Array::from_iter_values(vec![1., 2.]))],
+    )
+    .unwrap();
+
+    let mut buffer = Vec::new();
+    let mut writer = ArrowWriter::try_new(&mut buffer, record_batch.schema(), 
Some(props)).unwrap();
+    let _ = writer.write(&record_batch);
+}

Reply via email to