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

alamb pushed a commit to branch branch-51
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/branch-51 by this push:
     new 37c00ab1fd [branch-51] Backport Fix for Creating Null FixedSizeBinary 
Arrays to DF 51Branch (#19017)
37c00ab1fd is described below

commit 37c00ab1fdf5e74305f9dea38c725d6d675b2adf
Author: Tobias Schwarzinger <[email protected]>
AuthorDate: Tue Dec 2 22:40:13 2025 +0100

    [branch-51] Backport Fix for Creating Null FixedSizeBinary Arrays to DF 
51Branch (#19017)
    
    ## Which issue does this PR close?
    
    Backports https://github.com/apache/datafusion/pull/18903 to DF 51
    branch
    
    ## Rationale for this change
    
    Fix the bug in a future 51.1.0 release
    (https://github.com/apache/datafusion/issues/18843)
    
    ## What changes are included in this PR?
    
    Same as in https://github.com/apache/datafusion/pull/18903
    
    ## Are these changes tested?
    
    Yes.
    
    ## Are there any user-facing changes?
    
    Yes, fix the original bug and create a non-zero sized values buffer in
    the case that exhibits the bug.
---
 datafusion/common/src/scalar/mod.rs | 39 +++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/datafusion/common/src/scalar/mod.rs 
b/datafusion/common/src/scalar/mod.rs
index fadd2e41ea..5b119ab305 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -60,15 +60,15 @@ use arrow::array::{
     Date64Array, Decimal128Array, Decimal256Array, Decimal32Array, 
Decimal64Array,
     DictionaryArray, DurationMicrosecondArray, DurationMillisecondArray,
     DurationNanosecondArray, DurationSecondArray, FixedSizeBinaryArray,
-    FixedSizeListArray, Float16Array, Float32Array, Float64Array, 
GenericListArray,
-    Int16Array, Int32Array, Int64Array, Int8Array, IntervalDayTimeArray,
-    IntervalMonthDayNanoArray, IntervalYearMonthArray, LargeBinaryArray, 
LargeListArray,
-    LargeStringArray, ListArray, MapArray, MutableArrayData, OffsetSizeTrait,
-    PrimitiveArray, Scalar, StringArray, StringViewArray, StructArray,
-    Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
-    Time64NanosecondArray, TimestampMicrosecondArray, 
TimestampMillisecondArray,
-    TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array,
-    UInt64Array, UInt8Array, UnionArray,
+    FixedSizeBinaryBuilder, FixedSizeListArray, Float16Array, Float32Array, 
Float64Array,
+    GenericListArray, Int16Array, Int32Array, Int64Array, Int8Array,
+    IntervalDayTimeArray, IntervalMonthDayNanoArray, IntervalYearMonthArray,
+    LargeBinaryArray, LargeListArray, LargeStringArray, ListArray, MapArray,
+    MutableArrayData, OffsetSizeTrait, PrimitiveArray, Scalar, StringArray,
+    StringViewArray, StructArray, Time32MillisecondArray, Time32SecondArray,
+    Time64MicrosecondArray, Time64NanosecondArray, TimestampMicrosecondArray,
+    TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray,
+    UInt16Array, UInt32Array, UInt64Array, UInt8Array, UnionArray,
 };
 use arrow::buffer::{BooleanBuffer, ScalarBuffer};
 use arrow::compute::kernels::cast::{cast_with_options, CastOptions};
@@ -2989,7 +2989,14 @@ impl ScalarValue {
                     )
                     .unwrap(),
                 ),
-                None => Arc::new(FixedSizeBinaryArray::new_null(*s, size)),
+                None => {
+                    // TODO: Replace with FixedSizeBinaryArray::new_null once 
a fix for
+                    // https://github.com/apache/arrow-rs/issues/8900 is in 
the used arrow-rs
+                    // version.
+                    let mut builder = FixedSizeBinaryBuilder::new(*s);
+                    builder.append_nulls(size);
+                    Arc::new(builder.finish())
+                }
             },
             ScalarValue::LargeBinary(e) => match e {
                 Some(value) => Arc::new(
@@ -5172,6 +5179,18 @@ mod tests {
         assert_eq!(empty_array.len(), 0);
     }
 
+    /// See https://github.com/apache/datafusion/issues/18870
+    #[test]
+    fn test_to_array_of_size_for_none_fsb() {
+        let sv = ScalarValue::FixedSizeBinary(5, None);
+        let result = sv
+            .to_array_of_size(2)
+            .expect("Failed to convert to array of size");
+        assert_eq!(result.len(), 2);
+        assert_eq!(result.null_count(), 2);
+        assert_eq!(result.as_fixed_size_binary().values().len(), 10);
+    }
+
     #[test]
     fn test_list_to_array_string() {
         let scalars = vec![


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to