diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala index b00113b2e9ee3..cb03ab2ee4aae 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala @@ -279,7 +279,11 @@ private object DateTimeFormatterHelper { // localized, for the default Locale.US, it uses Sunday as the first day of week, while in Spark // 2.4, the SimpleDateFormat uses Monday as the first day of week. final val weekBasedLetters = Set('Y', 'W', 'w', 'u', 'e', 'c') - final val unsupportedLetters = Set('A', 'n', 'N', 'p') + // SPARK-36970: `select date_format('2018-11-17 13:33:33.333', 'B')` failed with Java 8, + // but use Java 17 will return `in the afternoon` because 'B' is used to represent + // `Pattern letters to output a day period` in Java 17. So there manual disabled `B` for + // compatibility with Java 8 behavior. + final val unsupportedLetters = Set('A', 'B', 'n', 'N', 'p') // The quarter fields will also be parsed strangely, e.g. when the pattern contains `yMd` and can // be directly resolved then the `q` do check for whether the month is valid, but if the date // fields is incomplete, e.g. `yM`, the checking will be bypassed. diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DatetimeFormatterSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DatetimeFormatterSuite.scala index 0640dc7a16edb..332568ab2d71a 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DatetimeFormatterSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DatetimeFormatterSuite.scala @@ -76,7 +76,7 @@ trait DatetimeFormatterSuite extends SparkFunSuite with SQLHelper with Matchers Seq(true, false).foreach { isParsing => // not support by the legacy one too - val unsupportedBoth = Seq("QQQQQ", "qqqqq", "eeeee", "A", "c", "n", "N", "p", "e") + val unsupportedBoth = Seq("QQQQQ", "qqqqq", "eeeee", "A", "B", "c", "n", "N", "p", "e") unsupportedBoth.foreach { pattern => intercept[IllegalArgumentException](checkFormatterCreation(pattern, isParsing)) } diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out index 18d1a10068794..9c8553dc0f01f 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out @@ -314,7 +314,7 @@ select date_format('2018-11-17 13:33:33.333', 'B') struct<> -- !query output java.lang.IllegalArgumentException -Unknown pattern letter: B +Illegal pattern character: B -- !query