Jefffrey commented on code in PR #10831:
URL: https://github.com/apache/arrow-rs/pull/10831#discussion_r3860927108
##########
parquet/src/arrow/array_reader/byte_array_dictionary.rs:
##########
@@ -119,11 +123,50 @@ pub fn make_byte_array_dictionary_reader(
}
}
+/// Convert a dictionary-typed array with string or binary typed values
+/// to one with string or binary view typed values.
+fn convert_values_to_view(array: ArrayRef, to_type: &ArrowType) ->
Result<ArrayRef> {
+ let ArrowType::Dictionary(_, to_value_type) = to_type else {
+ return Err(general_err!(
+ "Cannot convert {} dictionary values to non-dictionary type {}",
+ array.data_type(),
+ to_type
+ ));
+ };
+
+ let data = array.to_data();
+ let values = make_array(data.child_data()[0].clone());
+
+ let new_values: ArrayRef = match to_value_type.as_ref() {
+ ArrowType::Utf8View =>
Arc::new(StringViewArray::from(values.as_string::<i32>())),
+ ArrowType::BinaryView =>
Arc::new(BinaryViewArray::from(values.as_binary::<i32>())),
+ other => {
+ return Err(general_err!(
+ "Cannot convert dictionary values to {}",
+ other
+ ));
+ }
+ };
+
+ let new_data = unsafe {
+ // safety: The original ArrayData is valid, and we only replace the
child dictionary
+ // values with a correctly typed array, so skip ArrayDataBuilder
validation.
+ data.into_builder()
+ .data_type(to_type.clone())
+ .child_data(vec![new_values.to_data()])
+ .build_unchecked()
+ };
+
+ Ok(make_array(new_data))
Review Comment:
```suggestion
Ok(array.with_values(new_values))
```
##########
parquet/src/arrow/array_reader/byte_array_dictionary.rs:
##########
@@ -119,11 +123,50 @@ pub fn make_byte_array_dictionary_reader(
}
}
+/// Convert a dictionary-typed array with string or binary typed values
+/// to one with string or binary view typed values.
+fn convert_values_to_view(array: ArrayRef, to_type: &ArrowType) ->
Result<ArrayRef> {
+ let ArrowType::Dictionary(_, to_value_type) = to_type else {
+ return Err(general_err!(
+ "Cannot convert {} dictionary values to non-dictionary type {}",
+ array.data_type(),
+ to_type
+ ));
+ };
+
+ let data = array.to_data();
+ let values = make_array(data.child_data()[0].clone());
Review Comment:
```suggestion
let array = array.as_any_dictionary();
let values = array.values();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]