tustvold opened a new issue, #2842: URL: https://github.com/apache/arrow-rs/issues/2842
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.** <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] (This section helps Arrow developers understand the context and *why* for this feature, in addition to the *what*) --> As expanded upon in https://github.com/apache/arrow-rs/issues/2837 currently the encoding of scalars in dyn kernels is inconsistent. The arithmetic kernels must be explicitly type hinted with the `ArrowPrimitiveType`, whilst the comparison kernels coerce the scalar type to the desired type. Taking a step back, users just want to give a kernel an array and a scalar of the correct type and have it work, with all the dispatch logic handled for it. **Describe the solution you'd like** <!-- A clear and concise description of what you want to happen. --> I would like to suggest encoding scalars as `& dyn std::any::Any`, for example, ``` pub fn eq_scalar_dyn( left: &dyn Array, right: &dyn std::any::Any, ) -> Result<BooleanArray> { downcast_primitive_array! { left => match right.downcast_ref() { Some(r) => eq_scalar(left, *r), None => Err(ArrowError::ComputeError(format!("Failed to downcast scalar for {}", left.data_type()))) }, DataType::Boolean => match right.downcast_ref() { Some(r) => eq_bool_scalar(as_boolean_array(left), *r), None => Err(ArrowError::ComputeError(format!("Failed to downcast scalar for {}", left.data_type()))) } DataType::Utf8 => match right.downcast_ref() { Some(r) => eq_utf8_scalar(as_string_array(left), *r), None => Err(ArrowError::ComputeError(format!("Failed to downcast scalar for {}", left.data_type()))) } DataType::Dictionary(_, _) => downcast_dictionary_array! { left => { let dict_compare = eq_scalar_dyn(left.values().as_ref(), right)?; unpack_dict_comparison(left, dict_compare) } _ => unreachable!() } t => Err(ArrowError::ComputeError(format!("Unsupported datatype for eq_dyn_scalar_any {}", t))) } } ``` This has the following advantages: * The dyn kernels don't require any type hinting * The kernels don't perform any implicit type coercion The only major downside is that users will need to be careful to correctly hint scalar types, i.e. `&1_i64`. **Describe alternatives you've considered** <!-- A clear and concise description of any alternative solutions or features you've considered. --> We could not do this **Additional context** <!-- Add any other context or screenshots about the feature request here. --> -- 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]
