Yang Jie created SPARK-57955:
--------------------------------

             Summary: Raise a proper error for out-of-Int-range data type 
parameters instead of NumberFormatException
                 Key: SPARK-57955
                 URL: https://issues.apache.org/jira/browse/SPARK-57955
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 5.0.0
            Reporter: Yang Jie


The data type parser converts integer type parameters (DECIMAL precision/scale, 
CHAR/VARCHAR length, TIME precision, GEOMETRY/GEOGRAPHY SRID) to Int with a raw 
`.toInt`. The grammar backs these with `INTEGER_VALUE : DIGIT+` (an unbounded 
digit run), so a value outside the 32-bit integer range overflows and throws a 
raw `java.lang.NumberFormatException` with no Spark error class.

For example:

{code:sql}
SELECT CAST(1 AS DECIMAL(9999999999, 2));
{code}

surfaces `java.lang.NumberFormatException: For input string: "9999999999"` 
instead of a proper Spark error, on the following reachable paths: SQL / CAST, 
`StructType.fromDDL`, `DataType.fromJson`, direct 
`DataTypeParser.parseDataType`, and the legacy Parquet schema-string parser.

The `TIMESTAMP(p)` branch of the same parser already guards this and raises 
`INVALID_TIMESTAMP_PRECISION`; the other type parameters were simply not 
brought in line.

This ticket guards the conversion on all three parse paths (ANTLR parser, JSON, 
and the legacy case-class string parser) so an out-of-range parameter raises a 
proper Spark error: DECIMAL precision reuses 
`DECIMAL_PRECISION_EXCEEDS_MAX_PRECISION`, TIME precision reuses 
`UNSUPPORTED_TIME_PRECISION`, GEOMETRY/GEOGRAPHY SRID reuses 
`ST_INVALID_SRID_VALUE`, and CHAR/VARCHAR length + DECIMAL scale use a new 
`DATATYPE_PARAMETER_VALUE_OUT_OF_RANGE` error condition.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to