Ganesha S created SPARK-62420:
---------------------------------
Summary: JSON_TABLE and JSON_QUERY fail with NumberFormatException
on a number with a very large exponent
Key: SPARK-62420
URL: https://issues.apache.org/jira/browse/SPARK-62420
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 4.3.0, 4.4.0
Reporter: Ganesha S
JSON_TABLE and JSON_QUERY fail with a raw java.lang.NumberFormatException when
the JSON contains a number whose exponent is too large for a BigDecimal, such
as 1e9999999999. This is valid JSON, and the ON ERROR clause does not apply:
the query fails even with the default NULL ON ERROR.
{code:sql}
SELECT * FROM JSON_TABLE('[1e9999999999]', '$[*]' COLUMNS (v STRING PATH '$'));
SELECT JSON_QUERY('\{"a":1e9999999999}', '$.a');
{code}
Both fail with:
{noformat}
java.lang.NumberFormatException: Value "1e9999999999" can not be deserialized
as `java.math.BigDecimal`, reason: Exponent overflow.
{noformat}
JSON_VALUE and JSON_EXISTS are not affected: JSON_VALUE('\{"a":1e9999999999}',
'$.a') returns 1e9999999999.
Both functions convert numbers to BigDecimal to keep their exact text, and only
Jackson's parse errors are handled, not NumberFormatException.
Proposal: when a number cannot be converted to BigDecimal, keep its text as
written, as JSON_VALUE does. A STRING column and JSON_QUERY then return
1e9999999999, and a numeric column follows the normal cast rules. Other numbers
must keep their current text, so decimal values stay exact.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]