From 264cf8488d2a6f0303c62b8ff9811027cd6f6976 Mon Sep 17 00:00:00 2001 From: Yin Jifeng Date: Tue, 23 Jan 2024 13:53:22 +0800 Subject: [PATCH] chore: use Utf8View instead of BinaryView --- crates/polars-arrow/src/compute/cast/decimal_to.rs | 8 ++++---- crates/polars-arrow/src/compute/cast/mod.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/polars-arrow/src/compute/cast/decimal_to.rs b/crates/polars-arrow/src/compute/cast/decimal_to.rs index ad6e979e79e2..adb79b034780 100644 --- a/crates/polars-arrow/src/compute/cast/decimal_to.rs +++ b/crates/polars-arrow/src/compute/cast/decimal_to.rs @@ -140,7 +140,7 @@ where /// Returns a [`Utf8Array`] where every element is the utf8 representation of the decimal. #[cfg(feature = "dtype-decimal")] -pub(super) fn decimal_to_binview(from: &PrimitiveArray) -> BinaryViewArray { +pub(super) fn decimal_to_utf8view(from: &PrimitiveArray) -> Utf8ViewArray { let (_, from_scale) = if let ArrowDataType::Decimal(p, s) = from.data_type().to_logical_type() { (*p, *s) } else { @@ -151,14 +151,14 @@ pub(super) fn decimal_to_binview(from: &PrimitiveArray) -> BinaryViewArray for &x in from.values().iter() { let buf = crate::legacy::compute::decimal::format_decimal(x, from_scale, false); - mutable.push_value_ignore_validity(buf.as_str().as_bytes()) + mutable.push_value_ignore_validity(buf.as_str()) } mutable.freeze().with_validity(from.validity().cloned()) } #[cfg(feature = "dtype-decimal")] -pub(super) fn decimal_to_binview_dyn(from: &dyn Array) -> BinaryViewArray { +pub(super) fn decimal_to_utf8view_dyn(from: &dyn Array) -> Utf8ViewArray { let from = from.as_any().downcast_ref().unwrap(); - decimal_to_binview(from) + decimal_to_utf8view(from) } diff --git a/crates/polars-arrow/src/compute/cast/mod.rs b/crates/polars-arrow/src/compute/cast/mod.rs index 988b783bd59f..2c822b9c0897 100644 --- a/crates/polars-arrow/src/compute/cast/mod.rs +++ b/crates/polars-arrow/src/compute/cast/mod.rs @@ -452,6 +452,8 @@ pub fn cast( Utf8 => Ok( utf8_to_utf8view(array.as_any().downcast_ref::>().unwrap()).boxed(), ), + #[cfg(feature = "dtype-decimal")] + Decimal(_, _) => Ok(decimal_to_utf8view_dyn(array).boxed()), _ => from_to_binview(array, from_type, to_type) .map(|arr| unsafe { arr.to_utf8view_unchecked() }.boxed()), }, @@ -778,8 +780,6 @@ fn from_to_binview( Binary => binary_to_binview::(array.as_any().downcast_ref().unwrap()), FixedSizeBinary(_) => fixed_size_binary_to_binview(array.as_any().downcast_ref().unwrap()), LargeBinary => binary_to_binview::(array.as_any().downcast_ref().unwrap()), - #[cfg(feature = "dtype-decimal")] - Decimal(_, _) => decimal_to_binview_dyn(array), _ => polars_bail!(InvalidOperation: "casting from {from_type:?} to {to_type:?} not supported", ),