Migration guide: CAST(string AS BIGINT) precision fix¶
Config flag: snowpark.connect.cast.stringToIntegralHighPrecision (default: true from 1.46.0)
Who is affected¶
- Workloads casting very large string integers (approximately 9.2×10¹⁸) to
BIGINT/long. Such magnitudes are rare, and the change is silent (a wrong value becomes a correct value). - ANSI mode users (
spark.sql.ansi.enabled = true) casting a string just past the Long boundary: previously returned a wrong value, now raises.
What changes¶
Casting a string to LongType (BIGINT) near (±9,223,372,036,854,775,807) previously
rounded to the nearest power of two, producing wrong overflow decisions.
After this change, casting values near the boundary are exact. As a side effect, ANSI-mode
Long overflow now correctly raises NumberFormatException where it previously returned a
wrong value.
Smaller integral targets (INT, SHORT, BYTE) are unchanged.
Cast of a 19-digit string near Long.MAX | |
|---|---|
| Before | wrong value or wrong NULL |
| After (non-ANSI) | exact value, or NULL if genuinely out of range |
| After (ANSI) | exact value, or raises NumberFormatException on real overflow |
Example¶
How to migrate¶
- The new values are correct. Review any downstream logic that keyed on the old (wrong)
results — for example a
WHERE id IS NULLfilter used to catch overflow, or a join that silently dropped the miscast rows. - ANSI-mode jobs at the exact boundary should handle the new
NumberFormatException, or usetry_castto tolerate malformed input and getNULLinstead.