You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Rounding functions don't work well with values > INT_MAX #1036
We currently support double, but not long, and anything larger than a double gets truncated without an error/warning.
Option a) Limit the values to the size of a double or error/warn about loss of precision (not recommended).
Option b) Submit a ticket to OpenSearch to error/warn or support long numbers.
Option c) For numbers not supported by double, we can support larger numbers (long?) in-memory.
When converting to support long data type, there are issues. The IEEE 754 which is the floating point format of listed in the OpenSearch documentation for the double type has precision issues within the scope of this ticket. IEEE 754 has 52 bits for the fraction (for double type), if the input takes up more than that space, such as with 282474973688888.022, the decimal places may be sacrificed.
MySQL Issue:
MySQL also has a similar issue, albeit with a larger number. Both of the below queries should end in a 9, however the 2nd one ends in an 8.
mysql> select ceil(219988888888888888888888888888888888888888888888888888888888888888888888.9);
+----------------------------------------------------------------------------------+
| ceil(219988888888888888888888888888888888888888888888888888888888888888888888.9) |
+----------------------------------------------------------------------------------+
| 219988888888888888888888888888888888888888888888888888888888888888888889 |
+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select ceil(3219988888888888888888888888888888888888888888888888888888888888888888888.9);
+-----------------------------------------------------------------------------------+
| ceil(3219988888888888888888888888888888888888888888888888888888888888888888888.9) |
+-----------------------------------------------------------------------------------+
| 3219988888888888888888888888888888888888888888888888888888888888888888888 |
+-----------------------------------------------------------------------------------+
1 row in set (0.01 sec)
OpenSearchSQL Fix Issue:
Issue observed after fix for OpenSearchSQL ceil function. Both queries should go up to the next whole number, however because of floating point precision issues we lose some decimals in same situations. Issue in the positive domain for ceil/ceiling functions and negative domain for floor function.
This issue exists in OpenSearch, we can see when the number 282474973688888.022 is stored it is value 2.82474973688888E14 losing the decimal places. Example below. If there are no decimal places stored, we can't know if the ceil function should change the value in the return.
Allowing for return values larger than INT_MAX can be implemented to work as well as OpenSearch does for handling doubles. Unless a user is using OpenSearchSQL as a ceil/floor calculator, most of the values will be stored at some point in OpenSearch, we will lose.
I propose the fix for this issue is to have a return type of long from the ceil/ceiling/floor functions in java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java. This will support better support for large numbers, but may produce incorrect data if OpenSearch loses the decimal places from the input double.
Activity
MitchellGale commentedon Nov 17, 2022
Seems like MySQL has no limit on length.
Should we use
Long Doubletype and limit the length the length for opensearch?acarbonetto commentedon Nov 22, 2022
We currently support
double, but notlong, and anything larger than adoublegets truncated without an error/warning.Option a) Limit the values to the size of a
doubleor error/warn about loss of precision (not recommended).Option b) Submit a ticket to OpenSearch to error/warn or support
longnumbers.Option c) For numbers not supported by
double, we can support larger numbers (long?) in-memory.Regardless, we should fail with an error for any number larger than what is supported by OpenSearch (https://opensearch.org/docs/2.0/opensearch/supported-field-types/numeric).
MitchellGale commentedon Dec 2, 2022
When converting to support
longdata type, there are issues. The IEEE 754 which is the floating point format of listed in the OpenSearch documentation for the double type has precision issues within the scope of this ticket. IEEE 754 has 52 bits for the fraction (for double type), if the input takes up more than that space, such as with282474973688888.022, the decimal places may be sacrificed.MySQL Issue:
MySQL also has a similar issue, albeit with a larger number. Both of the below queries should end in a 9, however the 2nd one ends in an 8.
OpenSearchSQL Fix Issue:
Issue observed after fix for OpenSearchSQL
ceilfunction. Both queries should go up to the next whole number, however because of floating point precision issues we lose some decimals in same situations. Issue in the positive domain forceil/ceilingfunctions and negative domain forfloorfunction.OpenSearch Issue:
This issue exists in OpenSearch, we can see when the number
282474973688888.022is stored it is value2.82474973688888E14losing the decimal places. Example below. If there are no decimal places stored, we can't know if the ceil function should change the value in the return.Summary:
Allowing for return values larger than INT_MAX can be implemented to work as well as OpenSearch does for handling doubles. Unless a user is using OpenSearchSQL as a ceil/floor calculator, most of the values will be stored at some point in OpenSearch, we will lose.
I propose the fix for this issue is to have a return type of
longfrom the ceil/ceiling/floor functions injava/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java. This will support better support for large numbers, but may produce incorrect data if OpenSearch loses the decimal places from the input double.@kylepbit @acarbonetto @Yury-Fridlyand @dai-chen @penghuo
acarbonetto commentedon Jan 10, 2023
This issue can be closed
Yury-Fridlyand commentedon Jan 10, 2023
Closed by #1205 and #1255.