Search before asking
Version
Apache Doris 4.0.5
This issue does not exist in Doris 2.1 according to my test.
What's Wrong?
In Doris 4.0.5, casting a VARCHAR value in scientific notation to DECIMAL returns an incorrect result.
For example:
`CAST('1.4E+4' AS DECIMAL(38, 15))`
Actual result:
Expected result:
The same issue also happens for other scientific notation strings, such as:
However, casting the same string to DOUBLE works correctly:
`CAST('1.4E+4' AS DOUBLE)`
-- 14000
Also, casting via DOUBLE works correctly:
`CAST(CAST('1.4E+4' AS DOUBLE) AS DECIMAL(38, 15))`
-- 14000.000000000000000
What You Expected?
CAST(VARCHAR scientific notation AS DECIMAL) should correctly parse scientific notation.
Expected:
CAST('1.4E+4' AS DECIMAL(38, 15))
-- 14000.000000000000000
CAST('2.128E+4' AS DECIMAL(38, 15))
-- 21280.000000000000000
CAST('-1.4E+4' AS DECIMAL(38, 15))
-- -14000.000000000000000
How to Reproduce?
CREATE TABLE t (
s VARCHAR(64)
)
PROPERTIES (
"replication_num" = "1"
);
INSERT INTO t VALUES
('1.4E+4'),
('2.128E+4'),
('1.4e+4'),
('-1.4E+4'),
('0E-9'),
('1.60'),
('14000');
SELECT
s AS raw_str,
CAST(s AS DECIMAL(38, 15)) AS col_cast_decimal,
CAST(s AS DOUBLE) AS col_cast_double,
CAST(CAST(s AS DOUBLE) AS DECIMAL(38, 15)) AS via_double
FROM t
ORDER BY s;
Actual result in Doris 4.0.5:
+----------+------------------------+-----------------+------------------------+
| raw_str | col_cast_decimal | col_cast_double | via_double |
+----------+------------------------+-----------------+------------------------+
| -1.4E+4 | -14.000000000000000 | -14000 | -14000.000000000000000 |
| 0E-9 | 0.000000000000000 | 0 | 0.000000000000000 |
| 1.4E+4 | 14.000000000000000 | 14000 | 14000.000000000000000 |
| 1.4e+4 | 14.000000000000000 | 14000 | 14000.000000000000000 |
| 1.60 | 1.600000000000000 | 1.6 | 1.600000000000000 |
| 14000 | 14000.000000000000000 | 14000 | 14000.000000000000000 |
| 2.128E+4 | 2128.000000000000000 | 21280 | 21280.000000000000000 |
+----------+------------------------+-----------------+------------------------+
Anything Else?
This seems to be a regression because the same case works correctly in Doris 2.1.
The issue seems to be specific to the direct cast path:
VARCHAR -> DECIMAL
because these paths work correctly:
VARCHAR -> DOUBLE
VARCHAR -> DOUBLE -> DECIMAL
This is risky for financial or balance-related data, because scientific notation strings may be silently converted to incorrect DECIMAL values instead of throwing an error.
Are you willing to submit PR?
Code of Conduct
Search before asking
Version
Apache Doris 4.0.5
This issue does not exist in Doris 2.1 according to my test.
What's Wrong?
In Doris 4.0.5, casting a VARCHAR value in scientific notation to DECIMAL returns an incorrect result.
For example:
Actual result:
Expected result:
The same issue also happens for other scientific notation strings, such as:
However, casting the same string to DOUBLE works correctly:
Also, casting via DOUBLE works correctly:
What You Expected?
CAST(VARCHAR scientific notation AS DECIMAL)should correctly parse scientific notation.Expected:
CAST('1.4E+4' AS DECIMAL(38, 15))-- 14000.000000000000000
CAST('2.128E+4' AS DECIMAL(38, 15))-- 21280.000000000000000
CAST('-1.4E+4' AS DECIMAL(38, 15))-- -14000.000000000000000
How to Reproduce?
Actual result in Doris 4.0.5:
Anything Else?
This seems to be a regression because the same case works correctly in Doris 2.1.
The issue seems to be specific to the direct cast path:
VARCHAR -> DECIMAL
because these paths work correctly:
VARCHAR -> DOUBLE
VARCHAR -> DOUBLE -> DECIMAL
This is risky for financial or balance-related data, because scientific notation strings may be silently converted to incorrect DECIMAL values instead of throwing an error.
Are you willing to submit PR?
Code of Conduct