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
28 changes: 12 additions & 16 deletions arrow-cast/src/cast/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,18 @@ where
D: DecimalType + ArrowPrimitiveType,
{
let dict = pack_numeric_to_dictionary::<K, D>(array, dict_value_type, cast_options)?;
let dict = dict
.as_dictionary::<K>()
.downcast_dict::<PrimitiveArray<D>>()
.ok_or_else(|| {
ArrowError::ComputeError(format!(
"Internal Error: Cannot cast dict to {}Array",
D::PREFIX
))
})?;
let value = dict.values().clone();
// Set correct precision/scale
let value = value.with_precision_and_scale(precision, scale)?;
Ok(Arc::new(DictionaryArray::<K>::try_new(
dict.keys().clone(),
Arc::new(value),
)?))
let dict = dict.as_dictionary::<K>();
let typed = dict.downcast_dict::<PrimitiveArray<D>>().ok_or_else(|| {
ArrowError::ComputeError(format!(
"Internal Error: Cannot cast dict to {}Array",
D::PREFIX
))
})?;
let value = typed
.values()
.clone()
.with_precision_and_scale(precision, scale)?;
Ok(Arc::new(dict.with_values(Arc::new(value))))
}

pub(crate) fn string_view_to_dictionary<K, O: OffsetSizeTrait>(
Expand Down
3 changes: 1 addition & 2 deletions arrow-string/src/substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ pub fn substring(
stringify!($gt), array.data_type())
});
let values = substring(dict.values(), start, length)?;
let result = DictionaryArray::try_new(dict.keys().clone(), values)?;
Ok(Arc::new(result))
Ok(Arc::new(dict.with_values(values)))
},
)*
t => panic!("Unsupported dictionary key type: {}", t)
Expand Down
Loading