Joe McDonnell created IMPALA-15719:
--------------------------------------
Summary: trunc produces incorrect value for large negative scales
Key: IMPALA-15719
URL: https://issues.apache.org/jira/browse/IMPALA-15719
Project: IMPALA
Issue Type: Bug
Components: Backend
Affects Versions: Impala 5.0.0
Reporter: Joe McDonnell
#
# TRUNC produces the wrong result with large negative values for the scale:
{noformat}
# This correctly returns 0
Query: select trunc(1234, -9)
+-----------------+
| trunc(1234, -9) |
+-----------------+
| 0 |
+-----------------+
# BUG: This should return 0
Query: select trunc(1234, -10)
+------------------+
| trunc(1234, -10) |
+------------------+
| 1234 |
+------------------+
{noformat}
This is an issue in DecimalOperators::RoundDecimalNegativeScale(). If the
rounding position is further left than the storage type can represent as a
power of ten (10^10 for 4-byte, 10^19 for 8-byte, 10^39 for 16-byte decimals),
RoundDecimalNegativeScale overflowed the multiplier and returned the input
unchanged, e.g. trunc(1234.567, -10) returned 1234 instead of 0.
It should return 0 directly when rounding_scale > output_precision.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)