xudong963 commented on issue #1576:
URL: 
https://github.com/apache/arrow-datafusion/issues/1576#issuecomment-1013681759


   I've found out why it failed.
   
   let's see query 8, there is `when ... then ... else ...`.
   ```sql
   select
       o_year,
       sum(case
               when nation = 'BRAZIL' then volume
               else 0
           end) / sum(volume) as mkt_share
   ...
   ```
   In datafusion, the following code to process `when ... then ... else ...`
   ```rust
   fn if_then_else(
       bools: &BooleanArray,
       true_values: ArrayRef,
       false_values: ArrayRef,
       data_type: &DataType,
   ) -> Result<ArrayRef> {
       match data_type {
           ...
           DataType::Float64 => if_then_else!(
               array::Float64Builder,
               array::Float64Array,
               bools,
               true_values,
               false_values
           ),
       }
   }
   ```
   In query8, 0 is `Int64`, then during casing  to `Float64`, it fails.
   ```rust
   macro_rules! if_then_else {
       ($BUILDER_TYPE:ty, $ARRAY_TYPE:ty, $BOOLS:expr, $TRUE:expr, $FALSE:expr) 
=> {{
           let true_values = $TRUE
               .as_ref()
               .as_any()
               .downcast_ref::<$ARRAY_TYPE>()
               .expect("true_values downcast failed");
   
           let false_values = $FALSE
               .as_ref()
               .as_any()
               .downcast_ref::<$ARRAY_TYPE>()
               .expect("false_values downcast failed");
   ```


-- 
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]


Reply via email to