Commit f866549
[SPARK-45816][SQL] Return
### What changes were proposed in this pull request?
Spark cast works in two modes: ansi and non-ansi. When overflowing during casting, the common behavior under non-ansi mode is to return null. However, casting from Timestamp to Int/Short/Byte returns a wrapping value now. The behavior to silently overflow doesn't make sense. This patch changes it to the common behavior, i.e., returning null.
### Why are the changes needed?
Returning a wrapping value, e.g., negative one, during casting Timestamp to Int/Short/Byte could implicitly cause misinterpret casted result without caution. We also should follow the common behavior of overflowing handling.
### Does this PR introduce _any_ user-facing change?
Yes. Overflowing during casting from Timestamp to Int/Short/Byte under non-ansi mode, returns null instead of wrapping value.
### How was this patch tested?
Will add test or update test if any existing ones fail
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #43694 from viirya/fix_cast_integers.
Authored-by: Liang-Chi Hsieh <[email protected]>
Signed-off-by: Jiaan Geng <[email protected]>NULL when overflowing during casting from timestamp to integers1 parent 1d8df4f commit f866549
File tree
3 files changed
+33
-25
lines changed- docs
- sql/catalyst/src
- main/scala/org/apache/spark/sql/catalyst/expressions
- test/scala/org/apache/spark/sql/catalyst/expressions
3 files changed
+33
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
Lines changed: 29 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
347 | 348 | | |
348 | 349 | | |
349 | 350 | | |
| |||
777 | 778 | | |
778 | 779 | | |
779 | 780 | | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
780 | 789 | | |
781 | 790 | | |
782 | 791 | | |
| |||
788 | 797 | | |
789 | 798 | | |
790 | 799 | | |
791 | | - | |
| 800 | + | |
792 | 801 | | |
793 | 802 | | |
794 | 803 | | |
795 | 804 | | |
796 | 805 | | |
797 | | - | |
| 806 | + | |
798 | 807 | | |
799 | 808 | | |
800 | | - | |
801 | | - | |
802 | 809 | | |
803 | 810 | | |
804 | 811 | | |
| |||
826 | 833 | | |
827 | 834 | | |
828 | 835 | | |
829 | | - | |
| 836 | + | |
830 | 837 | | |
831 | 838 | | |
832 | 839 | | |
833 | 840 | | |
834 | 841 | | |
835 | | - | |
| 842 | + | |
836 | 843 | | |
837 | 844 | | |
838 | | - | |
839 | | - | |
840 | 845 | | |
841 | 846 | | |
842 | 847 | | |
| |||
875 | 880 | | |
876 | 881 | | |
877 | 882 | | |
878 | | - | |
| 883 | + | |
879 | 884 | | |
880 | 885 | | |
881 | 886 | | |
882 | 887 | | |
883 | 888 | | |
884 | | - | |
| 889 | + | |
885 | 890 | | |
886 | 891 | | |
887 | | - | |
888 | | - | |
889 | 892 | | |
890 | 893 | | |
891 | 894 | | |
| |||
1661 | 1664 | | |
1662 | 1665 | | |
1663 | 1666 | | |
1664 | | - | |
1665 | | - | |
1666 | | - | |
1667 | | - | |
1668 | | - | |
1669 | | - | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
1670 | 1680 | | |
1671 | 1681 | | |
1672 | 1682 | | |
1673 | 1683 | | |
1674 | | - | |
| 1684 | + | |
1675 | 1685 | | |
1676 | 1686 | | |
1677 | | - | |
1678 | | - | |
1679 | | - | |
1680 | 1687 | | |
1681 | 1688 | | |
1682 | 1689 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
514 | 514 | | |
515 | 515 | | |
516 | 516 | | |
517 | | - | |
518 | | - | |
519 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| |||
0 commit comments