-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major
-
None
-
Affects Version/s: 3.5.8, 4.2.0, 4.3.0, 4.1.3, 4.0.4, 4.4.0
-
Component/s: SQL
With `spark.sql.legacy.allowNegativeScaleOfDecimal=true`, `DecimalType` has no lower bound on a negative scale. Casting such a decimal to string under ANSI (`useDecimalPlainString`, `ToStringBase`) and `Dataset.show` (`ToPrettyString`) call `Decimal.toPlainString`, which builds the full plain string. For `1E+2147483647` it fails with `OutOfMemoryError: too large to fit in a String`:
lit("1e2147483647").cast(DecimalType(1, -2147483647)).cast("string") spark.range(1).select(lit(new java.math.BigDecimal("1e2147483647"))).show()
The inner cast succeeds because the precision and scale already match, so `Decimal.changePrecision` takes its fast path and the value reaches the string conversion.
SPARK-60119 bounds this only for the `NUMERIC_VALUE_OUT_OF_RANGE` error message (scientific notation below scale -1000). The threshold could move to a `Decimal`-level helper shared by these callers.
- links to