mbutrovich commented on issue #12426: URL: https://github.com/apache/arrow-rs/issues/12426#issuecomment-7115524882
Some context for deciding this. The truncation dates from #4465, which added the `Datum` kernels, and the [`div` rustdoc](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/arrow-arith/src/numeric.rs#L57-L61) doesn't say how the quotient is rounded. The work in #11421 kept it as it was. Arrow C++ has two decimal divides that disagree: - The compute kernel `divide` [divides with `BasicDecimal128::operator/`](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/cpp/src/arrow/compute/kernels/base_arithmetic_internal.h#L388-L396), and that operator's division ["rounds to zero"](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/cpp/src/arrow/util/basic_decimal.h#L596-L601), as arrow-rs does. Its result scale is [`max(4, s1 + p2 - s2 + 1)`](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/docs/source/cpp/compute.rst#L560-L561), not `s1 + 4`. - Gandiva's `Divide` [rounds half away from zero](https://github.com/apache/arrow/blob/373d64c02cb23663b63c5853099fca43a46c39fc/cpp/src/gandiva/precompiled/decimal_ops.cc#L375-L378) on its 128-bit path. Within arrow-rs, a decimal cast that lowers the scale [rounds half away from zero](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/arrow-cast/src/cast/decimal.rs#L260-L265). The `decimal_op` comment cites PostgreSQL for the `s1 + 4` scale, but PostgreSQL [chooses the scale per value](https://github.com/postgres/postgres/blob/884aca9b96989b9bc1b65d42e731e90f098ee2ee/src/backend/utils/adt/numeric.c#L9748-L9754) to give at least 16 significant digits. Rounding would change the last digit of many quotients for existing callers, such as DataFusion's decimal `/`, without changing any signature. Should a change like that wait for a major release under `api-change`, as [CONTRIBUTING.md](https://github.com/apache/arrow-rs/blob/6a3f719f1de43137f0ecc2e7de12d4a7a0b13bd5/CONTRIBUTING.md?plain=1#L216-L221) requires for API breaks? -- 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]
