Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions parquet-variant-compute/src/variant_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ mod test {
use arrow::compute::CastOptions;
use arrow::datatypes::DataType::{Int16, Int32, Int64};
use arrow::datatypes::i256;
use arrow::util::display::FormatOptions;
use arrow_schema::DataType::{Boolean, Float32, Float64, Int8};
use arrow_schema::{DataType, Field, FieldRef, Fields, IntervalUnit, TimeUnit};
use chrono::DateTime;
Expand Down Expand Up @@ -1039,6 +1040,43 @@ mod test {
arrow::array::NullArray::new(3)
);

perfectly_shredded_variant_array_fn!(perfectly_shredded_null_variant_array_with_int, || {
Int32Array::from(vec![Some(32), Some(64), Some(48)])
});

// We append null values if type miss match happens in safe mode
perfectly_shredded_to_arrow_primitive_test!(
get_variant_perfectly_shredded_null_with_type_missmatch_in_safe_mode,
DataType::Null,
perfectly_shredded_null_variant_array_with_int,
arrow::array::NullArray::new(3)
);

// We'll return an error if type miss match happens in strict mode
#[test]
fn get_variant_perfectly_shredded_null_as_null_with_type_missmatch_in_strict_mode() {
let array = perfectly_shredded_null_variant_array_with_int();
let field = Field::new("typed_value", DataType::Null, true);
let options = GetOptions::new()
.with_as_type(Some(FieldRef::from(field)))
.with_cast_options(CastOptions {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use arrow::compute::CastOptions in variant_get and crate::CastOptions in cast_to_variant_with_options, not sure if we need to unify these in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we had similar discussion before. I vote for unifying them, and we don't really need the format_options in the arrow::compute::CastOptions

Copy link
Member Author

@klion26 klion26 Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will file an issue to track this
Filed an issue #8873

safe: false,
format_options: FormatOptions::default(),
});

let result = variant_get(&array, options);

assert!(result.is_err());
let error_msg = format!("{}", result.unwrap_err());
assert!(
error_msg
.contains("Cast error: Failed to extract primitive of type Null from variant Int32(32) at path VariantPath([])"),
"Expected=[Cast error: Failed to extract primitive of type Null from variant Int32(32) at path VariantPath([])],\
Got error message=[{}]",
error_msg
);
}

perfectly_shredded_variant_array_fn!(perfectly_shredded_decimal4_variant_array, || {
Decimal32Array::from(vec![Some(12345), Some(23400), Some(-12342)])
.with_precision_and_scale(5, 2)
Expand Down
21 changes: 13 additions & 8 deletions parquet-variant-compute/src/variant_to_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,24 +696,29 @@ impl VariantToBinaryVariantArrowRowBuilder {
}
}

struct FakeNullBuilder(NullArray);
#[derive(Default)]
struct FakeNullBuilder {
item_count: usize,
}

impl FakeNullBuilder {
fn new(capacity: usize) -> Self {
Self(NullArray::new(capacity))
fn append_value(&mut self, _: ()) {
self.item_count += 1;
}

fn append_null(&mut self) {
self.item_count += 1;
}
fn append_value<T>(&mut self, _: T) {}
fn append_null(&mut self) {}

fn finish(self) -> NullArray {
self.0
NullArray::new(self.item_count)
}
}

define_variant_to_primitive_builder!(
struct VariantToNullArrowRowBuilder<'a>
|capacity| -> FakeNullBuilder { FakeNullBuilder::new(capacity) },
|_value| Some(Variant::Null),
|_capacity| -> FakeNullBuilder { FakeNullBuilder::default() },
|value| value.as_null(),
type_name: "Null"
);

Expand Down
Loading