Skip to content

Commit 1bc02ad

Browse files
committed
Manual disabled format B
1 parent 13b0251 commit 1bc02ad

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ private object DateTimeFormatterHelper {
280280
// 2.4, the SimpleDateFormat uses Monday as the first day of week.
281281
final val weekBasedLetters = Set('Y', 'W', 'w', 'u', 'e', 'c')
282282
final val unsupportedLetters = Set('A', 'n', 'N', 'p')
283+
final val unknownPatternLetters: Set[Char] = Set('B')
283284
// The quarter fields will also be parsed strangely, e.g. when the pattern contains `yMd` and can
284285
// be directly resolved then the `q` do check for whether the month is valid, but if the date
285286
// fields is incomplete, e.g. `yM`, the checking will be bypassed.
@@ -322,6 +323,13 @@ private object DateTimeFormatterHelper {
322323
(isParsing && unsupportedLettersForParsing.contains(c))) {
323324
throw new IllegalArgumentException(s"Illegal pattern character: $c")
324325
}
326+
// SPARK-36970: `select date_format('2018-11-17 13:33:33.333', 'B')` failed with Java 8,
327+
// but use Java 17 will return `in the afternoon` because 'B' is used to represent
328+
// `Pattern letters to output a day period` in Java 17 and manual disabled it here for
329+
// compatibility with Java 8 behavior.
330+
for (c <- patternPart if unknownPatternLetters.contains(c)) {
331+
throw new IllegalArgumentException(s"Unknown pattern letter: $c")
332+
}
325333
for (style <- unsupportedPatternLengths if patternPart.contains(style)) {
326334
throw new IllegalArgumentException(s"Too many pattern letters: ${style.head}")
327335
}

0 commit comments

Comments
 (0)