Skip to content

Commit c364ff3

Browse files
committed
with q/Q
1 parent b0413d3 commit c364ff3

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

docs/sql-ref-datetime-pattern.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ The count of pattern letters determines the format.
137137
During parsing, the whole section may be missing from the parsed string.
138138
An optional section is started by `[` and ended using `]` (or at the end of the pattern).
139139
140-
- Symbols of 'Y', 'W', 'w', 'E', 'u', 'F' can only be used for datetime formatting, e.g. `date_format`.
140+
- Symbols of 'Y', 'W', 'w', 'E', 'u', 'F', 'q' and 'Q' can only be used for datetime formatting, e.g. `date_format`. They are not allowed used for datetime parsing, e.g. `to_timestamp`.
141141
142142
More details for the text style:
143143

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,11 @@ private object DateTimeFormatterHelper {
228228
}
229229
final val unsupportedLetters = Set('A', 'c', 'e', 'n', 'N', 'p')
230230
// SPARK-31892: The week-based date fields are rarely used and really confusing for parsing values
231-
// to timestamp, especially when they are mixed with other non-week-based ones. we have tried our
232-
// best to restore the behavior change between 2.4 and 3.0 and failed, see
233-
// https://github.com/apache/spark/pull/28674
234-
final val unsupportedLettersForParsing = Set('Y', 'W', 'w', 'E', 'u', 'F')
231+
// to datetime, especially when they are mixed with other non-week-based ones
232+
// The quarter fields will also be parsed strangely, e.g. when the pattern contains `yMd` and can
233+
// be directly resolved then the `q` do check for whether the month is valid, but if the date
234+
// fields is incomplete, e.g. `yM`, the checking will be bypassed.
235+
final val unsupportedLettersForParsing = Set('Y', 'W', 'w', 'E', 'u', 'F', 'q', 'Q')
235236
final val unsupportedPatternLengths = {
236237
// SPARK-31771: Disable Narrow-form TextStyle to avoid silent data change, as it is Full-form in
237238
// 2.4

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
11691169
MillisToTimestamp(Literal(-92233720368547758L)), "long overflow")
11701170
}
11711171

1172-
test("Disable week-based date filed for parsing") {
1172+
test("Disable week-based date fields and quarter fields for parsing") {
11731173

11741174
def checkSparkUpgrade(c: Char): Unit = {
11751175
checkExceptionInExpression[SparkUpgradeException](
@@ -1182,7 +1182,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
11821182
UnixTimestamp(Literal("1"), Literal(c.toString)), "3.0")
11831183
}
11841184

1185-
Seq('Y', 'W', 'w', 'E', 'u', 'F').foreach { l =>
1185+
Seq('Y', 'W', 'w', 'E', 'u', 'F', 'q', 'Q').foreach { l =>
11861186
checkSparkUpgrade(l)
11871187
}
11881188
}

0 commit comments

Comments
 (0)