Conversation
arrow/src/compute/kernels/filter.rs
Outdated
There was a problem hiding this comment.
Unfortunately rust doesn't support macros in branch position, and so this was the best I could come up with - rust-lang/rfcs#2654
f161208 to
0fdbfff
Compare
| >($values); | ||
| $e | ||
| } | ||
| $crate::datatypes::DataType::Float16 => { |
There was a problem hiding this comment.
This was actually missing before
| /// # use arrow::array::as_string_array; | ||
| /// | ||
| /// fn print_primitive(array: &dyn Array) { | ||
| /// downcast_primitive_array!( |
There was a problem hiding this 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 ❤️
| /// println!("{:?}", v); | ||
| /// } | ||
| /// } | ||
| /// t => println!("Unsupported datatype {}", t) |
There was a problem hiding this 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
There was a problem hiding this comment.
Done, and threw in a bit of TypedDictionaryArray spice as well 😆
| // actually filter | ||
| _ => match values.data_type() { | ||
| _ => downcast_primitive_array! { | ||
| values => Ok(Arc::new(filter_primitive(values, predicate))), |
|
Benchmark runs are scheduled for baseline = 2d3a350 and contender = 5a49cfe. 5a49cfe is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Which issue does this PR close?
Closes #2635
Rationale for this change
I find myself frequently writing the same code, we can instead generate this with macros. This will also benefit downstreams and acts to reduce the current situation where we have ergonomic but limited dyn-dispatch, or significantly more verbose manual-dispatch but with full flexibility.
What changes are included in this PR?
Adds two macros
downcast_primitiveanddowncast_dict.Are there any user-facing changes?