alamb commented on code in PR #2636:
URL: https://github.com/apache/arrow-rs/pull/2636#discussion_r961692236
##########
arrow/src/array/cast.rs:
##########
@@ -53,6 +260,90 @@ where
.expect("Unable to downcast to primitive array")
}
+/// Downcast an [`Array`] to a [`DictionaryArray`] based on its [`DataType`],
accepts
+/// a number of subsequent patterns to match the data type
+///
+/// ```
+/// # use arrow::downcast_dict_array;
+/// # use arrow::array::Array;
+/// # use arrow::datatypes::DataType;
+/// # use arrow::array::as_string_array;
+///
+/// fn print_keys(array: &dyn Array) {
+/// downcast_dict_array!(
+/// array => {
+/// for v in array.keys() {
+/// println!("{:?}", v);
+/// }
+/// }
+/// t => println!("Unsupported datatype {}", t)
Review Comment:
I think it would be good to extend this example to show the String array as
well -- not only to document how to support other types, but also because the
StringArray is so common
##########
arrow/src/array/cast.rs:
##########
@@ -20,6 +20,213 @@
use crate::array::*;
use crate::datatypes::*;
+/// Downcast an [`Array`] to a [`PrimitiveArray`] based on its [`DataType`],
accepts
+/// a number of subsequent patterns to match the data type
+///
+/// ```
+/// # use arrow::downcast_primitive_array;
+/// # use arrow::array::Array;
+/// # use arrow::datatypes::DataType;
+/// # use arrow::array::as_string_array;
+///
+/// fn print_primitive(array: &dyn Array) {
+/// downcast_primitive_array!(
Review Comment:
❤️ that certainly will make the macros in code such as
https://github.com/apache/arrow-datafusion/blob/master/datafusion/physical-expr/src/expressions/binary.rs
easier to deal with ❤️
##########
arrow/src/compute/kernels/filter.rs:
##########
@@ -358,92 +336,12 @@ fn filter_array(values: &dyn Array, predicate:
&FilterPredicate) -> Result<Array
IterationStrategy::None => Ok(new_empty_array(values.data_type())),
IterationStrategy::All => Ok(make_array(values.data().slice(0,
predicate.count))),
// actually filter
- _ => match values.data_type() {
+ _ => downcast_primitive_array! {
+ values => Ok(Arc::new(filter_primitive(values, predicate))),
Review Comment:
👨🍳 👌
Very nice
--
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]