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 f3a4698f36 [Varaint]: add `DataType::Null` support to cast_to_variant
(#8107)
f3a4698f36 is described below
commit f3a4698f36e749f2c352e8a08de2e39352b94f76
Author: feniljain <[email protected]>
AuthorDate: Wed Aug 13 21:59:21 2025 +0530
[Varaint]: add `DataType::Null` support to cast_to_variant (#8107)
# Which issue does this PR close?
- Closes #8053
# Are these changes tested?
Yes
# Notes
From this comment:
```
/// # Notes
/// If the input array element is null, the corresponding element in the
/// output `VariantArray` will also be null (not `Variant::Null`).
```
I think we need to make a variant array of nulls, do correct me if I am
wrong here, and a `Variant::Null` needs to be returned 😅
Co-authored-by: Andrew Lamb <[email protected]>
---
parquet-variant-compute/src/cast_to_variant.rs | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/parquet-variant-compute/src/cast_to_variant.rs
b/parquet-variant-compute/src/cast_to_variant.rs
index bce3a427a0..ed40538cab 100644
--- a/parquet-variant-compute/src/cast_to_variant.rs
+++ b/parquet-variant-compute/src/cast_to_variant.rs
@@ -229,6 +229,11 @@ pub fn cast_to_variant(input: &dyn Array) ->
Result<VariantArray, ArrowError> {
DataType::FixedSizeBinary(_) => {
non_generic_conversion!(as_fixed_size_binary, |v| v, input,
builder);
}
+ DataType::Null => {
+ for _ in 0..input.len() {
+ builder.append_null();
+ }
+ }
dt => {
return Err(ArrowError::CastError(format!(
"Unsupported data type for casting to Variant: {dt:?}",
@@ -248,8 +253,8 @@ mod tests {
use arrow::array::{
ArrayRef, BooleanArray, Decimal128Array, Decimal256Array,
Decimal32Array, Decimal64Array,
FixedSizeBinaryBuilder, Float16Array, Float32Array, Float64Array,
GenericByteBuilder,
- GenericByteViewBuilder, Int16Array, Int32Array, Int64Array, Int8Array,
UInt16Array,
- UInt32Array, UInt64Array, UInt8Array,
+ GenericByteViewBuilder, Int16Array, Int32Array, Int64Array, Int8Array,
NullArray,
+ UInt16Array, UInt32Array, UInt64Array, UInt8Array,
};
use arrow_schema::{
DECIMAL128_MAX_PRECISION, DECIMAL32_MAX_PRECISION,
DECIMAL64_MAX_PRECISION,
@@ -588,6 +593,11 @@ mod tests {
)
}
+ #[test]
+ fn test_cast_to_variant_null() {
+ run_test(Arc::new(NullArray::new(2)), vec![None, None])
+ }
+
#[test]
fn test_cast_to_variant_decimal32() {
run_test(