Commit 2a059e6
### What changes were proposed in this pull request?
In the PR, I propose to add legacy date/timestamp formatters based on `SimpleDateFormat` and `FastDateFormat`:
- `LegacyFastTimestampFormatter` - uses `FastDateFormat` and supports parsing/formatting in microsecond precision. The code was borrowed from Spark 2.4, see #26507 & #26582
- `LegacySimpleTimestampFormatter` uses `SimpleDateFormat`, and support the `lenient` mode. When the `lenient` parameter is set to `false`, the parser become much stronger in checking its input.
### Why are the changes needed?
Spark 2.4.x uses the following parsers for parsing/formatting date/timestamp strings:
- `DateTimeFormat` in CSV/JSON datasource
- `SimpleDateFormat` - is used in JDBC datasource, in partitions parsing.
- `SimpleDateFormat` in strong mode (`lenient = false`), see https://github.com/apache/spark/blob/branch-2.4/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala#L124. It is used by the `date_format`, `from_unixtime`, `unix_timestamp` and `to_unix_timestamp` functions.
The PR aims to make Spark 3.0 compatible with Spark 2.4.x in all those cases when `spark.sql.legacy.timeParser.enabled` is set to `true`.
### Does this PR introduce any user-facing change?
This shouldn't change behavior with default settings. If `spark.sql.legacy.timeParser.enabled` is set to `true`, users should observe behavior of Spark 2.4.
### How was this patch tested?
- Modified tests in `DateExpressionsSuite` to check the legacy parser - `SimpleDateFormat`.
- Added `CSVLegacyTimeParserSuite` and `JsonLegacyTimeParserSuite` to run `CSVSuite` and `JsonSuite` with the legacy parser - `FastDateFormat`.
Closes #27524 from MaxGekk/timestamp-formatter-legacy-fallback.
Authored-by: Maxim Gekk <max.gekk@gmail.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit c198620)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 7c5d7d7 commit 2a059e6
File tree
19 files changed
+654
-419
lines changed- sql
- catalyst/src
- main/scala/org/apache/spark/sql
- catalyst
- csv
- expressions
- json
- util
- types
- test/scala/org/apache/spark/sql/catalyst/expressions
- core/src
- main/scala/org/apache/spark/sql
- test
- resources/test-data
- scala/org/apache/spark/sql
- execution/datasources
- csv
- json
19 files changed
+654
-419
lines changedLines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
93 | | - | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | 98 | | |
96 | 99 | | |
| |||
Lines changed: 32 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
622 | 623 | | |
623 | 624 | | |
624 | 625 | | |
625 | | - | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
626 | 629 | | |
627 | 630 | | |
628 | 631 | | |
629 | 632 | | |
630 | 633 | | |
631 | | - | |
| 634 | + | |
632 | 635 | | |
633 | 636 | | |
634 | 637 | | |
| |||
643 | 646 | | |
644 | 647 | | |
645 | 648 | | |
| 649 | + | |
646 | 650 | | |
647 | 651 | | |
648 | | - | |
649 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
650 | 657 | | |
651 | 658 | | |
652 | 659 | | |
| |||
688 | 695 | | |
689 | 696 | | |
690 | 697 | | |
691 | | - | |
| 698 | + | |
692 | 699 | | |
693 | 700 | | |
694 | 701 | | |
| |||
732 | 739 | | |
733 | 740 | | |
734 | 741 | | |
735 | | - | |
| 742 | + | |
736 | 743 | | |
737 | 744 | | |
738 | 745 | | |
| |||
758 | 765 | | |
759 | 766 | | |
760 | 767 | | |
761 | | - | |
| 768 | + | |
762 | 769 | | |
763 | 770 | | |
764 | 771 | | |
| |||
791 | 798 | | |
792 | 799 | | |
793 | 800 | | |
794 | | - | |
795 | | - | |
| 801 | + | |
| 802 | + | |
796 | 803 | | |
797 | 804 | | |
798 | 805 | | |
| |||
831 | 838 | | |
832 | 839 | | |
833 | 840 | | |
834 | | - | |
835 | 841 | | |
| 842 | + | |
836 | 843 | | |
837 | 844 | | |
838 | 845 | | |
839 | | - | |
840 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
841 | 851 | | |
842 | 852 | | |
843 | 853 | | |
| |||
908 | 918 | | |
909 | 919 | | |
910 | 920 | | |
911 | | - | |
| 921 | + | |
912 | 922 | | |
913 | 923 | | |
914 | 924 | | |
| |||
922 | 932 | | |
923 | 933 | | |
924 | 934 | | |
925 | | - | |
| 935 | + | |
926 | 936 | | |
927 | 937 | | |
928 | 938 | | |
| |||
948 | 958 | | |
949 | 959 | | |
950 | 960 | | |
951 | | - | |
952 | | - | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
953 | 964 | | |
954 | 965 | | |
955 | 966 | | |
| |||
980 | 991 | | |
981 | 992 | | |
982 | 993 | | |
983 | | - | |
984 | 994 | | |
| 995 | + | |
985 | 996 | | |
986 | 997 | | |
987 | 998 | | |
988 | | - | |
989 | | - | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
990 | 1002 | | |
991 | 1003 | | |
992 | 1004 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
87 | | - | |
| 89 | + | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| |||
0 commit comments