jorgecarleitao commented on a change in pull request #9014:
URL: https://github.com/apache/arrow/pull/9014#discussion_r548946031
##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -351,17 +351,13 @@ pub fn cast(array: &ArrayRef, to_type: &DataType) ->
Result<ArrayRef> {
Float32 => cast_bool_to_numeric::<Float32Type>(array),
Float64 => cast_bool_to_numeric::<Float64Type>(array),
Utf8 => {
- let from =
array.as_any().downcast_ref::<BooleanArray>().unwrap();
- let mut b = StringBuilder::new(array.len());
- for i in 0..array.len() {
- if array.is_null(i) {
- b.append(false)?;
- } else {
- b.append_value(if from.value(i) { "1" } else { "0" })?;
- }
- }
-
- Ok(Arc::new(b.finish()) as ArrayRef)
+ let array =
array.as_any().downcast_ref::<BooleanArray>().unwrap();
+ Ok(Arc::new(
+ array
+ .iter()
+ .map(|value| value.map(|value| if value { "1" } else {
"0" }))
Review comment:
Good question. I suspect the builder, because the iterator does the same
thing as before atm (i.e. same bound checks).
The builders IMO are inefficient atm. Since IMO they are less idiomatic, I
do not see any issue in replacing them whenever we can ^_^
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]