Skip to content

Commit cd55763

Browse files
committed
fill
1 parent 09651c7 commit cd55763

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

parquet-variant-compute/src/variant_get/output/primitive.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
use std::env::var;
1819
use crate::variant_get::output::OutputBuilder;
1920
use crate::VariantArray;
2021
use arrow::array::{Array, ArrayRef, ArrowPrimitiveType, AsArray, BinaryViewArray, NullBufferBuilder, PrimitiveArray};
2122
use arrow::compute::{cast_with_options, CastOptions};
2223
use arrow_schema::{ArrowError, FieldRef};
23-
use parquet_variant::VariantPath;
24+
use parquet_variant::{Variant, VariantPath};
2425
use std::marker::PhantomData;
2526
use std::sync::Arc;
2627

@@ -64,7 +65,7 @@ impl<'a, T: ArrowPrimitiveType> OutputBuilder for PrimitiveOutputBuilder<'a, T>
6465
let mut values = Vec::with_capacity(variant_array.len());
6566
let typed_value =
6667
cast_with_options(typed_value, &self.as_type.data_type(), &self.cast_options)?;
67-
// downcast to the primitive type
68+
// downcast to the primitive array (e.g. Int32Array, Float64Array, etc)
6869
let typed_value = typed_value.as_primitive::<T>();
6970

7071
for i in 0..variant_array.len() {
@@ -74,19 +75,30 @@ impl<'a, T: ArrowPrimitiveType> OutputBuilder for PrimitiveOutputBuilder<'a, T>
7475
continue;
7576
}
7677

77-
nulls.append_non_null();
7878

79+
// if the typed value is null, decode the variant and extract the value
7980
if typed_value.is_null(i) {
80-
todo!()
81-
/*
82-
// fall back to the value (variant) field
83-
if let Some(value) = variant_array.value(i) {
84-
// extract the path from the variant and try to convert it to the desired type
85-
let extracted = value.get_path(&self.path)
86-
}
87-
*/
81+
// todo follow path
82+
let Some(variant) = variant_array.value(i) else {
83+
nulls.append_null();
84+
values.push(T::default_value()); // not used, placeholder
85+
continue;
86+
};
87+
88+
let Some(value) = extract_primitive_from_variant::<T>(&variant) else {
89+
return Err(ArrowError::CastError(format!(
90+
"Failed to extract primitive of type {:?} from variant {:?} at path {:?}",
91+
self.as_type.data_type(),
92+
variant,
93+
self.path
94+
)));
95+
};
96+
97+
nulls.append_non_null();
98+
values.push(value)
8899
} else {
89100
// otherwise we have a typed value, so we can use it directly
101+
nulls.append_non_null();
90102
values.push(typed_value.value(i));
91103
}
92104
}
@@ -125,3 +137,8 @@ impl<'a, T: ArrowPrimitiveType> OutputBuilder for PrimitiveOutputBuilder<'a, T>
125137
todo!()
126138
}
127139
}
140+
141+
/// extract a primitive value from a variant
142+
fn extract_primitive_from_variant<T: ArrowPrimitiveType>(variant: &Variant) -> Option<T::Native> {
143+
todo!()
144+
}

0 commit comments

Comments
 (0)