You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "ZhangHuiGui (via GitHub)" <gi...@apache.org> on 2024/04/22 15:11:55 UTC

[I] [C++][Compute] Inaccurate calculation results will be produced when the 'cases' arrays of 'case_when' have different Decimal types [arrow]

ZhangHuiGui opened a new issue, #41336:
URL: https://github.com/apache/arrow/issues/41336

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   It's an interesting problem we find recently in `case_when` kernel.
   
   For the call function:
   `CaseWhen({MakeStruct({cond1, cond2, cond3}), {arr1, arr2, arr3, arr4}})`
   will produce the `case_when` logic like below:
   ```shell
   cond1 --> arr1 decimal(9,7),
   cond2 --> arr2 decimal(6,2),
   cond3 --> arr3 decimal(3, 2),
   arr4 decimal(2,1)
   ```
   
   The `case_when` will use the `LastType` which is `decimal(2,1)` as it's output type.
   https://github.com/apache/arrow/blob/79799e59b1a0c7bde8b85ea955593b2d63d2a46c/cpp/src/arrow/compute/kernels/scalar_if_else.cc#L2683-L2685.
   
   That means for the arr1/arr2/arr3's output results, the precision will be set to `decimal(2,1)`, obviously it's inaccurate in fact especially when we the `case_when` as an expression combining with aggregate's `sum/avg...`.
   
   laotan332 [qinpengxiang@outlook.com](mailto:qinpengxiang@outlook.com)
   
   
   
   ### Component(s)
   
   C++


-- 
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: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org