LuciferYang commented on a change in pull request #34153:
URL: https://github.com/apache/spark/pull/34153#discussion_r719124756



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala
##########
@@ -322,6 +323,13 @@ private object DateTimeFormatterHelper {
             (isParsing && unsupportedLettersForParsing.contains(c))) {
             throw new IllegalArgumentException(s"Illegal pattern character: 
$c")
           }
+          // SPARK-36796: `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 and disabled 
it here for
+          // compatibility with Java 8 behavior.
+          for (c <- patternPart if unknownPatternLetters.contains(c)) {

Review comment:
       @dongjoon-hyun  @wangyum the result of  `select date_format('2018-11-17 
13:33:33.333', 'B')` in `datetime-formatting-invalid.sql` with Java 8 is:
   ```
   -- !query
   select date_format('2018-11-17 13:33:33.333', 'B')
   -- !query schema
   struct<>
   -- !query output
   java.lang.IllegalArgumentException
   Unknown pattern letter: B
   ```
   
   With Java 17 the result is  
   ```
   - datetime-formatting-invalid.sql *** FAILED ***
     datetime-formatting-invalid.sql
     Expected "struct<[]>", but got "struct<[date_format(2018-11-17 
13:33:33.333, B):string]>" Schema did not match for query #34
     select date_format('2018-11-17 13:33:33.333', 'B'): -- !query
     select date_format('2018-11-17 13:33:33.333', 'B')
     -- !query schema
     struct<date_format(2018-11-17 13:33:33.333, B):string>
     -- !query output
     in the afternoon (SQLQueryTestSuite.scala:469)
   ```
   
   'B' is used to represent `Pattern letters to output a day period` in Java 17 
   
   ```
   *  Pattern  Count  Equivalent builder methods
        *  -------  -----  --------------------------
        *    B       1      appendDayPeriodText(TextStyle.SHORT)
        *    BBBB    4      appendDayPeriodText(TextStyle.FULL)
        *    BBBBB   5      appendDayPeriodText(TextStyle.NARROW)
   ```
   
   Manual disabled it there for compatibility with Java 8 behavior.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to