Skip to content

Commit

Permalink
chore: use Utf8View instead of BinaryView
Browse files Browse the repository at this point in the history
  • Loading branch information
flisky committed Jan 23, 2024
1 parent f9072df commit 264cf84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions crates/polars-arrow/src/compute/cast/decimal_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i128>) -> BinaryViewArray {
pub(super) fn decimal_to_utf8view(from: &PrimitiveArray<i128>) -> Utf8ViewArray {
let (_, from_scale) = if let ArrowDataType::Decimal(p, s) = from.data_type().to_logical_type() {
(*p, *s)
} else {
Expand All @@ -151,14 +151,14 @@ pub(super) fn decimal_to_binview(from: &PrimitiveArray<i128>) -> 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)
}
4 changes: 2 additions & 2 deletions crates/polars-arrow/src/compute/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ pub fn cast(
Utf8 => Ok(
utf8_to_utf8view(array.as_any().downcast_ref::<Utf8Array<i32>>().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()),
},
Expand Down Expand Up @@ -778,8 +780,6 @@ fn from_to_binview(
Binary => binary_to_binview::<i32>(array.as_any().downcast_ref().unwrap()),
FixedSizeBinary(_) => fixed_size_binary_to_binview(array.as_any().downcast_ref().unwrap()),
LargeBinary => binary_to_binview::<i64>(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",
),
Expand Down

0 comments on commit 264cf84

Please sign in to comment.