cloud-fan commented on a change in pull request #28766: URL: https://github.com/apache/spark/pull/28766#discussion_r437834522
########## File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/TimestampFormatterSuite.scala ########## @@ -433,4 +433,35 @@ class TimestampFormatterSuite extends DatetimeFormatterSuite { assert(formatter.format(date(1970, 4, 10)) == "100") } } + + test("SPARK-31939: Fix Parsing day of year when year field pattern is missing") { + // resolved to queryable LocaleDate or fail directly + val f0 = TimestampFormatter("yyyy-dd-DD", UTC, isParsing = true) + assert(f0.parse("2020-29-60") === date(2020, 2, 29)) + assertParsingError(f0.parse("2020-02-60")) + val f1 = TimestampFormatter("yyyy-MM-DD", UTC, isParsing = true) + assert(f1.parse("2020-02-60") === date(2020, 2, 29)) + assertParsingError(f1.parse("2020-03-60")) + val f2 = TimestampFormatter("yyyy-MM-dd-DD", UTC, isParsing = true) + assert(f2.parse("2020-02-29-60") === date(2020, 2, 29)) + assertParsingError(f2.parse("2020-03-01-60")) + val f3 = TimestampFormatter("yyyy-DDD", UTC, isParsing = true) + assert(f3.parse("2020-366") === date(2020, 12, 31)) + assertParsingError(f3.parse("2019-366")) + + // unresolved and need to check manually(SPARK-31939 fixed) + val f4 = TimestampFormatter("DDD", UTC, isParsing = true) + assert(f4.parse("365") === date(1970, 12, 31)) + assertParsingError(f4.parse("366")) // 1970 is not a leap year + val f5 = TimestampFormatter("MM-DD", UTC, isParsing = true) + assert(f5.parse("03-60") === date(1970, 3, 1)) + assertParsingError(f5.parse("02-60")) + val f6 = TimestampFormatter("MM-dd-DD", UTC, isParsing = true) + assert(f6.parse("02-28-59") === date(1970, 2, 28)) + assertParsingError(f6.parse("02-28-60")) + assertParsingError(f6.parse("02-28-58")) + val f7 = TimestampFormatter("dd-DD", UTC, isParsing = true) + assert(f7.parse("28-59") === date(1970, 2, 28)) + assertParsingError(f7.parse("27-59")) + } Review comment: can we also add tests in the .sql file? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org