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

[I] Why arrow decimal divide precision and scale is not correct? [arrow]

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

   ### Describe the usage question you have. Please include as many useful details as  possible.
   
   
   ```
   select 1.00/id from test;
   
   id is decimal(15,2) which is  16906.24
   1.00 is decimal(3,2)
   but the result is decimal(3, 0);
   ```
   
   looks like it's follow the rule that is
   rule1
   ```
   Result<TypeHolder> ResolveDecimalDivisionOutput(KernelContext*,
                                                   const std::vector<TypeHolder>& types) {
     return ResolveDecimalBinaryOperationOutput(
         types, [](int32_t p1, int32_t s1, int32_t p2, int32_t s2) {
           DCHECK_GE(s1, s2);
           const int32_t scale = s1 - s2;
           const int32_t precision = p1;
           return std::make_pair(precision, scale);
         });
   }
   ```
   but the document is show that
   rule 2:
   ```
   scale = max(4, s1 + p2 - s2 + 1)
   precision = p1 - s1 + s2 + scale
   ```
   How could i use the second rule?
   
   ### 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