Commit 0472626
committed
Fix DECIMAL parameter cast size for exponent-notation and negative values
DecimalParameter.calculate_decimal_cast_string inferred DECIMAL(precision,
scale) by string-splitting str(value) on ".", which miscounts two forms
that str(Decimal) legitimately produces:
- exponent notation (Decimal("1500").normalize() -> "1.5E+3"): the "E+3"
was counted as fractional digits, giving DECIMAL(5,4) for 1500, which
overflows (an error in ANSI mode, NULL in legacy mode).
- a leading minus sign: counted as an extra integer digit, so a negative
38-digit value produced DECIMAL(39,0), exceeding Databricks' max DECIMAL
precision of 38 and failing the cast.
Derive precision/scale from Decimal.as_tuple() (digits + exponent), ignoring
sign and display format. Existing cast-string tests are unchanged; added
regression cases for exponent notation and negative values.
Signed-off-by: Madan Kumar <winklemad@outlook.com>1 parent 70427d7 commit 0472626
2 files changed
Lines changed: 18 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
663 | 662 | | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
669 | 666 | | |
670 | | - | |
| 667 | + | |
671 | 668 | | |
672 | 669 | | |
673 | 670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
| |||
0 commit comments