abreis edited a comment on pull request #9454:
URL: https://github.com/apache/arrow/pull/9454#issuecomment-777809399


   IMO, that would be the superior approach (though it's a much larger rewrite).
   
   I tried to mock what it could look like for the numeric kernels:
   ```rust
   // Datum with concrete types for the arithmetic module
   enum DatumNumeric<'a, T>
   where
       T: ArrowNumericType,
   {
       Array(&'a PrimitiveArray<T>),
       Scalar(T::Native),
   }
   
   // lets the user pass arrays without interacting with Datum
   impl<'a, T> From<&'a PrimitiveArray<T>> for DatumNumeric<'a, T>
   where
       T: ArrowNumericType,
   {
       fn from(array: &'a PrimitiveArray<T>) -> Self {
           DatumNumeric::Array(array)
       }
   }
   
   // can match and run specialized code for array/array, array/scalar, etcetera
   fn datum_math_divide<'a, T, DN>(left: DN, right: DN) -> 
Result<PrimitiveArray<T>>
   where
       T: ArrowNumericType,
       T::Native: Div<Output = T::Native> + Zero,
       DN: Into<DatumNumeric<'a, T>>,
   {
       use DatumNumeric::*;
       match (left.into(), right.into()) {
           (Array(left), Array(right)) => todo!("array/array"),
           (Array(array), Scalar(divisor)) => todo!("array/scalar"),
           _ => todo!(),
       }
   }
   
   fn test_datum_divide() {
       let a = Int32Array::from(vec![15, 15, 8, 1, 9]);
       let b = Int32Array::from(vec![5, 6, 8, 9, 1]);
       let c = datum_math_divide(&a, &b).unwrap(); // Works, same interface as 
before
   }
   ```
   
   However, Rust doesn't like the impl From for scalars (I tried ` impl<'a, T> 
From<T::Native> for DatumNumeric<'a, T> where T: ArrowNumericType`). Perhaps 
there's a better way to accomplish this.
   
   


----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to