Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 2 additions & 7 deletions parquet-variant-compute/src/cast_to_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use arrow::temporal_conversions::{
};
use arrow_schema::{ArrowError, DataType, TimeUnit};
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
#[allow(unused_imports)]
use half::f16;
use parquet_variant::{
Variant, VariantBuilder, VariantDecimal16, VariantDecimal4, VariantDecimal8,
Expand Down Expand Up @@ -185,13 +186,7 @@ pub fn cast_to_variant(input: &dyn Array) -> Result<VariantArray, ArrowError> {
primitive_conversion_array!(UInt64Type, input, builder);
}
DataType::Float16 => {
generic_conversion_array!(
Float16Type,
as_primitive,
|v: f16| -> f32 { v.into() },
input,
builder
);
generic_conversion_array!(Float16Type, as_primitive, f32::from, input, builder);
}
DataType::Float32 => {
primitive_conversion_array!(Float32Type, input, builder);
Expand Down
23 changes: 13 additions & 10 deletions parquet-variant-compute/src/type_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ macro_rules! non_generic_conversion_single_value {
($method:ident, $cast_fn:expr, $input:expr, $index:expr) => {{
let array = $input.$method();
if array.is_null($index) {
return Variant::Null;
Variant::Null
} else {
let cast_value = $cast_fn(array.value($index));
Variant::from(cast_value)
}
let cast_value = $cast_fn(array.value($index));
Variant::from(cast_value)
}};
}

Expand All @@ -54,7 +55,7 @@ macro_rules! non_generic_conversion_single_value {
#[macro_export]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: There's no point (publicly) exporting a macro that references $crate -- compilation will fail for any use sites outside this crate. Can do pub(crate) use generic_conversion_array to make it visible everywhere inside the crate.

macro_rules! generic_conversion_array {
($t:ty, $method:ident, $cast_fn:expr, $input:expr, $builder:expr) => {{
non_generic_conversion_array!($input.$method::<$t>(), $cast_fn, $builder)
$crate::non_generic_conversion_array!($input.$method::<$t>(), $cast_fn, $builder)
}};
}

Expand All @@ -66,10 +67,11 @@ macro_rules! generic_conversion_single_value {
($t:ty, $method:ident, $cast_fn:expr, $input:expr, $index:expr) => {{
let array = $input.$method::<$t>();
if array.is_null($index) {
return Variant::Null;
Variant::Null
} else {
let cast_value = $cast_fn(array.value($index));
Variant::from(cast_value)
}
let cast_value = $cast_fn(array.value($index));
Variant::from(cast_value)
}};
}

Expand All @@ -78,7 +80,7 @@ macro_rules! generic_conversion_single_value {
#[macro_export]
macro_rules! primitive_conversion_array {
($t:ty, $input:expr, $builder:expr) => {{
generic_conversion_array!($t, as_primitive, |v| v, $input, $builder)
$crate::generic_conversion_array!($t, as_primitive, |v| v, $input, $builder)
}};
}

Expand All @@ -88,9 +90,10 @@ macro_rules! primitive_conversion_single_value {
($t:ty, $input:expr, $index:expr) => {{
let array = $input.as_primitive::<$t>();
if array.is_null($index) {
return Variant::Null;
Variant::Null
} else {
Variant::from(array.value($index))
}
Variant::from(array.value($index))
}};
}

Expand Down
5 changes: 1 addition & 4 deletions parquet-variant-compute/src/variant_get/output/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
// under the License.

use crate::variant_get::output::OutputBuilder;
use crate::{
generic_conversion_array, non_generic_conversion_array, primitive_conversion_array,
VariantArray, VariantArrayBuilder,
};
use crate::{primitive_conversion_array, VariantArray, VariantArrayBuilder};
use arrow::array::{Array, ArrayRef, AsArray, BinaryViewArray};
use arrow::datatypes::{Int16Type, Int32Type};
use arrow_schema::{ArrowError, DataType};
Expand Down
Loading