@@ -280,6 +280,7 @@ private object DateTimeFormatterHelper {
280
280
// 2.4, the SimpleDateFormat uses Monday as the first day of week.
281
281
final val weekBasedLetters = Set ('Y' , 'W' , 'w' , 'u' , 'e' , 'c' )
282
282
final val unsupportedLetters = Set ('A' , 'n' , 'N' , 'p' )
283
+ final val unknownPatternLetters : Set [Char ] = Set ('B' )
283
284
// The quarter fields will also be parsed strangely, e.g. when the pattern contains `yMd` and can
284
285
// be directly resolved then the `q` do check for whether the month is valid, but if the date
285
286
// fields is incomplete, e.g. `yM`, the checking will be bypassed.
@@ -322,6 +323,13 @@ private object DateTimeFormatterHelper {
322
323
(isParsing && unsupportedLettersForParsing.contains(c))) {
323
324
throw new IllegalArgumentException (s " Illegal pattern character: $c" )
324
325
}
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
+ }
325
333
for (style <- unsupportedPatternLengths if patternPart.contains(style)) {
326
334
throw new IllegalArgumentException (s " Too many pattern letters: ${style.head}" )
327
335
}
0 commit comments