From 7e59d650f3006958b6ea48dca1c3b200a6bf9aad Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 17:12:37 +0800 Subject: [PATCH 01/10] [SPARK-31892][SQL][FOLLOWUP] Improve test coverage for valid pattern formatting --- .../sql/catalyst/util/DateFormatter.scala | 8 +- .../util/DateTimeFormatterHelper.scala | 2 +- .../catalyst/util/TimestampFormatter.scala | 12 +- .../expressions/DateExpressionsSuite.scala | 2 +- .../spark/sql/util/DateFormatterSuite.scala | 46 ++++++++ .../sql/util/TimestampFormatterSuite.scala | 64 +++++++--- .../resources/sql-tests/inputs/datetime.sql | 18 +++ .../sql-tests/results/ansi/datetime.sql.out | 109 +++++++++++++++++- .../sql-tests/results/datetime-legacy.sql.out | 99 +++++++++++++++- .../sql-tests/results/datetime.sql.out | 109 +++++++++++++++++- 10 files changed, 437 insertions(+), 32 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala index 5bb92c61cced2..63988ad4a5077 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala @@ -46,7 +46,7 @@ class Iso8601DateFormatter( extends DateFormatter with DateTimeFormatterHelper { @transient - private lazy val formatter = getOrCreateFormatter(pattern, locale) + private lazy val formatter = getOrCreateFormatter(pattern, locale, isParsing) @transient private lazy val legacyFormatter = DateFormatter.getLegacyFormatter( @@ -132,7 +132,7 @@ object DateFormatter { zoneId: ZoneId, locale: Locale = defaultLocale, legacyFormat: LegacyDateFormat = LENIENT_SIMPLE_DATE_FORMAT, - isParsing: Boolean = true): DateFormatter = { + isParsing: Boolean): DateFormatter = { val pattern = format.getOrElse(defaultPattern) if (SQLConf.get.legacyTimeParserPolicy == LEGACY) { getLegacyFormatter(pattern, zoneId, locale, legacyFormat) @@ -166,10 +166,10 @@ object DateFormatter { } def apply(format: String, zoneId: ZoneId): DateFormatter = { - getFormatter(Some(format), zoneId) + getFormatter(Some(format), zoneId, isParsing = false) } def apply(zoneId: ZoneId): DateFormatter = { - getFormatter(None, zoneId) + getFormatter(None, zoneId, isParsing = false) } } 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 ffa7cd438b29b..b6aaf17830379 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 @@ -89,7 +89,7 @@ trait DateTimeFormatterHelper { protected def getOrCreateFormatter( pattern: String, locale: Locale, - isParsing: Boolean = false): DateTimeFormatter = { + isParsing: Boolean): DateTimeFormatter = { val newPattern = convertIncompatiblePattern(pattern, isParsing) val useVarLen = isParsing && newPattern.contains('S') val key = (newPattern, locale, useVarLen) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala index 63a4c2ed3fc08..99fab405d48f2 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala @@ -62,11 +62,11 @@ class Iso8601TimestampFormatter( zoneId: ZoneId, locale: Locale, legacyFormat: LegacyDateFormat = LENIENT_SIMPLE_DATE_FORMAT, - needVarLengthSecondFraction: Boolean) + isParsing: Boolean) extends TimestampFormatter with DateTimeFormatterHelper { @transient protected lazy val formatter: DateTimeFormatter = - getOrCreateFormatter(pattern, locale, needVarLengthSecondFraction) + getOrCreateFormatter(pattern, locale, isParsing) @transient protected lazy val legacyFormatter = TimestampFormatter.getLegacyFormatter( @@ -122,7 +122,7 @@ class FractionTimestampFormatter(zoneId: ZoneId) zoneId, TimestampFormatter.defaultLocale, LegacyDateFormats.FAST_DATE_FORMAT, - needVarLengthSecondFraction = false) { + isParsing = false) { @transient override protected lazy val formatter = DateTimeFormatterHelper.fractionFormatter @@ -293,7 +293,7 @@ object TimestampFormatter { zoneId: ZoneId, locale: Locale = defaultLocale, legacyFormat: LegacyDateFormat = LENIENT_SIMPLE_DATE_FORMAT, - isParsing: Boolean = false): TimestampFormatter = { + isParsing: Boolean): TimestampFormatter = { val pattern = format.getOrElse(defaultPattern) if (SQLConf.get.legacyTimeParserPolicy == LEGACY) { getLegacyFormatter(pattern, zoneId, locale, legacyFormat) @@ -340,12 +340,12 @@ object TimestampFormatter { def apply( format: String, zoneId: ZoneId, - isParsing: Boolean = false): TimestampFormatter = { + isParsing: Boolean): TimestampFormatter = { getFormatter(Some(format), zoneId, isParsing = isParsing) } def apply(zoneId: ZoneId): TimestampFormatter = { - getFormatter(None, zoneId) + getFormatter(None, zoneId, isParsing = false) } def getFractionFormatter(zoneId: ZoneId): TimestampFormatter = { diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala index c4c189c50febc..cc02c55e29d92 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala @@ -41,7 +41,7 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { private val JST_OPT = Option(JST.getId) def toMillis(timestamp: String): Long = { - val tf = TimestampFormatter("yyyy-MM-dd HH:mm:ss", UTC) + val tf = TimestampFormatter("yyyy-MM-dd HH:mm:ss", UTC, isParsing = false) DateTimeUtils.microsToMillis(tf.parse(timestamp)) } val date = "2015-04-08 13:10:15" diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/util/DateFormatterSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/util/DateFormatterSuite.scala index 22a1396d5efdc..a64ba4e360af4 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/util/DateFormatterSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/util/DateFormatterSuite.scala @@ -199,4 +199,50 @@ class DateFormatterSuite extends SparkFunSuite with SQLHelper { // SparkUpgradeException here. intercept[SparkUpgradeException](formatter.parse("02-29")) } + + test("Disable week-based date fields and quarter fields for parsing") { + + def checkSparkUpgrade(c: Char): Unit = { + intercept[SparkUpgradeException] { + DateFormatter( + c.toString, + UTC, + DateFormatter.defaultLocale, + LegacyDateFormats.SIMPLE_DATE_FORMAT, + isParsing = true) + } + assert(DateFormatter( + c.toString, + UTC, + DateFormatter.defaultLocale, + LegacyDateFormats.SIMPLE_DATE_FORMAT, + isParsing = false).format(0).nonEmpty) + } + + def checkIllegalArg(c: Char): Unit = { + intercept[IllegalArgumentException] { + DateFormatter( + c.toString, + UTC, + DateFormatter.defaultLocale, + LegacyDateFormats.SIMPLE_DATE_FORMAT, + isParsing = true) + } + + assert(DateFormatter( + c.toString, + UTC, + DateFormatter.defaultLocale, + LegacyDateFormats.SIMPLE_DATE_FORMAT, + isParsing = false).format(0).nonEmpty) + } + + Seq('Y', 'W', 'w', 'E', 'u', 'F').foreach { l => + checkSparkUpgrade(l) + } + + Seq('q', 'Q').foreach { l => + checkIllegalArg(l) + } + } } diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/util/TimestampFormatterSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/util/TimestampFormatterSuite.scala index 7ba45be06a5d3..bd12fc1704d67 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/util/TimestampFormatterSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/util/TimestampFormatterSuite.scala @@ -96,7 +96,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers 2177456523456789L, 11858049903010203L).foreach { micros => outstandingZoneIds.foreach { zoneId => - val timestamp = TimestampFormatter(pattern, zoneId).format(micros) + val timestamp = TimestampFormatter(pattern, zoneId, isParsing = false).format(micros) val parsed = TimestampFormatter( pattern, zoneId, isParsing = true).parse(timestamp) assert(micros === parsed) @@ -120,14 +120,14 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers val pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS" val micros = TimestampFormatter( pattern, zoneId, isParsing = true).parse(timestamp) - val formatted = TimestampFormatter(pattern, zoneId).format(micros) + val formatted = TimestampFormatter(pattern, zoneId, isParsing = false).format(micros) assert(timestamp === formatted) } } } test("case insensitive parsing of am and pm") { - val formatter = TimestampFormatter("yyyy MMM dd hh:mm:ss a", UTC) + val formatter = TimestampFormatter("yyyy MMM dd hh:mm:ss a", UTC, isParsing = false) val micros = formatter.parse("2009 Mar 20 11:30:01 am") assert(micros === date(2009, 3, 20, 11, 30, 1)) } @@ -157,8 +157,8 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers assert(TimestampFormatter(UTC).format(micros) === "-0099-01-01 00:00:00") assert(TimestampFormatter(UTC).format(instant) === "-0099-01-01 00:00:00") withDefaultTimeZone(UTC) { // toJavaTimestamp depends on the default time zone - assert(TimestampFormatter("yyyy-MM-dd HH:mm:SS G", UTC).format(toJavaTimestamp(micros)) - === "0100-01-01 00:00:00 BC") + assert(TimestampFormatter("yyyy-MM-dd HH:mm:SS G", UTC, isParsing = false) + .format(toJavaTimestamp(micros)) === "0100-01-01 00:00:00 BC") } } @@ -209,7 +209,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers "2019-10-14T09:39:07.1", "2019-10-14T09:39:07.1") try { - TimestampFormatter("yyyy/MM/dd HH_mm_ss.SSSSSS", zoneId, true) + TimestampFormatter("yyyy/MM/dd HH_mm_ss.SSSSSS", zoneId, isParsing = true) .parse("2019/11/14 20#25#30.123456") fail("Expected to throw an exception for the invalid input") } catch { @@ -222,7 +222,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers test("formatting timestamp strings up to microsecond precision") { outstandingZoneIds.foreach { zoneId => def check(pattern: String, input: String, expected: String): Unit = { - val formatter = TimestampFormatter(pattern, zoneId) + val formatter = TimestampFormatter(pattern, zoneId, isParsing = false) val timestamp = stringToTimestamp(UTF8String.fromString(input), zoneId).get val actual = formatter.format(timestamp) assert(actual === expected) @@ -259,7 +259,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers } test("SPARK-30958: parse timestamp with negative year") { - val formatter1 = TimestampFormatter("yyyy-MM-dd HH:mm:ss", UTC, true) + val formatter1 = TimestampFormatter("yyyy-MM-dd HH:mm:ss", UTC, isParsing = true) assert(formatter1.parse("-1234-02-22 02:22:22") === date(-1234, 2, 22, 2, 22, 22)) def assertParsingError(f: => Unit): Unit = { @@ -272,7 +272,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers } // "yyyy" with "G" can't parse negative year or year 0000. - val formatter2 = TimestampFormatter("G yyyy-MM-dd HH:mm:ss", UTC, true) + val formatter2 = TimestampFormatter("G yyyy-MM-dd HH:mm:ss", UTC, isParsing = true) assertParsingError(formatter2.parse("BC -1234-02-22 02:22:22")) assertParsingError(formatter2.parse("AC 0000-02-22 02:22:22")) @@ -318,7 +318,7 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers test("parsing hour with various patterns") { def createFormatter(pattern: String): TimestampFormatter = { // Use `SIMPLE_DATE_FORMAT`, so that the legacy parser also fails with invalid value range. - TimestampFormatter(pattern, UTC, LegacyDateFormats.SIMPLE_DATE_FORMAT, false) + TimestampFormatter(pattern, UTC, LegacyDateFormats.SIMPLE_DATE_FORMAT, isParsing = false) } withClue("HH") { @@ -377,25 +377,26 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers } test("missing date fields") { - val formatter = TimestampFormatter("HH:mm:ss", UTC) + val formatter = TimestampFormatter("HH:mm:ss", UTC, isParsing = true) val micros = formatter.parse("11:30:01") assert(micros === date(1970, 1, 1, 11, 30, 1)) } test("missing year field with invalid date") { // Use `SIMPLE_DATE_FORMAT`, so that the legacy parser also fails with invalid date. - val formatter = TimestampFormatter("MM-dd", UTC, LegacyDateFormats.SIMPLE_DATE_FORMAT, false) + val formatter = + TimestampFormatter("MM-dd", UTC, LegacyDateFormats.SIMPLE_DATE_FORMAT, isParsing = false) withDefaultTimeZone(UTC)(intercept[DateTimeException](formatter.parse("02-29"))) } test("missing am/pm field") { - val formatter = TimestampFormatter("yyyy hh:mm:ss", UTC) + val formatter = TimestampFormatter("yyyy hh:mm:ss", UTC, isParsing = true) val micros = formatter.parse("2009 11:30:01") assert(micros === date(2009, 1, 1, 11, 30, 1)) } test("missing time fields") { - val formatter = TimestampFormatter("yyyy HH", UTC) + val formatter = TimestampFormatter("yyyy HH", UTC, isParsing = true) val micros = formatter.parse("2009 11") assert(micros === date(2009, 1, 1, 11)) } @@ -403,12 +404,41 @@ class TimestampFormatterSuite extends SparkFunSuite with SQLHelper with Matchers test("explicitly forbidden datetime patterns") { // not support by the legacy one too Seq("QQQQQ", "qqqqq", "A", "c", "e", "n", "N", "p").foreach { pattern => - intercept[IllegalArgumentException](TimestampFormatter(pattern, UTC).format(0)) + intercept[IllegalArgumentException](TimestampFormatter(pattern, UTC, isParsing = false) + .format(0)) } // supported by the legacy one, then we will suggest users with SparkUpgradeException - Seq("GGGGG", "MMMMM", "LLLLL", "EEEEE", "uuuuu", "aa", "aaa", "y" * 11, "y" * 11) + Seq("GGGGG", "MMMMM", "LLLLL", "EEEEE", "uuuuu", "aa", "aaa", "y" * 11, "Y" * 11) .foreach { pattern => - intercept[SparkUpgradeException](TimestampFormatter(pattern, UTC).format(0)) + intercept[SparkUpgradeException] { + TimestampFormatter(pattern, UTC, isParsing = false).format(0) + } + } + } + + test("Disable week-based date fields and quarter fields for parsing") { + + def checkSparkUpgrade(c: Char): Unit = { + intercept[SparkUpgradeException] { + TimestampFormatter(c.toString, UTC, isParsing = true) + } + assert(TimestampFormatter(c.toString, UTC, isParsing = false).format(0).nonEmpty) + } + + def checkIllegalArg(c: Char): Unit = { + intercept[IllegalArgumentException] { + TimestampFormatter(c.toString, UTC, isParsing = true) + } + + assert(TimestampFormatter(c.toString, UTC, isParsing = false).format(0).nonEmpty) + } + + Seq('Y', 'W', 'w', 'E', 'u', 'F').foreach { l => + checkSparkUpgrade(l) + } + + Seq('q', 'Q').foreach { l => + checkIllegalArg(l) } } } diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql index 5636e0b670362..86df3b4988a06 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql @@ -168,3 +168,21 @@ select date_format(date '2018-11-17', 'yyyyyyyyyyy-MM-dd'); -- SPARK-31879: the first day of week select date_format('2020-01-01', 'YYYY-MM-dd uu'); select date_format('2020-01-01', 'YYYY-MM-dd uuuu'); + +-- valid formatter pattern check +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t); +select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt; +select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt; +select date_format(t, 'M MM MMM MMMM L LL') from ttt; +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt; +select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt; +select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt; +select date_format(date '1970-01-01', 'D DD'); + diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out index 3803460f3f083..0bb1ab62659a3 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 121 +-- Number of queries: 129 -- !query @@ -1041,3 +1041,110 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 Wednesday + + +-- !query +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) +-- !query schema +struct<> +-- !query output + + + +-- !query +select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +-- !query schema +struct +-- !query output +1582 82 1582 01582 01582 1582 82 1582 1582 01582 +1970 70 1970 01970 01970 1969 69 1969 1969 01969 +1970 70 1970 01970 01970 1970 70 1970 1970 01970 +1996 96 1996 01996 01996 1996 96 1996 1996 01996 +2018 18 2018 02018 02018 2018 18 2018 2018 02018 +2020 20 2020 02020 02020 2019 19 2019 2019 02019 +2099 99 2099 02099 02099 2099 99 2099 2099 02099 + + +-- !query +select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt +-- !query schema +struct +-- !query output +1 01 1 01 Q1 1st quarter +2 02 2 02 Q2 2nd quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter + + +-- !query +select date_format(t, 'M MM MMM MMMM L LL') from ttt +-- !query schema +struct +-- !query output +11 11 Nov November 11 11 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +3 03 Mar March 3 03 +5 05 May May 5 05 + + +-- !query +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +-- !query schema +struct +-- !query output +3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday +4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday +5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday +5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday +5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday + + +-- !query +select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt +-- !query schema +struct +-- !query output +11 11 23 23 23 23 11 11 59 59 59 59 999 +3 03 15 15 15 15 3 03 0 00 0 00 000 +5 05 5 05 5 05 5 05 33 33 33 33 123 +6 06 6 06 6 06 6 06 33 33 33 33 123 +7 07 19 19 19 19 7 07 40 40 35 35 123 +7 07 7 07 7 07 7 07 3 03 33 33 123 +9 09 9 09 9 09 9 09 33 33 33 33 123 + + +-- !query +select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt +-- !query schema +struct +-- !query output +America/Los_Angeles PST PST PST Pacific Standard Time GMT-7:52:58 GMT-07:52:58 -0752 -0752 -07:52 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 + + +-- !query +select date_format(date '1970-01-01', 'D DD') +-- !query schema +struct +-- !query output +1 01 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out index 99dd14d21e6fd..b2f69659144f0 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 121 +-- Number of queries: 129 -- !query @@ -996,3 +996,100 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 0003 + + +-- !query +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) +-- !query schema +struct<> +-- !query output + + + +-- !query +select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +-- !query schema +struct +-- !query output +1582 82 1582 01582 01582 1582 82 1582 1582 01582 +1970 70 1970 01970 01970 1969 69 1969 1969 01969 +1970 70 1970 01970 01970 1970 70 1970 1970 01970 +1996 96 1996 01996 01996 1996 96 1996 1996 01996 +2018 18 2018 02018 02018 2018 18 2018 2018 02018 +2020 20 2020 02020 02020 2019 19 2019 2019 02019 +2099 99 2099 02099 02099 2099 99 2099 2099 02099 + + +-- !query +select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'q' + + +-- !query +select date_format(t, 'M MM MMM MMMM L LL') from ttt +-- !query schema +struct +-- !query output +11 11 Nov November 11 11 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +3 03 Mar March 3 03 +5 05 May May 5 05 + + +-- !query +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +-- !query schema +struct +-- !query output +3 46 17 17 321 6 06 006 0006 3 Sat Sat Sat Saturday +4 13 31 31 091 7 07 007 0007 5 Sun Sun Sun Sunday +5 01 31 31 365 2 02 002 0002 5 Tue Tue Tue Tuesday +5 01 31 31 365 3 03 003 0003 5 Wed Wed Wed Wednesday +5 22 31 31 151 4 04 004 0004 5 Thu Thu Thu Thursday +5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday +5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday + + +-- !query +select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt +-- !query schema +struct +-- !query output +11 11 23 23 23 23 11 11 59 59 59 59 999 +3 03 15 15 15 15 3 03 0 00 0 00 000 +5 05 5 05 5 05 5 05 33 33 33 33 123 +6 06 6 06 6 06 6 06 33 33 33 33 123 +7 07 19 19 19 19 7 07 40 40 35 35 123 +7 07 7 07 7 07 7 07 3 03 33 33 123 +9 09 9 09 9 09 9 09 33 33 33 33 123 + + +-- !query +select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'V' + + +-- !query +select date_format(date '1970-01-01', 'D DD') +-- !query schema +struct +-- !query output +1 01 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out index c8c568c736d76..c3922a438ba25 100755 --- a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 121 +-- Number of queries: 129 -- !query @@ -1013,3 +1013,110 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 Wednesday + + +-- !query +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) +-- !query schema +struct<> +-- !query output + + + +-- !query +select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +-- !query schema +struct +-- !query output +1582 82 1582 01582 01582 1582 82 1582 1582 01582 +1970 70 1970 01970 01970 1969 69 1969 1969 01969 +1970 70 1970 01970 01970 1970 70 1970 1970 01970 +1996 96 1996 01996 01996 1996 96 1996 1996 01996 +2018 18 2018 02018 02018 2018 18 2018 2018 02018 +2020 20 2020 02020 02020 2019 19 2019 2019 02019 +2099 99 2099 02099 02099 2099 99 2099 2099 02099 + + +-- !query +select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt +-- !query schema +struct +-- !query output +1 01 1 01 Q1 1st quarter +2 02 2 02 Q2 2nd quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter +4 04 4 04 Q4 4th quarter + + +-- !query +select date_format(t, 'M MM MMM MMMM L LL') from ttt +-- !query schema +struct +-- !query output +11 11 Nov November 11 11 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +12 12 Dec December 12 12 +3 03 Mar March 3 03 +5 05 May May 5 05 + + +-- !query +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +-- !query schema +struct +-- !query output +3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday +4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday +5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday +5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday +5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday + + +-- !query +select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt +-- !query schema +struct +-- !query output +11 11 23 23 23 23 11 11 59 59 59 59 999 +3 03 15 15 15 15 3 03 0 00 0 00 000 +5 05 5 05 5 05 5 05 33 33 33 33 123 +6 06 6 06 6 06 6 06 33 33 33 33 123 +7 07 19 19 19 19 7 07 40 40 35 35 123 +7 07 7 07 7 07 7 07 3 03 33 33 123 +9 09 9 09 9 09 9 09 33 33 33 33 123 + + +-- !query +select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt +-- !query schema +struct +-- !query output +America/Los_Angeles PST PST PST Pacific Standard Time GMT-7:52:58 GMT-07:52:58 -0752 -0752 -07:52 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 + + +-- !query +select date_format(date '1970-01-01', 'D DD') +-- !query schema +struct +-- !query output +1 01 From 6449e08dcd03a36dc1f011f991c0245fa4135b08 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 17:32:37 +0800 Subject: [PATCH 02/10] add case --- .../resources/sql-tests/inputs/datetime.sql | 8 ++--- .../sql-tests/results/ansi/datetime.sql.out | 34 +++++++++---------- .../sql-tests/results/datetime-legacy.sql.out | 32 ++++++++--------- .../sql-tests/results/datetime.sql.out | 34 +++++++++---------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql index 86df3b4988a06..ecffed846af58 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql @@ -172,16 +172,16 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu'); -- valid formatter pattern check create temporary view ttt as select t from VALUES (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '2018-11-17 13:33:33.123Z'), (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t); + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t); select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt; select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt; select date_format(t, 'M MM MMM MMMM L LL') from ttt; -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt; +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt; select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt; select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt; select date_format(date '1970-01-01', 'D DD'); diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out index 0bb1ab62659a3..83aa164272be3 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out @@ -1046,12 +1046,12 @@ struct -- !query create temporary view ttt as select t from VALUES (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '2018-11-17 13:33:33.123Z'), (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) -- !query schema struct<> -- !query output @@ -1069,7 +1069,7 @@ struct 1996 96 1996 01996 01996 1996 96 1996 1996 01996 2018 18 2018 02018 02018 2018 18 2018 2018 02018 2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2099 99 2099 2099 02099 +2099 99 2099 02099 02099 2100 00 2100 2100 02100 -- !query @@ -1078,12 +1078,12 @@ select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt struct -- !query output 1 01 1 01 Q1 1st quarter +1 01 1 01 Q1 1st quarter 2 02 2 02 Q2 2nd quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -- !query @@ -1091,27 +1091,27 @@ select date_format(t, 'M MM MMM MMMM L LL') from ttt -- !query schema struct -- !query output +1 01 Jan January 1 01 11 11 Nov November 11 11 12 12 Dec December 12 12 12 12 Dec December 12 12 12 12 Dec December 12 12 -12 12 Dec December 12 12 3 03 Mar March 3 03 5 05 May May 5 05 -- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt -- !query schema -struct +struct -- !query output -3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday -4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday -5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday -5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday -5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday +0 53 1 01 001 5 05 Fri Friday 1 Fri Fri Fri Friday AM +3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday AM +4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday AM +5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday AM +5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday PM +5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday PM +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday AM -- !query @@ -1119,10 +1119,10 @@ select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt -- !query schema struct -- !query output -11 11 23 23 23 23 11 11 59 59 59 59 999 +1 01 1 01 1 01 1 01 33 33 33 33 123 3 03 15 15 15 15 3 03 0 00 0 00 000 +4 04 4 04 4 04 4 04 59 59 59 59 999 5 05 5 05 5 05 5 05 33 33 33 33 123 -6 06 6 06 6 06 6 06 33 33 33 33 123 7 07 19 19 19 19 7 07 40 40 35 35 123 7 07 7 07 7 07 7 07 3 03 33 33 123 9 09 9 09 9 09 9 09 33 33 33 33 123 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out index b2f69659144f0..6e0e9a51a5ca6 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out @@ -1001,12 +1001,12 @@ struct -- !query create temporary view ttt as select t from VALUES (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '2018-11-17 13:33:33.123Z'), (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) -- !query schema struct<> -- !query output @@ -1024,7 +1024,7 @@ struct 1996 96 1996 01996 01996 1996 96 1996 1996 01996 2018 18 2018 02018 02018 2018 18 2018 2018 02018 2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2099 99 2099 2099 02099 +2099 99 2099 02099 02099 2100 00 2100 2100 02100 -- !query @@ -1041,27 +1041,27 @@ select date_format(t, 'M MM MMM MMMM L LL') from ttt -- !query schema struct -- !query output +1 01 Jan January 1 01 11 11 Nov November 11 11 12 12 Dec December 12 12 12 12 Dec December 12 12 12 12 Dec December 12 12 -12 12 Dec December 12 12 3 03 Mar March 3 03 5 05 May May 5 05 -- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt -- !query schema -struct +struct -- !query output -3 46 17 17 321 6 06 006 0006 3 Sat Sat Sat Saturday -4 13 31 31 091 7 07 007 0007 5 Sun Sun Sun Sunday -5 01 31 31 365 2 02 002 0002 5 Tue Tue Tue Tuesday -5 01 31 31 365 3 03 003 0003 5 Wed Wed Wed Wednesday -5 22 31 31 151 4 04 004 0004 5 Thu Thu Thu Thursday -5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday -5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday +0 53 1 01 001 5 05 005 0005 1 Fri Fri Fri Friday AM +3 46 17 17 321 6 06 006 0006 3 Sat Sat Sat Saturday AM +4 13 31 31 091 7 07 007 0007 5 Sun Sun Sun Sunday AM +5 01 31 31 365 2 02 002 0002 5 Tue Tue Tue Tuesday AM +5 01 31 31 365 3 03 003 0003 5 Wed Wed Wed Wednesday PM +5 22 31 31 151 4 04 004 0004 5 Thu Thu Thu Thursday PM +5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday AM -- !query @@ -1069,10 +1069,10 @@ select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt -- !query schema struct -- !query output -11 11 23 23 23 23 11 11 59 59 59 59 999 +1 01 1 01 1 01 1 01 33 33 33 33 123 3 03 15 15 15 15 3 03 0 00 0 00 000 +4 04 4 04 4 04 4 04 59 59 59 59 999 5 05 5 05 5 05 5 05 33 33 33 33 123 -6 06 6 06 6 06 6 06 33 33 33 33 123 7 07 19 19 19 19 7 07 40 40 35 35 123 7 07 7 07 7 07 7 07 3 03 33 33 123 9 09 9 09 9 09 9 09 33 33 33 33 123 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out index c3922a438ba25..629a9d1b0f85f 100755 --- a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out @@ -1018,12 +1018,12 @@ struct -- !query create temporary view ttt as select t from VALUES (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999America/Los_Angeles'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), (timestamp '2018-11-17 13:33:33.123Z'), (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123Asia/Srednekolymsk') tt(t) + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) -- !query schema struct<> -- !query output @@ -1041,7 +1041,7 @@ struct 1996 96 1996 01996 01996 1996 96 1996 1996 01996 2018 18 2018 02018 02018 2018 18 2018 2018 02018 2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2099 99 2099 2099 02099 +2099 99 2099 02099 02099 2100 00 2100 2100 02100 -- !query @@ -1050,12 +1050,12 @@ select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt struct -- !query output 1 01 1 01 Q1 1st quarter +1 01 1 01 Q1 1st quarter 2 02 2 02 Q2 2nd quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter 4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -- !query @@ -1063,27 +1063,27 @@ select date_format(t, 'M MM MMM MMMM L LL') from ttt -- !query schema struct -- !query output +1 01 Jan January 1 01 11 11 Nov November 11 11 12 12 Dec December 12 12 12 12 Dec December 12 12 12 12 Dec December 12 12 -12 12 Dec December 12 12 3 03 Mar March 3 03 5 05 May May 5 05 -- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE') from ttt +select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt -- !query schema -struct +struct -- !query output -3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday -4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday -5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday -5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday -5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday +0 53 1 01 001 5 05 Fri Friday 1 Fri Fri Fri Friday AM +3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday AM +4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday AM +5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday AM +5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday PM +5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday PM +5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday AM -- !query @@ -1091,10 +1091,10 @@ select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt -- !query schema struct -- !query output -11 11 23 23 23 23 11 11 59 59 59 59 999 +1 01 1 01 1 01 1 01 33 33 33 33 123 3 03 15 15 15 15 3 03 0 00 0 00 000 +4 04 4 04 4 04 4 04 59 59 59 59 999 5 05 5 05 5 05 5 05 33 33 33 33 123 -6 06 6 06 6 06 6 06 33 33 33 33 123 7 07 19 19 19 19 7 07 40 40 35 35 123 7 07 7 07 7 07 7 07 3 03 33 33 123 9 09 9 09 9 09 9 09 33 33 33 33 123 From de63621fb392d4d9448d365c8d8bc6bee9f46012 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 17:41:43 +0800 Subject: [PATCH 03/10] remove default value --- .../util/DateTimeFormatterHelper.scala | 2 +- .../util/DateTimeFormatterHelperSuite.scala | 44 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) 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 b6aaf17830379..af1f38c360c00 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 @@ -252,7 +252,7 @@ private object DateTimeFormatterHelper { * @param pattern The input pattern. * @return The pattern for new parser */ - def convertIncompatiblePattern(pattern: String, isParsing: Boolean = false): String = { + def convertIncompatiblePattern(pattern: String, isParsing: Boolean): String = { val eraDesignatorContained = pattern.split("'").zipWithIndex.exists { case (patternPart, index) => // Text can be quoted using single quotes, we only check the non-quote parts. diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala index c68bdacb13af7..2a9f0ac50c70f 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala @@ -23,21 +23,26 @@ import org.apache.spark.sql.catalyst.util.DateTimeFormatterHelper._ class DateTimeFormatterHelperSuite extends SparkFunSuite { test("check incompatible pattern") { - assert(convertIncompatiblePattern("MM-DD-u") === "MM-DD-e") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz") - === "uuuu-MM-dd'T'HH:mm:ss.SSSz") - assert(convertIncompatiblePattern("yyyy-MM'y contains in quoted text'HH:mm:ss") - === "uuuu-MM'y contains in quoted text'HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd-u'T'HH:mm:ss.SSSz") + assert(convertIncompatiblePattern("MM-DD-u", isParsing = false) === "MM-DD-e") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz", isParsing = false) === + "uuuu-MM-dd'T'HH:mm:ss.SSSz") + assert(convertIncompatiblePattern( + "yyyy-MM'y contains in quoted text'HH:mm:ss", isParsing = false) === + "uuuu-MM'y contains in quoted text'HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd-u'T'HH:mm:ss.SSSz", isParsing = false) === "uuuu-MM-dd-e'T'HH:mm:ss.SSSz") - assert(convertIncompatiblePattern("yyyy-MM'u contains in quoted text'HH:mm:ss") + assert( + convertIncompatiblePattern("yyyy-MM'u contains in quoted text'HH:mm:ss", isParsing = false) === "uuuu-MM'u contains in quoted text'HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM'u contains in quoted text'''''HH:mm:ss") - === "uuuu-MM'u contains in quoted text'''''HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz G") - === "yyyy-MM-dd'T'HH:mm:ss.SSSz G") + assert(convertIncompatiblePattern( + "yyyy-MM'u contains in quoted text'''''HH:mm:ss", isParsing = false) === + "uuuu-MM'u contains in quoted text'''''HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz G", isParsing = false) === + "yyyy-MM-dd'T'HH:mm:ss.SSSz G") unsupportedLetters.foreach { l => - val e = intercept[IllegalArgumentException](convertIncompatiblePattern(s"yyyy-MM-dd $l G")) + val e = intercept[IllegalArgumentException] { + convertIncompatiblePattern(s"yyyy-MM-dd $l G", isParsing = false) + } assert(e.getMessage === s"Illegal pattern character: $l") } unsupportedLettersForParsing.foreach { l => @@ -45,21 +50,22 @@ class DateTimeFormatterHelperSuite extends SparkFunSuite { convertIncompatiblePattern(s"$l", isParsing = true) } assert(e.getMessage === s"Illegal pattern character: $l") - assert(convertIncompatiblePattern(s"$l").nonEmpty) + assert(convertIncompatiblePattern(s"$l", isParsing = false).nonEmpty) } unsupportedPatternLengths.foreach { style => val e1 = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"yyyy-MM-dd $style") + convertIncompatiblePattern(s"yyyy-MM-dd $style", isParsing = false) } assert(e1.getMessage === s"Too many pattern letters: ${style.head}") val e2 = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"yyyy-MM-dd $style${style.head}") + convertIncompatiblePattern(s"yyyy-MM-dd $style${style.head}", isParsing = false) } assert(e2.getMessage === s"Too many pattern letters: ${style.head}") } - assert(convertIncompatiblePattern("yyyy-MM-dd uuuu") === "uuuu-MM-dd eeee") - assert(convertIncompatiblePattern("yyyy-MM-dd EEEE") === "uuuu-MM-dd EEEE") - assert(convertIncompatiblePattern("yyyy-MM-dd'e'HH:mm:ss") === "uuuu-MM-dd'e'HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'") === "uuuu-MM-dd'T'") + assert(convertIncompatiblePattern("yyyy-MM-dd uuuu", isParsing = false) === "uuuu-MM-dd eeee") + assert(convertIncompatiblePattern("yyyy-MM-dd EEEE", isParsing = false) === "uuuu-MM-dd EEEE") + assert(convertIncompatiblePattern("yyyy-MM-dd'e'HH:mm:ss", isParsing = false) === + "uuuu-MM-dd'e'HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'", isParsing = false) === "uuuu-MM-dd'T'") } } From 3fea4def77afc42df69da7796dbfec1b4fe4be51 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 18:12:22 +0800 Subject: [PATCH 04/10] better look --- .../resources/sql-tests/inputs/datetime.sql | 9 +-- .../sql-tests/results/ansi/datetime.sql.out | 72 ++++++------------- .../sql-tests/results/datetime-legacy.sql.out | 72 ++++++------------- .../sql-tests/results/datetime.sql.out | 72 ++++++------------- 4 files changed, 69 insertions(+), 156 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql index ecffed846af58..2ab99ef085d92 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql @@ -178,11 +178,8 @@ create temporary view ttt as select t from VALUES (timestamp '2018-11-17 13:33:33.123Z'), (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t); -select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt; +select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt; select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt; -select date_format(t, 'M MM MMM MMMM L LL') from ttt; -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt; -select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt; +select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt; select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt; -select date_format(date '1970-01-01', 'D DD'); - +select date_format(date '1970-01-01', 'D DD DDD'); diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out index 83aa164272be3..5a7bb3d321cdc 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 129 +-- Number of queries: 127 -- !query @@ -1059,17 +1059,17 @@ struct<> -- !query -select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt -- !query schema -struct +struct -- !query output -1582 82 1582 01582 01582 1582 82 1582 1582 01582 -1970 70 1970 01970 01970 1969 69 1969 1969 01969 -1970 70 1970 01970 01970 1970 70 1970 1970 01970 -1996 96 1996 01996 01996 1996 96 1996 1996 01996 -2018 18 2018 02018 02018 2018 18 2018 2018 02018 -2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2100 00 2100 2100 02100 +1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday +1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday +1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday +1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday +2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday +2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday +2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday -- !query @@ -1087,45 +1087,17 @@ struct -- !query -select date_format(t, 'M MM MMM MMMM L LL') from ttt +select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt -- !query schema -struct +struct -- !query output -1 01 Jan January 1 01 -11 11 Nov November 11 11 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -3 03 Mar March 3 03 -5 05 May May 5 05 - - --- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt --- !query schema -struct --- !query output -0 53 1 01 001 5 05 Fri Friday 1 Fri Fri Fri Friday AM -3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday AM -4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday AM -5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday AM -5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday PM -5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday PM -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday AM - - --- !query -select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt --- !query schema -struct --- !query output -1 01 1 01 1 01 1 01 33 33 33 33 123 -3 03 15 15 15 15 3 03 0 00 0 00 000 -4 04 4 04 4 04 4 04 59 59 59 59 999 -5 05 5 05 5 05 5 05 33 33 33 33 123 -7 07 19 19 19 19 7 07 40 40 35 35 123 -7 07 7 07 7 07 7 07 3 03 33 33 123 -9 09 9 09 9 09 9 09 33 33 33 33 123 +1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM +1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM +1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM +1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM +2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM +2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM -- !query @@ -1143,8 +1115,8 @@ America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -- !query -select date_format(date '1970-01-01', 'D DD') +select date_format(date '1970-01-01', 'D DD DDD') -- !query schema -struct +struct -- !query output -1 01 +1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out index 6e0e9a51a5ca6..26fb39a05952b 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 129 +-- Number of queries: 127 -- !query @@ -1014,17 +1014,17 @@ struct<> -- !query -select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt -- !query schema -struct +struct -- !query output -1582 82 1582 01582 01582 1582 82 1582 1582 01582 -1970 70 1970 01970 01970 1969 69 1969 1969 01969 -1970 70 1970 01970 01970 1970 70 1970 1970 01970 -1996 96 1996 01996 01996 1996 96 1996 1996 01996 -2018 18 2018 02018 02018 2018 18 2018 2018 02018 -2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2100 00 2100 2100 02100 +1582-22-4 1582-22-04 1582-5-004 82 01582 0004 Thu Thu Thu Thursday +1970-1-3 1970-01-03 1970-5-003 70 01970 0003 Wed Wed Wed Wednesday +1970-53-4 1970-53-04 1970-5-004 70 01970 0004 Thu Thu Thu Thursday +1996-13-7 1996-13-07 1996-4-007 96 01996 0007 Sun Sun Sun Sunday +2018-46-6 2018-46-06 2018-3-006 18 02018 0006 Sat Sat Sat Saturday +2020-1-2 2020-01-02 2020-5-002 20 02020 0002 Tue Tue Tue Tuesday +2099-53-5 2099-53-05 2099-0-005 99 02099 0005 Fri Fri Fri Friday -- !query @@ -1037,45 +1037,17 @@ Illegal pattern character 'q' -- !query -select date_format(t, 'M MM MMM MMMM L LL') from ttt +select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt -- !query schema -struct +struct -- !query output -1 01 Jan January 1 01 -11 11 Nov November 11 11 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -3 03 Mar March 3 03 -5 05 May May 5 05 - - --- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt --- !query schema -struct --- !query output -0 53 1 01 001 5 05 005 0005 1 Fri Fri Fri Friday AM -3 46 17 17 321 6 06 006 0006 3 Sat Sat Sat Saturday AM -4 13 31 31 091 7 07 007 0007 5 Sun Sun Sun Sunday AM -5 01 31 31 365 2 02 002 0002 5 Tue Tue Tue Tuesday AM -5 01 31 31 365 3 03 003 0003 5 Wed Wed Wed Wednesday PM -5 22 31 31 151 4 04 004 0004 5 Thu Thu Thu Thursday PM -5 53 31 31 365 4 04 004 0004 5 Thu Thu Thu Thursday AM - - --- !query -select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt --- !query schema -struct --- !query output -1 01 1 01 1 01 1 01 33 33 33 33 123 -3 03 15 15 15 15 3 03 0 00 0 00 000 -4 04 4 04 4 04 4 04 59 59 59 59 999 -5 05 5 05 5 05 5 05 33 33 33 33 123 -7 07 19 19 19 19 7 07 40 40 35 35 123 -7 07 7 07 7 07 7 07 3 03 33 33 123 -9 09 9 09 9 09 9 09 33 33 33 33 123 +1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 5 7 07 19 19 7 07 PM +1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 5 3 03 15 15 3 03 PM +1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 5 4 04 4 04 4 04 AM +1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 5 7 07 7 07 7 07 AM +2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 5 9 09 9 09 9 09 AM +2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM -- !query @@ -1088,8 +1060,8 @@ Illegal pattern character 'V' -- !query -select date_format(date '1970-01-01', 'D DD') +select date_format(date '1970-01-01', 'D DD DDD') -- !query schema -struct +struct -- !query output -1 01 +1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out index 629a9d1b0f85f..412f310661cab 100755 --- a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 129 +-- Number of queries: 127 -- !query @@ -1031,17 +1031,17 @@ struct<> -- !query -select date_format(t, 'Y YY YYYY YYYYY YYYYY y yy yyy yyyy yyyyy') from ttt +select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt -- !query schema -struct +struct -- !query output -1582 82 1582 01582 01582 1582 82 1582 1582 01582 -1970 70 1970 01970 01970 1969 69 1969 1969 01969 -1970 70 1970 01970 01970 1970 70 1970 1970 01970 -1996 96 1996 01996 01996 1996 96 1996 1996 01996 -2018 18 2018 02018 02018 2018 18 2018 2018 02018 -2020 20 2020 02020 02020 2019 19 2019 2019 02019 -2099 99 2099 02099 02099 2100 00 2100 2100 02100 +1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday +1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday +1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday +1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday +2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday +2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday +2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday -- !query @@ -1059,45 +1059,17 @@ struct -- !query -select date_format(t, 'M MM MMM MMMM L LL') from ttt +select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt -- !query schema -struct +struct -- !query output -1 01 Jan January 1 01 -11 11 Nov November 11 11 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -12 12 Dec December 12 12 -3 03 Mar March 3 03 -5 05 May May 5 05 - - --- !query -select date_format(t, 'W ww d dd DDD u uu uuu uuuu F E EE EEE EEEE a') from ttt --- !query schema -struct --- !query output -0 53 1 01 001 5 05 Fri Friday 1 Fri Fri Fri Friday AM -3 46 17 17 321 6 06 Sat Saturday 3 Sat Sat Sat Saturday AM -4 13 31 31 091 7 07 Sun Sunday 3 Sun Sun Sun Sunday AM -5 01 31 31 365 2 02 Tue Tuesday 3 Tue Tue Tue Tuesday AM -5 01 31 31 365 3 03 Wed Wednesday 3 Wed Wed Wed Wednesday PM -5 22 31 31 151 1 01 Mon Monday 3 Mon Mon Mon Monday PM -5 53 31 31 365 4 04 Thu Thursday 3 Thu Thu Thu Thursday AM - - --- !query -select date_format(t, 'h hh H HH k kk K KK m mm s ss SSS') from ttt --- !query schema -struct --- !query output -1 01 1 01 1 01 1 01 33 33 33 33 123 -3 03 15 15 15 15 3 03 0 00 0 00 000 -4 04 4 04 4 04 4 04 59 59 59 59 999 -5 05 5 05 5 05 5 05 33 33 33 33 123 -7 07 19 19 19 19 7 07 40 40 35 35 123 -7 07 7 07 7 07 7 07 3 03 33 33 123 -9 09 9 09 9 09 9 09 33 33 33 33 123 +1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM +1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM +1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM +1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM +2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM +2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM -- !query @@ -1115,8 +1087,8 @@ America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -- !query -select date_format(date '1970-01-01', 'D DD') +select date_format(date '1970-01-01', 'D DD DDD') -- !query schema -struct +struct -- !query output -1 01 +1 01 001 From 34aef7957c2daa6f2577c59b1a8088d2942e49b3 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 21:50:47 +0800 Subject: [PATCH 05/10] refine --- .../util/DateTimeFormatterHelperSuite.scala | 50 +++++----- .../inputs/datetime-formatting-legacy.sql | 2 + .../sql-tests/inputs/datetime-formatting.sql | 19 ++++ .../resources/sql-tests/inputs/datetime.sql | 15 --- .../sql-tests/results/ansi/datetime.sql.out | 81 +--------------- .../datetime-formatting-legacy.sql.out | 85 +++++++++++++++++ .../results/datetime-formatting.sql.out | 95 +++++++++++++++++++ .../sql-tests/results/datetime-legacy.sql.out | 71 +------------- .../sql-tests/results/datetime.sql.out | 81 +--------------- 9 files changed, 228 insertions(+), 271 deletions(-) create mode 100644 sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-legacy.sql create mode 100644 sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql create mode 100644 sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out create mode 100644 sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala index 2a9f0ac50c70f..5b3c21a15c0fc 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelperSuite.scala @@ -22,50 +22,48 @@ import org.apache.spark.sql.catalyst.util.DateTimeFormatterHelper._ class DateTimeFormatterHelperSuite extends SparkFunSuite { + private def convertIncompatiblePattern(pattern: String): String = { + DateTimeFormatterHelper.convertIncompatiblePattern(pattern, isParsing = false) + } + test("check incompatible pattern") { - assert(convertIncompatiblePattern("MM-DD-u", isParsing = false) === "MM-DD-e") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz", isParsing = false) === - "uuuu-MM-dd'T'HH:mm:ss.SSSz") - assert(convertIncompatiblePattern( - "yyyy-MM'y contains in quoted text'HH:mm:ss", isParsing = false) === - "uuuu-MM'y contains in quoted text'HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd-u'T'HH:mm:ss.SSSz", isParsing = false) + assert(convertIncompatiblePattern("MM-DD-u") === "MM-DD-e") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz") + === "uuuu-MM-dd'T'HH:mm:ss.SSSz") + assert(convertIncompatiblePattern("yyyy-MM'y contains in quoted text'HH:mm:ss") + === "uuuu-MM'y contains in quoted text'HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd-u'T'HH:mm:ss.SSSz") === "uuuu-MM-dd-e'T'HH:mm:ss.SSSz") - assert( - convertIncompatiblePattern("yyyy-MM'u contains in quoted text'HH:mm:ss", isParsing = false) + assert(convertIncompatiblePattern("yyyy-MM'u contains in quoted text'HH:mm:ss") === "uuuu-MM'u contains in quoted text'HH:mm:ss") - assert(convertIncompatiblePattern( - "yyyy-MM'u contains in quoted text'''''HH:mm:ss", isParsing = false) === - "uuuu-MM'u contains in quoted text'''''HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz G", isParsing = false) === - "yyyy-MM-dd'T'HH:mm:ss.SSSz G") + assert(convertIncompatiblePattern("yyyy-MM'u contains in quoted text'''''HH:mm:ss") + === "uuuu-MM'u contains in quoted text'''''HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'HH:mm:ss.SSSz G") + === "yyyy-MM-dd'T'HH:mm:ss.SSSz G") unsupportedLetters.foreach { l => - val e = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"yyyy-MM-dd $l G", isParsing = false) - } + val e = intercept[IllegalArgumentException](convertIncompatiblePattern(s"yyyy-MM-dd $l G")) assert(e.getMessage === s"Illegal pattern character: $l") } unsupportedLettersForParsing.foreach { l => val e = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"$l", isParsing = true) + DateTimeFormatterHelper.convertIncompatiblePattern(s"$l", isParsing = true) } assert(e.getMessage === s"Illegal pattern character: $l") - assert(convertIncompatiblePattern(s"$l", isParsing = false).nonEmpty) + assert(convertIncompatiblePattern(s"$l").nonEmpty) } unsupportedPatternLengths.foreach { style => val e1 = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"yyyy-MM-dd $style", isParsing = false) + convertIncompatiblePattern(s"yyyy-MM-dd $style") } assert(e1.getMessage === s"Too many pattern letters: ${style.head}") val e2 = intercept[IllegalArgumentException] { - convertIncompatiblePattern(s"yyyy-MM-dd $style${style.head}", isParsing = false) + convertIncompatiblePattern(s"yyyy-MM-dd $style${style.head}") } assert(e2.getMessage === s"Too many pattern letters: ${style.head}") } - assert(convertIncompatiblePattern("yyyy-MM-dd uuuu", isParsing = false) === "uuuu-MM-dd eeee") - assert(convertIncompatiblePattern("yyyy-MM-dd EEEE", isParsing = false) === "uuuu-MM-dd EEEE") - assert(convertIncompatiblePattern("yyyy-MM-dd'e'HH:mm:ss", isParsing = false) === - "uuuu-MM-dd'e'HH:mm:ss") - assert(convertIncompatiblePattern("yyyy-MM-dd'T'", isParsing = false) === "uuuu-MM-dd'T'") + assert(convertIncompatiblePattern("yyyy-MM-dd uuuu") === "uuuu-MM-dd eeee") + assert(convertIncompatiblePattern("yyyy-MM-dd EEEE") === "uuuu-MM-dd EEEE") + assert(convertIncompatiblePattern("yyyy-MM-dd'e'HH:mm:ss") === "uuuu-MM-dd'e'HH:mm:ss") + assert(convertIncompatiblePattern("yyyy-MM-dd'T'") === "uuuu-MM-dd'T'") } } diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-legacy.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-legacy.sql new file mode 100644 index 0000000000000..b4f74810935af --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-legacy.sql @@ -0,0 +1,2 @@ +--SET spark.sql.legacy.timeParserPolicy=LEGACY +--IMPORT datetime-formatting.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql new file mode 100644 index 0000000000000..163b59fb1b82b --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql @@ -0,0 +1,19 @@ +--- TESTS FOR DATETIME FORMATTING FUNCTIONS --- + +-- valid formatter pattern check +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t); + +select t, date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt; +select t, date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt; +select t, date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt; +select t, date_format(t, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from ttt; +-- These patterns for time zone is unsupported by the legacy formatter +select t, date_format(t, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from ttt; +select date_format(date '1970-01-01', 'D DD DDD'); diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql index 2ab99ef085d92..5636e0b670362 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime.sql @@ -168,18 +168,3 @@ select date_format(date '2018-11-17', 'yyyyyyyyyyy-MM-dd'); -- SPARK-31879: the first day of week select date_format('2020-01-01', 'YYYY-MM-dd uu'); select date_format('2020-01-01', 'YYYY-MM-dd uuuu'); - --- valid formatter pattern check -create temporary view ttt as select t from VALUES - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t); -select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt; -select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt; -select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt; -select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt; -select date_format(date '1970-01-01', 'D DD DDD'); diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out index 5a7bb3d321cdc..3803460f3f083 100644 --- a/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/ansi/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 127 +-- Number of queries: 121 -- !query @@ -1041,82 +1041,3 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 Wednesday - - --- !query -create temporary view ttt as select t from VALUES - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) --- !query schema -struct<> --- !query output - - - --- !query -select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt --- !query schema -struct --- !query output -1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday -1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday -1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday -1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday -2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday -2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday -2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday - - --- !query -select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt --- !query schema -struct --- !query output -1 01 1 01 Q1 1st quarter -1 01 1 01 Q1 1st quarter -2 02 2 02 Q2 2nd quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter - - --- !query -select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt --- !query schema -struct --- !query output -1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM -1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM -1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM -1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM -2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM -2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM -2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM - - --- !query -select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt --- !query schema -struct --- !query output -America/Los_Angeles PST PST PST Pacific Standard Time GMT-7:52:58 GMT-07:52:58 -0752 -0752 -07:52 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 - - --- !query -select date_format(date '1970-01-01', 'D DD DDD') --- !query schema -struct --- !query output -1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out new file mode 100644 index 0000000000000..893f967b96407 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out @@ -0,0 +1,85 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 7 + + +-- !query +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) +-- !query schema +struct<> +-- !query output + + + +-- !query +select t, date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582-22-4 1582-22-04 1582-5-004 82 01582 0004 Thu Thu Thu Thursday +1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-003 70 01970 0003 Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-004 70 01970 0004 Thu Thu Thu Thursday +1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-007 96 01996 0007 Sun Sun Sun Sunday +2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-006 18 02018 0006 Sat Sat Sat Saturday +2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-002 20 02020 0002 Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-005 99 02099 0005 Fri Fri Fri Friday + + +-- !query +select t, date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'q' + + +-- !query +select t, date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 5 7 07 19 19 7 07 PM +1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 5 3 03 15 15 3 03 PM +1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 5 4 04 4 04 4 04 AM +1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 5 7 07 7 07 7 07 AM +2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 5 9 09 9 09 9 09 AM +2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM + + +-- !query +select t, date_format(t, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 + + +-- !query +select t, date_format(t, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from ttt +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'V' + + +-- !query +select date_format(date '1970-01-01', 'D DD DDD') +-- !query schema +struct +-- !query output +1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out new file mode 100644 index 0000000000000..67ae9cc4e4598 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out @@ -0,0 +1,95 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 7 + + +-- !query +create temporary view ttt as select t from VALUES + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) +-- !query schema +struct<> +-- !query output + + + +-- !query +select t, date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday +1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday +1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday +2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday +2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday + + +-- !query +select t, date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 2 02 2 02 Q2 2nd quarter +1969-12-31 15:00:00 4 04 4 04 Q4 4th quarter +1970-12-31 04:59:59.999 4 04 4 04 Q4 4th quarter +1996-03-31 07:03:33.123 1 01 1 01 Q1 1st quarter +2018-11-17 05:33:33.123 4 04 4 04 Q4 4th quarter +2019-12-31 09:33:33.123 4 04 4 04 Q4 4th quarter +2100-01-01 01:33:33.123 1 01 1 01 Q1 1st quarter + + +-- !query +select t, date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM +1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM +1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM +1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM +2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM +2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM + + +-- !query +select t, date_format(t, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -0752 -0752 -07:52 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 +1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 + + +-- !query +select t, date_format(t, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from ttt +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 America/Los_Angeles GMT-7:52:58 GMT-07:52:58 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 +1969-12-31 15:00:00 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1970-12-31 04:59:59.999 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1996-03-31 07:03:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2018-11-17 05:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2019-12-31 09:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2100-01-01 01:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 + + +-- !query +select date_format(date '1970-01-01', 'D DD DDD') +-- !query schema +struct +-- !query output +1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out index 26fb39a05952b..99dd14d21e6fd 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-legacy.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 127 +-- Number of queries: 121 -- !query @@ -996,72 +996,3 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 0003 - - --- !query -create temporary view ttt as select t from VALUES - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) --- !query schema -struct<> --- !query output - - - --- !query -select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt --- !query schema -struct --- !query output -1582-22-4 1582-22-04 1582-5-004 82 01582 0004 Thu Thu Thu Thursday -1970-1-3 1970-01-03 1970-5-003 70 01970 0003 Wed Wed Wed Wednesday -1970-53-4 1970-53-04 1970-5-004 70 01970 0004 Thu Thu Thu Thursday -1996-13-7 1996-13-07 1996-4-007 96 01996 0007 Sun Sun Sun Sunday -2018-46-6 2018-46-06 2018-3-006 18 02018 0006 Sat Sat Sat Saturday -2020-1-2 2020-01-02 2020-5-002 20 02020 0002 Tue Tue Tue Tuesday -2099-53-5 2099-53-05 2099-0-005 99 02099 0005 Fri Fri Fri Friday - - --- !query -select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'q' - - --- !query -select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt --- !query schema -struct --- !query output -1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 5 7 07 19 19 7 07 PM -1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 5 3 03 15 15 3 03 PM -1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 5 4 04 4 04 4 04 AM -1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 5 7 07 7 07 7 07 AM -2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM -2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 5 9 09 9 09 9 09 AM -2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM - - --- !query -select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'V' - - --- !query -select date_format(date '1970-01-01', 'D DD DDD') --- !query schema -struct --- !query output -1 01 001 diff --git a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out index 412f310661cab..c8c568c736d76 100755 --- a/sql/core/src/test/resources/sql-tests/results/datetime.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 127 +-- Number of queries: 121 -- !query @@ -1013,82 +1013,3 @@ select date_format('2020-01-01', 'YYYY-MM-dd uuuu') struct -- !query output 2020-01-01 Wednesday - - --- !query -create temporary view ttt as select t from VALUES - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') tt(t) --- !query schema -struct<> --- !query output - - - --- !query -select date_format(t, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from ttt --- !query schema -struct --- !query output -1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday -1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday -1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday -1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday -2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday -2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday -2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday - - --- !query -select date_format(t, 'q qq Q QQ QQQ QQQQ') from ttt --- !query schema -struct --- !query output -1 01 1 01 Q1 1st quarter -1 01 1 01 Q1 1st quarter -2 02 2 02 Q2 2nd quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter -4 04 4 04 Q4 4th quarter - - --- !query -select date_format(t, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from ttt --- !query schema -struct --- !query output -1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM -1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM -1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM -1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM -2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM -2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM -2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM - - --- !query -select date_format(t, 'VV z zz zzz zzzz O OOOO X XX XXX XXXX XXXXX x xx xxx xxxx xxxx xxxxx Z ZZ ZZZ ZZZZ ZZZZZ') from ttt --- !query schema -struct --- !query output -America/Los_Angeles PST PST PST Pacific Standard Time GMT-7:52:58 GMT-07:52:58 -0752 -0752 -07:52 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -America/Los_Angeles PST PST PST Pacific Standard Time GMT-8 GMT-08:00 -08 -0800 -08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 - - --- !query -select date_format(date '1970-01-01', 'D DD DDD') --- !query schema -struct --- !query output -1 01 001 From 1e78a4eb98211cc28ec52abfec84df0ba7fc7b04 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 3 Jun 2020 22:20:12 +0800 Subject: [PATCH 06/10] fix tests --- .../sql-tests/inputs/datetime-formatting.sql | 2 +- .../datetime-formatting-legacy.sql.out | 46 +++++++++----- .../results/datetime-formatting.sql.out | 60 +++++++++++++------ 3 files changed, 73 insertions(+), 35 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql index 27b84bacb5186..527d09d7db7ee 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql @@ -1,7 +1,7 @@ --- TESTS FOR DATETIME FORMATTING FUNCTIONS --- -- valid formatter pattern check -create temporary view v as select t from values +create temporary view v as select col from values (timestamp '1582-06-01 11:33:33.123UTC+080000'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out index 3a80d8dad9258..f8ade794884a9 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out @@ -3,7 +3,7 @@ -- !query -create temporary view v as select t from values +create temporary view v as select col from values (timestamp '1582-06-01 11:33:33.123UTC+080000'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), @@ -14,17 +14,21 @@ create temporary view v as select t from values -- !query schema struct<> -- !query output -org.apache.spark.sql.AnalysisException -cannot resolve '`t`' given input columns: [t.col]; line 1 pos 34 + -- !query select col, date_format(col, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 92 +1582-05-31 19:40:35.123 1582-22-4 1582-22-04 1582-5-004 82 01582 0004 Thu Thu Thu Thursday +1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-003 70 01970 0003 Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-004 70 01970 0004 Thu Thu Thu Thursday +1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-007 96 01996 0007 Sun Sun Sun Sunday +2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-006 18 02018 0006 Sat Sat Sat Saturday +2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-002 20 02020 0002 Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-005 99 02099 0005 Fri Fri Fri Friday -- !query @@ -32,26 +36,36 @@ select col, date_format(col, 'q qq Q QQ QQQ QQQQ') from v -- !query schema struct<> -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 56 +java.lang.IllegalArgumentException +Illegal pattern character 'q' -- !query select col, date_format(col, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 119 +1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 5 7 07 19 19 7 07 PM +1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 5 3 03 15 15 3 03 PM +1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 5 4 04 4 04 4 04 AM +1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 5 7 07 7 07 7 07 AM +2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 5 9 09 9 09 9 09 AM +2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM -- !query select col, date_format(col, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 81 +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -- !query @@ -59,8 +73,8 @@ select col, date_format(col, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') fr -- !query schema struct<> -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 83 +java.lang.IllegalArgumentException +Illegal pattern character 'V' -- !query diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out index 3a80d8dad9258..89c97ebe7e3c4 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out @@ -3,7 +3,7 @@ -- !query -create temporary view v as select t from values +create temporary view v as select col from values (timestamp '1582-06-01 11:33:33.123UTC+080000'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), @@ -14,53 +14,77 @@ create temporary view v as select t from values -- !query schema struct<> -- !query output -org.apache.spark.sql.AnalysisException -cannot resolve '`t`' given input columns: [t.col]; line 1 pos 34 + -- !query select col, date_format(col, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 92 +1582-05-31 19:40:35.123 1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday +1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday +1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday +2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday +2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday -- !query select col, date_format(col, 'q qq Q QQ QQQ QQQQ') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 56 +1582-05-31 19:40:35.123 2 02 2 02 Q2 2nd quarter +1969-12-31 15:00:00 4 04 4 04 Q4 4th quarter +1970-12-31 04:59:59.999 4 04 4 04 Q4 4th quarter +1996-03-31 07:03:33.123 1 01 1 01 Q1 1st quarter +2018-11-17 05:33:33.123 4 04 4 04 Q4 4th quarter +2019-12-31 09:33:33.123 4 04 4 04 Q4 4th quarter +2100-01-01 01:33:33.123 1 01 1 01 Q1 1st quarter -- !query select col, date_format(col, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 119 +1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM +1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM +1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM +1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM +2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM +2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM +2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM -- !query select col, date_format(col, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 81 +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -0752 -0752 -07:52 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 +1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -- !query select col, date_format(col, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from v -- !query schema -struct<> +struct -- !query output -org.apache.spark.sql.AnalysisException -Table or view not found: v; line 1 pos 83 +1582-05-31 19:40:35.123 America/Los_Angeles GMT-7:52:58 GMT-07:52:58 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 +1969-12-31 15:00:00 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1970-12-31 04:59:59.999 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1996-03-31 07:03:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2018-11-17 05:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2019-12-31 09:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +2100-01-01 01:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -- !query From 83499a19513462a21cbaf8b9e35f35cc9577afc2 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 4 Jun 2020 00:03:42 +0800 Subject: [PATCH 07/10] new tests --- .../sql-tests/inputs/datetime-formatting.sql | 91 ++- .../datetime-formatting-legacy.sql.out | 758 +++++++++++++++++- .../results/datetime-formatting.sql.out | 695 ++++++++++++++-- 3 files changed, 1454 insertions(+), 90 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql index 527d09d7db7ee..03cf9b80bb5f1 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql @@ -1,6 +1,5 @@ --- TESTS FOR DATETIME FORMATTING FUNCTIONS --- --- valid formatter pattern check create temporary view v as select col from values (timestamp '1582-06-01 11:33:33.123UTC+080000'), (timestamp '1970-01-01 00:00:00.000Europe/Paris'), @@ -10,10 +9,86 @@ create temporary view v as select col from values (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col); -select col, date_format(col, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from v; -select col, date_format(col, 'q qq Q QQ QQQ QQQQ') from v; -select col, date_format(col, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from v; -select col, date_format(col, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from v; --- These patterns for time zone is unsupported by the legacy formatter -select col, date_format(col, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from v; -select date_format(date '1970-01-01', 'D DD DDD'); +--------------------------- '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890' +select col, date_format(col, 'G GG GGG GGGG') from v; +select col, date_format(col, 'GGGGG') from v; + +select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v; +select col, date_format(col, 'yyyyyyyyyyy') from v; + +select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v; +select col, date_format(col, 'YYYYYYYYYYY') from v; + +select col, date_format(col, 'q qq') from v; +select col, date_format(col, 'qqq') from v; + +select col, date_format(col, 'Q QQ QQQ QQQQ') from v; +select col, date_format(col, 'QQQQQ') from v; + +select col, date_format(col, 'M MM MMM MMMM') from v; +select col, date_format(col, 'MMMMM') from v; + +select col, date_format(col, 'L LL') from v; +select col, date_format(col, 'LLL') from v; + +select col, date_format(col, 'w ww') from v; +select col, date_format(col, 'www') from v; + +select col, date_format(col, 'W') from v; +select col, date_format(col, 'WW') from v; + +select col, date_format(col, 'u uu uuu uuuu') from v; +select col, date_format(col, 'uuuuu') from v; + +select col, date_format(col, 'E EE EEE EEEE') from v; +select col, date_format(col, 'EEEEE') from v; + +select col, date_format(col, 'F') from v; +select col, date_format(col, 'FF') from v; + +select col, date_format(col, 'd dd') from v; +select col, date_format(col, 'ddd') from v; + +select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles'; +select col, date_format(col, 'DD') from v; +select col, date_format(col, 'D DDD') from v; +select col, date_format(col, 'DDDD') from v; + +select col, date_format(col, 'H HH') from v; +select col, date_format(col, 'HHH') from v; + +select col, date_format(col, 'h hh') from v; +select col, date_format(col, 'hhh') from v; + +select col, date_format(col, 'k kk') from v; +select col, date_format(col, 'kkk') from v; + +select col, date_format(col, 'K KK') from v; +select col, date_format(col, 'KKK') from v; + +select col, date_format(col, 'm mm') from v; +select col, date_format(col, 'mmm') from v; + +select col, date_format(col, 's ss') from v; +select col, date_format(col, 'sss') from v; + +select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v; +select col, date_format(col, 'SSSSSSSSSS') from v; + +select col, date_format(col, 'a') from v; +select col, date_format(col, 'aa') from v; + +select col, date_format(col, 'VV') from v; +select col, date_format(col, 'V') from v; + +select col, date_format(col, 'z zz zzz zzzz') from v; +select col, date_format(col, 'zzzzz') from v; +select col, date_format(col, 'X XX XXX') from v; +select col, date_format(col, 'XXXX XXXXX') from v; +select col, date_format(col, 'XXXXXX') from v; +select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v; +select col, date_format(col, 'ZZZZZZ') from v; +select col, date_format(col, 'O OOOO') from v; +select col, date_format(col, 'OO') from v; +select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v; +select col, date_format(col, 'xxxxxx') from v; diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out index f8ade794884a9..67d439f05ea08 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 7 +-- Number of queries: 60 -- !query @@ -18,21 +18,91 @@ struct<> -- !query -select col, date_format(col, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from v +select col, date_format(col, 'G GG GGG GGGG') from v -- !query schema -struct +struct -- !query output -1582-05-31 19:40:35.123 1582-22-4 1582-22-04 1582-5-004 82 01582 0004 Thu Thu Thu Thursday -1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-003 70 01970 0003 Wed Wed Wed Wednesday -1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-004 70 01970 0004 Thu Thu Thu Thursday -1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-007 96 01996 0007 Sun Sun Sun Sunday -2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-006 18 02018 0006 Sat Sat Sat Saturday -2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-002 20 02020 0002 Tue Tue Tue Tuesday -2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-005 99 02099 0005 Fri Fri Fri Friday +1582-05-31 19:40:35.123 AD AD AD AD +1969-12-31 15:00:00 AD AD AD AD +1970-12-31 04:59:59.999 AD AD AD AD +1996-03-31 07:03:33.123 AD AD AD AD +2018-11-17 05:33:33.123 AD AD AD AD +2019-12-31 09:33:33.123 AD AD AD AD +2100-01-01 01:33:33.123 AD AD AD AD -- !query -select col, date_format(col, 'q qq Q QQ QQQ QQQQ') from v +select col, date_format(col, 'GGGGG') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 AD +1969-12-31 15:00:00 AD +1970-12-31 04:59:59.999 AD +1996-03-31 07:03:33.123 AD +2018-11-17 05:33:33.123 AD +2019-12-31 09:33:33.123 AD +2100-01-01 01:33:33.123 AD + + +-- !query +select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582 82 1582 1582 01582 001582 0001582 00001582 000001582 0000001582 +1969-12-31 15:00:00 1969 69 1969 1969 01969 001969 0001969 00001969 000001969 0000001969 +1970-12-31 04:59:59.999 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1996-03-31 07:03:33.123 1996 96 1996 1996 01996 001996 0001996 00001996 000001996 0000001996 +2018-11-17 05:33:33.123 2018 18 2018 2018 02018 002018 0002018 00002018 000002018 0000002018 +2019-12-31 09:33:33.123 2019 19 2019 2019 02019 002019 0002019 00002019 000002019 0000002019 +2100-01-01 01:33:33.123 2100 00 2100 2100 02100 002100 0002100 00002100 000002100 0000002100 + + +-- !query +select col, date_format(col, 'yyyyyyyyyyy') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 00000001582 +1969-12-31 15:00:00 00000001969 +1970-12-31 04:59:59.999 00000001970 +1996-03-31 07:03:33.123 00000001996 +2018-11-17 05:33:33.123 00000002018 +2019-12-31 09:33:33.123 00000002019 +2100-01-01 01:33:33.123 00000002100 + + +-- !query +select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582 82 1582 1582 01582 001582 0001582 00001582 000001582 0000001582 +1969-12-31 15:00:00 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1970-12-31 04:59:59.999 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1996-03-31 07:03:33.123 1996 96 1996 1996 01996 001996 0001996 00001996 000001996 0000001996 +2018-11-17 05:33:33.123 2018 18 2018 2018 02018 002018 0002018 00002018 000002018 0000002018 +2019-12-31 09:33:33.123 2020 20 2020 2020 02020 002020 0002020 00002020 000002020 0000002020 +2100-01-01 01:33:33.123 2099 99 2099 2099 02099 002099 0002099 00002099 000002099 0000002099 + + +-- !query +select col, date_format(col, 'YYYYYYYYYYY') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 00000001582 +1969-12-31 15:00:00 00000001970 +1970-12-31 04:59:59.999 00000001970 +1996-03-31 07:03:33.123 00000001996 +2018-11-17 05:33:33.123 00000002018 +2019-12-31 09:33:33.123 00000002020 +2100-01-01 01:33:33.123 00000002099 + + +-- !query +select col, date_format(col, 'q qq') from v -- !query schema struct<> -- !query output @@ -41,35 +111,541 @@ Illegal pattern character 'q' -- !query -select col, date_format(col, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from v +select col, date_format(col, 'qqq') from v -- !query schema -struct +struct<> -- !query output -1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 5 7 07 19 19 7 07 PM -1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 5 3 03 15 15 3 03 PM -1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 5 4 04 4 04 4 04 AM -1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 5 7 07 7 07 7 07 AM -2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM -2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 5 9 09 9 09 9 09 AM -2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM +java.lang.IllegalArgumentException +Illegal pattern character 'q' -- !query -select col, date_format(col, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from v +select col, date_format(col, 'Q QQ QQQ QQQQ') from v -- !query schema -struct +struct<> -- !query output -1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 -2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 -0800 -0800 +java.lang.IllegalArgumentException +Illegal pattern character 'Q' -- !query -select col, date_format(col, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from v +select col, date_format(col, 'QQQQQ') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'Q' + + +-- !query +select col, date_format(col, 'M MM MMM MMMM') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 05 May May +1969-12-31 15:00:00 12 12 Dec December +1970-12-31 04:59:59.999 12 12 Dec December +1996-03-31 07:03:33.123 3 03 Mar March +2018-11-17 05:33:33.123 11 11 Nov November +2019-12-31 09:33:33.123 12 12 Dec December +2100-01-01 01:33:33.123 1 01 Jan January + + +-- !query +select col, date_format(col, 'MMMMM') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 May +1969-12-31 15:00:00 December +1970-12-31 04:59:59.999 December +1996-03-31 07:03:33.123 March +2018-11-17 05:33:33.123 November +2019-12-31 09:33:33.123 December +2100-01-01 01:33:33.123 January + + +-- !query +select col, date_format(col, 'L LL') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 05 +1969-12-31 15:00:00 12 12 +1970-12-31 04:59:59.999 12 12 +1996-03-31 07:03:33.123 3 03 +2018-11-17 05:33:33.123 11 11 +2019-12-31 09:33:33.123 12 12 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'LLL') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 May +1969-12-31 15:00:00 Dec +1970-12-31 04:59:59.999 Dec +1996-03-31 07:03:33.123 Mar +2018-11-17 05:33:33.123 Nov +2019-12-31 09:33:33.123 Dec +2100-01-01 01:33:33.123 Jan + + +-- !query +select col, date_format(col, 'w ww') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 22 22 +1969-12-31 15:00:00 1 01 +1970-12-31 04:59:59.999 53 53 +1996-03-31 07:03:33.123 13 13 +2018-11-17 05:33:33.123 46 46 +2019-12-31 09:33:33.123 1 01 +2100-01-01 01:33:33.123 53 53 + + +-- !query +select col, date_format(col, 'www') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 022 +1969-12-31 15:00:00 001 +1970-12-31 04:59:59.999 053 +1996-03-31 07:03:33.123 013 +2018-11-17 05:33:33.123 046 +2019-12-31 09:33:33.123 001 +2100-01-01 01:33:33.123 053 + + +-- !query +select col, date_format(col, 'W') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 +1969-12-31 15:00:00 5 +1970-12-31 04:59:59.999 5 +1996-03-31 07:03:33.123 4 +2018-11-17 05:33:33.123 3 +2019-12-31 09:33:33.123 5 +2100-01-01 01:33:33.123 0 + + +-- !query +select col, date_format(col, 'WW') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 05 +1969-12-31 15:00:00 05 +1970-12-31 04:59:59.999 05 +1996-03-31 07:03:33.123 04 +2018-11-17 05:33:33.123 03 +2019-12-31 09:33:33.123 05 +2100-01-01 01:33:33.123 00 + + +-- !query +select col, date_format(col, 'u uu uuu uuuu') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 4 04 004 0004 +1969-12-31 15:00:00 3 03 003 0003 +1970-12-31 04:59:59.999 4 04 004 0004 +1996-03-31 07:03:33.123 7 07 007 0007 +2018-11-17 05:33:33.123 6 06 006 0006 +2019-12-31 09:33:33.123 2 02 002 0002 +2100-01-01 01:33:33.123 5 05 005 0005 + + +-- !query +select col, date_format(col, 'uuuuu') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 00004 +1969-12-31 15:00:00 00003 +1970-12-31 04:59:59.999 00004 +1996-03-31 07:03:33.123 00007 +2018-11-17 05:33:33.123 00006 +2019-12-31 09:33:33.123 00002 +2100-01-01 01:33:33.123 00005 + + +-- !query +select col, date_format(col, 'E EE EEE EEEE') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 Thu Thu Thu Thursday +1969-12-31 15:00:00 Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 Thu Thu Thu Thursday +1996-03-31 07:03:33.123 Sun Sun Sun Sunday +2018-11-17 05:33:33.123 Sat Sat Sat Saturday +2019-12-31 09:33:33.123 Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 Fri Fri Fri Friday + + +-- !query +select col, date_format(col, 'EEEEE') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 Thursday +1969-12-31 15:00:00 Wednesday +1970-12-31 04:59:59.999 Thursday +1996-03-31 07:03:33.123 Sunday +2018-11-17 05:33:33.123 Saturday +2019-12-31 09:33:33.123 Tuesday +2100-01-01 01:33:33.123 Friday + + +-- !query +select col, date_format(col, 'F') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 +1969-12-31 15:00:00 5 +1970-12-31 04:59:59.999 5 +1996-03-31 07:03:33.123 5 +2018-11-17 05:33:33.123 3 +2019-12-31 09:33:33.123 5 +2100-01-01 01:33:33.123 1 + + +-- !query +select col, date_format(col, 'FF') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 05 +1969-12-31 15:00:00 05 +1970-12-31 04:59:59.999 05 +1996-03-31 07:03:33.123 05 +2018-11-17 05:33:33.123 03 +2019-12-31 09:33:33.123 05 +2100-01-01 01:33:33.123 01 + + +-- !query +select col, date_format(col, 'd dd') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 31 31 +1969-12-31 15:00:00 31 31 +1970-12-31 04:59:59.999 31 31 +1996-03-31 07:03:33.123 31 31 +2018-11-17 05:33:33.123 17 17 +2019-12-31 09:33:33.123 31 31 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'ddd') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 031 +1969-12-31 15:00:00 031 +1970-12-31 04:59:59.999 031 +1996-03-31 07:03:33.123 031 +2018-11-17 05:33:33.123 017 +2019-12-31 09:33:33.123 031 +2100-01-01 01:33:33.123 001 + + +-- !query +select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles' +-- !query schema +struct +-- !query output +2100-01-01 01:33:33.123 01 + + +-- !query +select col, date_format(col, 'D DDD') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 151 151 +1969-12-31 15:00:00 365 365 +1970-12-31 04:59:59.999 365 365 +1996-03-31 07:03:33.123 91 091 +2018-11-17 05:33:33.123 321 321 +2019-12-31 09:33:33.123 365 365 +2100-01-01 01:33:33.123 1 001 + + +-- !query +select col, date_format(col, 'DD') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 151 +1969-12-31 15:00:00 365 +1970-12-31 04:59:59.999 365 +1996-03-31 07:03:33.123 91 +2018-11-17 05:33:33.123 321 +2019-12-31 09:33:33.123 365 +2100-01-01 01:33:33.123 01 + + +-- !query +select col, date_format(col, 'DDDD') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 0151 +1969-12-31 15:00:00 0365 +1970-12-31 04:59:59.999 0365 +1996-03-31 07:03:33.123 0091 +2018-11-17 05:33:33.123 0321 +2019-12-31 09:33:33.123 0365 +2100-01-01 01:33:33.123 0001 + + +-- !query +select col, date_format(col, 'H HH') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 19 19 +1969-12-31 15:00:00 15 15 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'HHH') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 019 +1969-12-31 15:00:00 015 +1970-12-31 04:59:59.999 004 +1996-03-31 07:03:33.123 007 +2018-11-17 05:33:33.123 005 +2019-12-31 09:33:33.123 009 +2100-01-01 01:33:33.123 001 + + +-- !query +select col, date_format(col, 'h hh') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 7 07 +1969-12-31 15:00:00 3 03 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'hhh') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 007 +1969-12-31 15:00:00 003 +1970-12-31 04:59:59.999 004 +1996-03-31 07:03:33.123 007 +2018-11-17 05:33:33.123 005 +2019-12-31 09:33:33.123 009 +2100-01-01 01:33:33.123 001 + + +-- !query +select col, date_format(col, 'k kk') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 19 19 +1969-12-31 15:00:00 15 15 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'kkk') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 019 +1969-12-31 15:00:00 015 +1970-12-31 04:59:59.999 004 +1996-03-31 07:03:33.123 007 +2018-11-17 05:33:33.123 005 +2019-12-31 09:33:33.123 009 +2100-01-01 01:33:33.123 001 + + +-- !query +select col, date_format(col, 'K KK') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 7 07 +1969-12-31 15:00:00 3 03 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'KKK') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 007 +1969-12-31 15:00:00 003 +1970-12-31 04:59:59.999 004 +1996-03-31 07:03:33.123 007 +2018-11-17 05:33:33.123 005 +2019-12-31 09:33:33.123 009 +2100-01-01 01:33:33.123 001 + + +-- !query +select col, date_format(col, 'm mm') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 40 40 +1969-12-31 15:00:00 0 00 +1970-12-31 04:59:59.999 59 59 +1996-03-31 07:03:33.123 3 03 +2018-11-17 05:33:33.123 33 33 +2019-12-31 09:33:33.123 33 33 +2100-01-01 01:33:33.123 33 33 + + +-- !query +select col, date_format(col, 'mmm') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 040 +1969-12-31 15:00:00 000 +1970-12-31 04:59:59.999 059 +1996-03-31 07:03:33.123 003 +2018-11-17 05:33:33.123 033 +2019-12-31 09:33:33.123 033 +2100-01-01 01:33:33.123 033 + + +-- !query +select col, date_format(col, 's ss') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 35 35 +1969-12-31 15:00:00 0 00 +1970-12-31 04:59:59.999 59 59 +1996-03-31 07:03:33.123 33 33 +2018-11-17 05:33:33.123 33 33 +2019-12-31 09:33:33.123 33 33 +2100-01-01 01:33:33.123 33 33 + + +-- !query +select col, date_format(col, 'sss') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 035 +1969-12-31 15:00:00 000 +1970-12-31 04:59:59.999 059 +1996-03-31 07:03:33.123 033 +2018-11-17 05:33:33.123 033 +2019-12-31 09:33:33.123 033 +2100-01-01 01:33:33.123 033 + + +-- !query +select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 123 123 123 0123 00123 000123 0000123 00000123 000000123 +1969-12-31 15:00:00 0 00 000 0000 00000 000000 0000000 00000000 000000000 +1970-12-31 04:59:59.999 999 999 999 0999 00999 000999 0000999 00000999 000000999 +1996-03-31 07:03:33.123 123 123 123 0123 00123 000123 0000123 00000123 000000123 +2018-11-17 05:33:33.123 123 123 123 0123 00123 000123 0000123 00000123 000000123 +2019-12-31 09:33:33.123 123 123 123 0123 00123 000123 0000123 00000123 000000123 +2100-01-01 01:33:33.123 123 123 123 0123 00123 000123 0000123 00000123 000000123 + + +-- !query +select col, date_format(col, 'SSSSSSSSSS') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 0000000123 +1969-12-31 15:00:00 0000000000 +1970-12-31 04:59:59.999 0000000999 +1996-03-31 07:03:33.123 0000000123 +2018-11-17 05:33:33.123 0000000123 +2019-12-31 09:33:33.123 0000000123 +2100-01-01 01:33:33.123 0000000123 + + +-- !query +select col, date_format(col, 'a') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PM +1969-12-31 15:00:00 PM +1970-12-31 04:59:59.999 AM +1996-03-31 07:03:33.123 AM +2018-11-17 05:33:33.123 AM +2019-12-31 09:33:33.123 AM +2100-01-01 01:33:33.123 AM + + +-- !query +select col, date_format(col, 'aa') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PM +1969-12-31 15:00:00 PM +1970-12-31 04:59:59.999 AM +1996-03-31 07:03:33.123 AM +2018-11-17 05:33:33.123 AM +2019-12-31 09:33:33.123 AM +2100-01-01 01:33:33.123 AM + + +-- !query +select col, date_format(col, 'VV') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'V' + + +-- !query +select col, date_format(col, 'V') from v -- !query schema struct<> -- !query output @@ -78,8 +654,124 @@ Illegal pattern character 'V' -- !query -select date_format(date '1970-01-01', 'D DD DDD') +select col, date_format(col, 'z zz zzz zzzz') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time +1969-12-31 15:00:00 PST PST PST Pacific Standard Time +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time + + +-- !query +select col, date_format(col, 'zzzzz') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 Pacific Standard Time +1969-12-31 15:00:00 Pacific Standard Time +1970-12-31 04:59:59.999 Pacific Standard Time +1996-03-31 07:03:33.123 Pacific Standard Time +2018-11-17 05:33:33.123 Pacific Standard Time +2019-12-31 09:33:33.123 Pacific Standard Time +2100-01-01 01:33:33.123 Pacific Standard Time + + +-- !query +select col, date_format(col, 'X XX XXX') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -08 -0800 -08:00 +1969-12-31 15:00:00 -08 -0800 -08:00 +1970-12-31 04:59:59.999 -08 -0800 -08:00 +1996-03-31 07:03:33.123 -08 -0800 -08:00 +2018-11-17 05:33:33.123 -08 -0800 -08:00 +2019-12-31 09:33:33.123 -08 -0800 -08:00 +2100-01-01 01:33:33.123 -08 -0800 -08:00 + + +-- !query +select col, date_format(col, 'XXXX XXXXX') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +invalid ISO 8601 format: length=4 + + +-- !query +select col, date_format(col, 'XXXXXX') from v -- !query schema -struct +struct<> -- !query output -1 01 001 +java.lang.IllegalArgumentException +invalid ISO 8601 format: length=6 + + +-- !query +select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -0800 -0800 -0800 -0800 -0800 +1969-12-31 15:00:00 -0800 -0800 -0800 -0800 -0800 +1970-12-31 04:59:59.999 -0800 -0800 -0800 -0800 -0800 +1996-03-31 07:03:33.123 -0800 -0800 -0800 -0800 -0800 +2018-11-17 05:33:33.123 -0800 -0800 -0800 -0800 -0800 +2019-12-31 09:33:33.123 -0800 -0800 -0800 -0800 -0800 +2100-01-01 01:33:33.123 -0800 -0800 -0800 -0800 -0800 + + +-- !query +select col, date_format(col, 'ZZZZZZ') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -0800 +1969-12-31 15:00:00 -0800 +1970-12-31 04:59:59.999 -0800 +1996-03-31 07:03:33.123 -0800 +2018-11-17 05:33:33.123 -0800 +2019-12-31 09:33:33.123 -0800 +2100-01-01 01:33:33.123 -0800 + + +-- !query +select col, date_format(col, 'O OOOO') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'O' + + +-- !query +select col, date_format(col, 'OO') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'O' + + +-- !query +select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'x' + + +-- !query +select col, date_format(col, 'xxxxxx') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Illegal pattern character 'x' diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out index 89c97ebe7e3c4..af042a588f0ef 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 7 +-- Number of queries: 60 -- !query @@ -18,78 +18,675 @@ struct<> -- !query -select col, date_format(col, 'Y-w-u YYYY-ww-uu YYY-W-uuu YY YYYYY uuuu E EE EEE EEEE') from v +select col, date_format(col, 'G GG GGG GGGG') from v -- !query schema -struct +struct -- !query output -1582-05-31 19:40:35.123 1582-22-1 1582-22-01 1582-5-Mon 82 01582 Monday Mon Mon Mon Monday -1969-12-31 15:00:00 1970-1-3 1970-01-03 1970-5-Wed 70 01970 Wednesday Wed Wed Wed Wednesday -1970-12-31 04:59:59.999 1970-53-4 1970-53-04 1970-5-Thu 70 01970 Thursday Thu Thu Thu Thursday -1996-03-31 07:03:33.123 1996-13-7 1996-13-07 1996-4-Sun 96 01996 Sunday Sun Sun Sun Sunday -2018-11-17 05:33:33.123 2018-46-6 2018-46-06 2018-3-Sat 18 02018 Saturday Sat Sat Sat Saturday -2019-12-31 09:33:33.123 2020-1-2 2020-01-02 2020-5-Tue 20 02020 Tuesday Tue Tue Tue Tuesday -2100-01-01 01:33:33.123 2099-53-5 2099-53-05 2099-0-Fri 99 02099 Friday Fri Fri Fri Friday +1582-05-31 19:40:35.123 AD AD AD Anno Domini +1969-12-31 15:00:00 AD AD AD Anno Domini +1970-12-31 04:59:59.999 AD AD AD Anno Domini +1996-03-31 07:03:33.123 AD AD AD Anno Domini +2018-11-17 05:33:33.123 AD AD AD Anno Domini +2019-12-31 09:33:33.123 AD AD AD Anno Domini +2100-01-01 01:33:33.123 AD AD AD Anno Domini -- !query -select col, date_format(col, 'q qq Q QQ QQQ QQQQ') from v +select col, date_format(col, 'GGGGG') from v -- !query schema -struct +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'GGGGG' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582 82 1582 1582 01582 001582 0001582 00001582 000001582 0000001582 +1969-12-31 15:00:00 1969 69 1969 1969 01969 001969 0001969 00001969 000001969 0000001969 +1970-12-31 04:59:59.999 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1996-03-31 07:03:33.123 1996 96 1996 1996 01996 001996 0001996 00001996 000001996 0000001996 +2018-11-17 05:33:33.123 2018 18 2018 2018 02018 002018 0002018 00002018 000002018 0000002018 +2019-12-31 09:33:33.123 2019 19 2019 2019 02019 002019 0002019 00002019 000002019 0000002019 +2100-01-01 01:33:33.123 2100 00 2100 2100 02100 002100 0002100 00002100 000002100 0000002100 + + +-- !query +select col, date_format(col, 'yyyyyyyyyyy') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'yyyyyyyyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1582 82 1582 1582 01582 001582 0001582 00001582 000001582 0000001582 +1969-12-31 15:00:00 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1970-12-31 04:59:59.999 1970 70 1970 1970 01970 001970 0001970 00001970 000001970 0000001970 +1996-03-31 07:03:33.123 1996 96 1996 1996 01996 001996 0001996 00001996 000001996 0000001996 +2018-11-17 05:33:33.123 2018 18 2018 2018 02018 002018 0002018 00002018 000002018 0000002018 +2019-12-31 09:33:33.123 2020 20 2020 2020 02020 002020 0002020 00002020 000002020 0000002020 +2100-01-01 01:33:33.123 2099 99 2099 2099 02099 002099 0002099 00002099 000002099 0000002099 + + +-- !query +select col, date_format(col, 'YYYYYYYYYYY') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'YYYYYYYYYYY' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'q qq') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 2 02 +1969-12-31 15:00:00 4 04 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 1 01 +2018-11-17 05:33:33.123 4 04 +2019-12-31 09:33:33.123 4 04 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'qqq') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Java 8 has a bug to support stand-alone form (3 or more 'L' or 'q' in the pattern string). Please use 'M' or 'Q' instead, or upgrade your Java version. For more details, please read https://bugs.openjdk.java.net/browse/JDK-8114833 + + +-- !query +select col, date_format(col, 'Q QQ QQQ QQQQ') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 2 02 Q2 2nd quarter +1969-12-31 15:00:00 4 04 Q4 4th quarter +1970-12-31 04:59:59.999 4 04 Q4 4th quarter +1996-03-31 07:03:33.123 1 01 Q1 1st quarter +2018-11-17 05:33:33.123 4 04 Q4 4th quarter +2019-12-31 09:33:33.123 4 04 Q4 4th quarter +2100-01-01 01:33:33.123 1 01 Q1 1st quarter + + +-- !query +select col, date_format(col, 'QQQQQ') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: Q + + +-- !query +select col, date_format(col, 'M MM MMM MMMM') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 05 May May +1969-12-31 15:00:00 12 12 Dec December +1970-12-31 04:59:59.999 12 12 Dec December +1996-03-31 07:03:33.123 3 03 Mar March +2018-11-17 05:33:33.123 11 11 Nov November +2019-12-31 09:33:33.123 12 12 Dec December +2100-01-01 01:33:33.123 1 01 Jan January + + +-- !query +select col, date_format(col, 'MMMMM') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'MMMMM' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'L LL') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 05 +1969-12-31 15:00:00 12 12 +1970-12-31 04:59:59.999 12 12 +1996-03-31 07:03:33.123 3 03 +2018-11-17 05:33:33.123 11 11 +2019-12-31 09:33:33.123 12 12 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'LLL') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'LLL' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'w ww') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 22 22 +1969-12-31 15:00:00 1 01 +1970-12-31 04:59:59.999 53 53 +1996-03-31 07:03:33.123 13 13 +2018-11-17 05:33:33.123 46 46 +2019-12-31 09:33:33.123 1 01 +2100-01-01 01:33:33.123 53 53 + + +-- !query +select col, date_format(col, 'www') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'www' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'W') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 5 +1969-12-31 15:00:00 5 +1970-12-31 04:59:59.999 5 +1996-03-31 07:03:33.123 4 +2018-11-17 05:33:33.123 3 +2019-12-31 09:33:33.123 5 +2100-01-01 01:33:33.123 0 + + +-- !query +select col, date_format(col, 'WW') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'WW' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'u uu uuu uuuu') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1 01 Mon Monday +1969-12-31 15:00:00 3 03 Wed Wednesday +1970-12-31 04:59:59.999 4 04 Thu Thursday +1996-03-31 07:03:33.123 7 07 Sun Sunday +2018-11-17 05:33:33.123 6 06 Sat Saturday +2019-12-31 09:33:33.123 2 02 Tue Tuesday +2100-01-01 01:33:33.123 5 05 Fri Friday + + +-- !query +select col, date_format(col, 'uuuuu') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'uuuuu' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'E EE EEE EEEE') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 Mon Mon Mon Monday +1969-12-31 15:00:00 Wed Wed Wed Wednesday +1970-12-31 04:59:59.999 Thu Thu Thu Thursday +1996-03-31 07:03:33.123 Sun Sun Sun Sunday +2018-11-17 05:33:33.123 Sat Sat Sat Saturday +2019-12-31 09:33:33.123 Tue Tue Tue Tuesday +2100-01-01 01:33:33.123 Fri Fri Fri Friday + + +-- !query +select col, date_format(col, 'EEEEE') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'EEEEE' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'F') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 3 +1969-12-31 15:00:00 3 +1970-12-31 04:59:59.999 3 +1996-03-31 07:03:33.123 3 +2018-11-17 05:33:33.123 3 +2019-12-31 09:33:33.123 3 +2100-01-01 01:33:33.123 1 + + +-- !query +select col, date_format(col, 'FF') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'FF' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'd dd') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 31 31 +1969-12-31 15:00:00 31 31 +1970-12-31 04:59:59.999 31 31 +1996-03-31 07:03:33.123 31 31 +2018-11-17 05:33:33.123 17 17 +2019-12-31 09:33:33.123 31 31 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'ddd') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ddd' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles' +-- !query schema +struct +-- !query output +2100-01-01 01:33:33.123 01 + + +-- !query +select col, date_format(col, 'D DDD') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 151 151 +1969-12-31 15:00:00 365 365 +1970-12-31 04:59:59.999 365 365 +1996-03-31 07:03:33.123 91 091 +2018-11-17 05:33:33.123 321 321 +2019-12-31 09:33:33.123 365 365 +2100-01-01 01:33:33.123 1 001 + + +-- !query +select col, date_format(col, 'DD') from v +-- !query schema +struct<> +-- !query output +java.time.DateTimeException +Field DayOfYear cannot be printed as the value 321 exceeds the maximum print width of 2 + + +-- !query +select col, date_format(col, 'DDDD') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'DDDD' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'H HH') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 19 19 +1969-12-31 15:00:00 15 15 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'HHH') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'HHH' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'h hh') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 7 07 +1969-12-31 15:00:00 3 03 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'hhh') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'hhh' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'k kk') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 19 19 +1969-12-31 15:00:00 15 15 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 + + +-- !query +select col, date_format(col, 'kkk') from v +-- !query schema +struct<> -- !query output -1582-05-31 19:40:35.123 2 02 2 02 Q2 2nd quarter -1969-12-31 15:00:00 4 04 4 04 Q4 4th quarter -1970-12-31 04:59:59.999 4 04 4 04 Q4 4th quarter -1996-03-31 07:03:33.123 1 01 1 01 Q1 1st quarter -2018-11-17 05:33:33.123 4 04 4 04 Q4 4th quarter -2019-12-31 09:33:33.123 4 04 4 04 Q4 4th quarter -2100-01-01 01:33:33.123 1 01 1 01 Q1 1st quarter +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'kkk' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html -- !query -select col, date_format(col, 'y-M-d H:m:s yyyy-MM-dd HH:mm:ss.SSS yy yyy yyyyy MMM MMMM L LL F h hh k kk K KK a') from v +select col, date_format(col, 'K KK') from v -- !query schema -struct +struct -- !query output -1582-05-31 19:40:35.123 1582-5-31 19:40:35 1582-05-31 19:40:35.123 82 1582 01582 May May 5 05 3 7 07 19 19 7 07 PM -1969-12-31 15:00:00 1969-12-31 15:0:0 1969-12-31 15:00:00.000 69 1969 01969 Dec December 12 12 3 3 03 15 15 3 03 PM -1970-12-31 04:59:59.999 1970-12-31 4:59:59 1970-12-31 04:59:59.999 70 1970 01970 Dec December 12 12 3 4 04 4 04 4 04 AM -1996-03-31 07:03:33.123 1996-3-31 7:3:33 1996-03-31 07:03:33.123 96 1996 01996 Mar March 3 03 3 7 07 7 07 7 07 AM -2018-11-17 05:33:33.123 2018-11-17 5:33:33 2018-11-17 05:33:33.123 18 2018 02018 Nov November 11 11 3 5 05 5 05 5 05 AM -2019-12-31 09:33:33.123 2019-12-31 9:33:33 2019-12-31 09:33:33.123 19 2019 02019 Dec December 12 12 3 9 09 9 09 9 09 AM -2100-01-01 01:33:33.123 2100-1-1 1:33:33 2100-01-01 01:33:33.123 00 2100 02100 Jan January 1 01 1 1 01 1 01 1 01 AM +1582-05-31 19:40:35.123 7 07 +1969-12-31 15:00:00 3 03 +1970-12-31 04:59:59.999 4 04 +1996-03-31 07:03:33.123 7 07 +2018-11-17 05:33:33.123 5 05 +2019-12-31 09:33:33.123 9 09 +2100-01-01 01:33:33.123 1 01 -- !query -select col, date_format(col, 'z zz zzz zzzz X XX XXX Z ZZ ZZZ ZZZZ ZZZZZ') from v +select col, date_format(col, 'KKK') from v -- !query schema -struct +struct<> -- !query output -1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time -0752 -0752 -07:52 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 -1969-12-31 15:00:00 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 -2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time -08 -0800 -08:00 -0800 -0800 -0800 GMT-08:00 -08:00 +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'KKK' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html -- !query -select col, date_format(col, 'VV O OOOO XXXX XXXXX x xx xxx xxxx xxxx xxxxx') from v +select col, date_format(col, 'm mm') from v -- !query schema -struct +struct -- !query output -1582-05-31 19:40:35.123 America/Los_Angeles GMT-7:52:58 GMT-07:52:58 -075258 -07:52:58 -0752 -0752 -07:52 -075258 -075258 -07:52:58 -1969-12-31 15:00:00 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -1970-12-31 04:59:59.999 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -1996-03-31 07:03:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -2018-11-17 05:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -2019-12-31 09:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 -2100-01-01 01:33:33.123 America/Los_Angeles GMT-8 GMT-08:00 -0800 -08:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1582-05-31 19:40:35.123 40 40 +1969-12-31 15:00:00 0 00 +1970-12-31 04:59:59.999 59 59 +1996-03-31 07:03:33.123 3 03 +2018-11-17 05:33:33.123 33 33 +2019-12-31 09:33:33.123 33 33 +2100-01-01 01:33:33.123 33 33 -- !query -select date_format(date '1970-01-01', 'D DD DDD') +select col, date_format(col, 'mmm') from v -- !query schema -struct +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'mmm' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 's ss') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 35 35 +1969-12-31 15:00:00 0 00 +1970-12-31 04:59:59.999 59 59 +1996-03-31 07:03:33.123 33 33 +2018-11-17 05:33:33.123 33 33 +2019-12-31 09:33:33.123 33 33 +2100-01-01 01:33:33.123 33 33 + + +-- !query +select col, date_format(col, 'sss') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'sss' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 1 12 123 1230 12300 123000 1230000 12300000 123000000 +1969-12-31 15:00:00 0 00 000 0000 00000 000000 0000000 00000000 000000000 +1970-12-31 04:59:59.999 9 99 999 9990 99900 999000 9990000 99900000 999000000 +1996-03-31 07:03:33.123 1 12 123 1230 12300 123000 1230000 12300000 123000000 +2018-11-17 05:33:33.123 1 12 123 1230 12300 123000 1230000 12300000 123000000 +2019-12-31 09:33:33.123 1 12 123 1230 12300 123000 1230000 12300000 123000000 +2100-01-01 01:33:33.123 1 12 123 1230 12300 123000 1230000 12300000 123000000 + + +-- !query +select col, date_format(col, 'SSSSSSSSSS') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'SSSSSSSSSS' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'a') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PM +1969-12-31 15:00:00 PM +1970-12-31 04:59:59.999 AM +1996-03-31 07:03:33.123 AM +2018-11-17 05:33:33.123 AM +2019-12-31 09:33:33.123 AM +2100-01-01 01:33:33.123 AM + + +-- !query +select col, date_format(col, 'aa') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'aa' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'VV') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 America/Los_Angeles +1969-12-31 15:00:00 America/Los_Angeles +1970-12-31 04:59:59.999 America/Los_Angeles +1996-03-31 07:03:33.123 America/Los_Angeles +2018-11-17 05:33:33.123 America/Los_Angeles +2019-12-31 09:33:33.123 America/Los_Angeles +2100-01-01 01:33:33.123 America/Los_Angeles + + +-- !query +select col, date_format(col, 'V') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Pattern letter count must be 2: V + + +-- !query +select col, date_format(col, 'z zz zzz zzzz') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 PST PST PST Pacific Standard Time +1969-12-31 15:00:00 PST PST PST Pacific Standard Time +1970-12-31 04:59:59.999 PST PST PST Pacific Standard Time +1996-03-31 07:03:33.123 PST PST PST Pacific Standard Time +2018-11-17 05:33:33.123 PST PST PST Pacific Standard Time +2019-12-31 09:33:33.123 PST PST PST Pacific Standard Time +2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time + + +-- !query +select col, date_format(col, 'zzzzz') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'zzzzz' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'X XX XXX') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -0752 -0752 -07:52 +1969-12-31 15:00:00 -08 -0800 -08:00 +1970-12-31 04:59:59.999 -08 -0800 -08:00 +1996-03-31 07:03:33.123 -08 -0800 -08:00 +2018-11-17 05:33:33.123 -08 -0800 -08:00 +2019-12-31 09:33:33.123 -08 -0800 -08:00 +2100-01-01 01:33:33.123 -08 -0800 -08:00 + + +-- !query +select col, date_format(col, 'XXXX XXXXX') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -075258 -07:52:58 +1969-12-31 15:00:00 -0800 -08:00 +1970-12-31 04:59:59.999 -0800 -08:00 +1996-03-31 07:03:33.123 -0800 -08:00 +2018-11-17 05:33:33.123 -0800 -08:00 +2019-12-31 09:33:33.123 -0800 -08:00 +2100-01-01 01:33:33.123 -0800 -08:00 + + +-- !query +select col, date_format(col, 'XXXXXX') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: X + + +-- !query +select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -0752 -0752 -0752 GMT-07:52:58 -07:52:58 +1969-12-31 15:00:00 -0800 -0800 -0800 GMT-08:00 -08:00 +1970-12-31 04:59:59.999 -0800 -0800 -0800 GMT-08:00 -08:00 +1996-03-31 07:03:33.123 -0800 -0800 -0800 GMT-08:00 -08:00 +2018-11-17 05:33:33.123 -0800 -0800 -0800 GMT-08:00 -08:00 +2019-12-31 09:33:33.123 -0800 -0800 -0800 GMT-08:00 -08:00 +2100-01-01 01:33:33.123 -0800 -0800 -0800 GMT-08:00 -08:00 + + +-- !query +select col, date_format(col, 'ZZZZZZ') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ZZZZZZ' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'O OOOO') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 GMT-7:52:58 GMT-07:52:58 +1969-12-31 15:00:00 GMT-8 GMT-08:00 +1970-12-31 04:59:59.999 GMT-8 GMT-08:00 +1996-03-31 07:03:33.123 GMT-8 GMT-08:00 +2018-11-17 05:33:33.123 GMT-8 GMT-08:00 +2019-12-31 09:33:33.123 GMT-8 GMT-08:00 +2100-01-01 01:33:33.123 GMT-8 GMT-08:00 + + +-- !query +select col, date_format(col, 'OO') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Pattern letter count must be 1 or 4: O + + +-- !query +select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v +-- !query schema +struct +-- !query output +1582-05-31 19:40:35.123 -0752 -0752 -07:52 -075258 -075258 -07:52:58 +1969-12-31 15:00:00 -08 -0800 -08:00 -0800 -0800 -08:00 +1970-12-31 04:59:59.999 -08 -0800 -08:00 -0800 -0800 -08:00 +1996-03-31 07:03:33.123 -08 -0800 -08:00 -0800 -0800 -08:00 +2018-11-17 05:33:33.123 -08 -0800 -08:00 -0800 -0800 -08:00 +2019-12-31 09:33:33.123 -08 -0800 -08:00 -0800 -0800 -08:00 +2100-01-01 01:33:33.123 -08 -0800 -08:00 -0800 -0800 -08:00 + + +-- !query +select col, date_format(col, 'xxxxxx') from v +-- !query schema +struct<> -- !query output -1 01 001 +java.lang.IllegalArgumentException +Too many pattern letters: x From 4d34f443691de60f28652a19a7d40cab7ba92307 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 4 Jun 2020 00:52:08 +0800 Subject: [PATCH 08/10] update test --- .../inputs/datetime-formatting-invalid.sql | 43 ++ .../sql-tests/inputs/datetime-formatting.sql | 42 +- .../datetime-formatting-invalid.sql.out | 278 ++++++++++++ .../datetime-formatting-legacy.sql.out | 394 +----------------- .../results/datetime-formatting.sql.out | 285 ++----------- 5 files changed, 381 insertions(+), 661 deletions(-) create mode 100644 sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql create mode 100644 sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql new file mode 100644 index 0000000000000..9ea8e69dc218c --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql @@ -0,0 +1,43 @@ +--- TESTS FOR DATETIME FORMATTING FUNCTIONS WITH INVALID PATTERNS --- + +-- separating this from datetime-formatting.sql ,because the text form +-- for patterns with 5 letters in SimpleDateFormat varies from different JDKs +create temporary view v as select col from values + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col); + +select col, date_format(col, 'GGGGG') from v; +select col, date_format(col, 'yyyyyyyyyyy') from v; -- pattern letter count can not be greater than 10 +select col, date_format(col, 'YYYYYYYYYYY') from v; +-- q/L in JDK 8 will fail when the count is more than 2 +select col, date_format(col, 'qqqqq') from v; +select col, date_format(col, 'QQQQQ') from v; +select col, date_format(col, 'MMMMM') from v; +select col, date_format(col, 'LLLLL') from v; +select col, date_format(col, 'www') from v; +select col, date_format(col, 'WW') from v; +select col, date_format(col, 'uuuuu') from v; +select col, date_format(col, 'EEEEE') from v; +select col, date_format(col, 'FF') from v; +select col, date_format(col, 'ddd') from v; +select col, date_format(col, 'DD') from v; +select col, date_format(col, 'DDDD') from v; +select col, date_format(col, 'HHH') from v; +select col, date_format(col, 'hhh') from v; +select col, date_format(col, 'kkk') from v; +select col, date_format(col, 'KKK') from v; +select col, date_format(col, 'mmm') from v; +select col, date_format(col, 'sss') from v; +select col, date_format(col, 'SSSSSSSSSS') from v; +select col, date_format(col, 'aa') from v; +select col, date_format(col, 'V') from v; +select col, date_format(col, 'zzzzz') from v; +select col, date_format(col, 'XXXXXX') from v; +select col, date_format(col, 'ZZZZZZ') from v; +select col, date_format(col, 'OO') from v; +select col, date_format(col, 'xxxxxx') from v; diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql index 03cf9b80bb5f1..391e018627e93 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql @@ -9,86 +9,66 @@ create temporary view v as select col from values (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col); ---------------------------- '1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890' select col, date_format(col, 'G GG GGG GGGG') from v; -select col, date_format(col, 'GGGGG') from v; select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v; -select col, date_format(col, 'yyyyyyyyyyy') from v; select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v; -select col, date_format(col, 'YYYYYYYYYYY') from v; select col, date_format(col, 'q qq') from v; -select col, date_format(col, 'qqq') from v; select col, date_format(col, 'Q QQ QQQ QQQQ') from v; -select col, date_format(col, 'QQQQQ') from v; select col, date_format(col, 'M MM MMM MMMM') from v; -select col, date_format(col, 'MMMMM') from v; select col, date_format(col, 'L LL') from v; -select col, date_format(col, 'LLL') from v; select col, date_format(col, 'w ww') from v; -select col, date_format(col, 'www') from v; select col, date_format(col, 'W') from v; -select col, date_format(col, 'WW') from v; select col, date_format(col, 'u uu uuu uuuu') from v; -select col, date_format(col, 'uuuuu') from v; select col, date_format(col, 'E EE EEE EEEE') from v; -select col, date_format(col, 'EEEEE') from v; select col, date_format(col, 'F') from v; -select col, date_format(col, 'FF') from v; select col, date_format(col, 'd dd') from v; -select col, date_format(col, 'ddd') from v; select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles'; -select col, date_format(col, 'DD') from v; select col, date_format(col, 'D DDD') from v; -select col, date_format(col, 'DDDD') from v; select col, date_format(col, 'H HH') from v; -select col, date_format(col, 'HHH') from v; select col, date_format(col, 'h hh') from v; -select col, date_format(col, 'hhh') from v; select col, date_format(col, 'k kk') from v; -select col, date_format(col, 'kkk') from v; select col, date_format(col, 'K KK') from v; -select col, date_format(col, 'KKK') from v; select col, date_format(col, 'm mm') from v; -select col, date_format(col, 'mmm') from v; select col, date_format(col, 's ss') from v; -select col, date_format(col, 'sss') from v; select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v; -select col, date_format(col, 'SSSSSSSSSS') from v; -select col, date_format(col, 'a') from v; -select col, date_format(col, 'aa') from v; +-- add upper function here to avoid +select col, upper(date_format(col, 'a')) from v; select col, date_format(col, 'VV') from v; -select col, date_format(col, 'V') from v; select col, date_format(col, 'z zz zzz zzzz') from v; -select col, date_format(col, 'zzzzz') from v; + select col, date_format(col, 'X XX XXX') from v; select col, date_format(col, 'XXXX XXXXX') from v; -select col, date_format(col, 'XXXXXX') from v; + select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v; -select col, date_format(col, 'ZZZZZZ') from v; + select col, date_format(col, 'O OOOO') from v; -select col, date_format(col, 'OO') from v; + select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v; -select col, date_format(col, 'xxxxxx') from v; + +-- optional pattern, but the results won't be optional for formatting +select col, date_format(col, '[yyyy-MM-dd HH:mm:ss]') from v; + +select col, date_format(col, "姚123'GyYqQMLwWuEFDdhHmsSaVzZxXOV'") from v; -- literals 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 new file mode 100644 index 0000000000000..0acec09c24d45 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-invalid.sql.out @@ -0,0 +1,278 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 30 + + +-- !query +create temporary view v as select col from values + (timestamp '1582-06-01 11:33:33.123UTC+080000'), + (timestamp '1970-01-01 00:00:00.000Europe/Paris'), + (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), + (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), + (timestamp '2018-11-17 13:33:33.123Z'), + (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), + (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col) +-- !query schema +struct<> +-- !query output + + + +-- !query +select col, date_format(col, 'GGGGG') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'GGGGG' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'yyyyyyyyyyy') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'yyyyyyyyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'YYYYYYYYYYY') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'YYYYYYYYYYY' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'qqqqq') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: q + + +-- !query +select col, date_format(col, 'QQQQQ') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: Q + + +-- !query +select col, date_format(col, 'MMMMM') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'MMMMM' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'LLLLL') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'LLLLL' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'www') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'www' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'WW') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'WW' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'uuuuu') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'uuuuu' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'EEEEE') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'EEEEE' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'FF') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'FF' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'ddd') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ddd' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'DD') from v +-- !query schema +struct<> +-- !query output +java.time.DateTimeException +Field DayOfYear cannot be printed as the value 151 exceeds the maximum print width of 2 + + +-- !query +select col, date_format(col, 'DDDD') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'DDDD' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'HHH') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'HHH' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'hhh') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'hhh' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'kkk') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'kkk' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'KKK') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'KKK' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'mmm') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'mmm' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'sss') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'sss' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'SSSSSSSSSS') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'SSSSSSSSSS' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'aa') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'aa' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'V') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Pattern letter count must be 2: V + + +-- !query +select col, date_format(col, 'zzzzz') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'zzzzz' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'XXXXXX') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: X + + +-- !query +select col, date_format(col, 'ZZZZZZ') from v +-- !query schema +struct<> +-- !query output +org.apache.spark.SparkUpgradeException +You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ZZZZZZ' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html + + +-- !query +select col, date_format(col, 'OO') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Pattern letter count must be 1 or 4: O + + +-- !query +select col, date_format(col, 'xxxxxx') from v +-- !query schema +struct<> +-- !query output +java.lang.IllegalArgumentException +Too many pattern letters: x diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out index 67d439f05ea08..d84d3b02a4999 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 60 +-- Number of queries: 33 -- !query @@ -31,20 +31,6 @@ struct 2100-01-01 01:33:33.123 AD AD AD AD --- !query -select col, date_format(col, 'GGGGG') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 AD -1969-12-31 15:00:00 AD -1970-12-31 04:59:59.999 AD -1996-03-31 07:03:33.123 AD -2018-11-17 05:33:33.123 AD -2019-12-31 09:33:33.123 AD -2100-01-01 01:33:33.123 AD - - -- !query select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v -- !query schema @@ -59,20 +45,6 @@ struct --- !query output -1582-05-31 19:40:35.123 00000001582 -1969-12-31 15:00:00 00000001969 -1970-12-31 04:59:59.999 00000001970 -1996-03-31 07:03:33.123 00000001996 -2018-11-17 05:33:33.123 00000002018 -2019-12-31 09:33:33.123 00000002019 -2100-01-01 01:33:33.123 00000002100 - - -- !query select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v -- !query schema @@ -87,20 +59,6 @@ struct --- !query output -1582-05-31 19:40:35.123 00000001582 -1969-12-31 15:00:00 00000001970 -1970-12-31 04:59:59.999 00000001970 -1996-03-31 07:03:33.123 00000001996 -2018-11-17 05:33:33.123 00000002018 -2019-12-31 09:33:33.123 00000002020 -2100-01-01 01:33:33.123 00000002099 - - -- !query select col, date_format(col, 'q qq') from v -- !query schema @@ -110,15 +68,6 @@ java.lang.IllegalArgumentException Illegal pattern character 'q' --- !query -select col, date_format(col, 'qqq') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'q' - - -- !query select col, date_format(col, 'Q QQ QQQ QQQQ') from v -- !query schema @@ -128,15 +77,6 @@ java.lang.IllegalArgumentException Illegal pattern character 'Q' --- !query -select col, date_format(col, 'QQQQQ') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'Q' - - -- !query select col, date_format(col, 'M MM MMM MMMM') from v -- !query schema @@ -151,20 +91,6 @@ struct 2100-01-01 01:33:33.123 1 01 Jan January --- !query -select col, date_format(col, 'MMMMM') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 May -1969-12-31 15:00:00 December -1970-12-31 04:59:59.999 December -1996-03-31 07:03:33.123 March -2018-11-17 05:33:33.123 November -2019-12-31 09:33:33.123 December -2100-01-01 01:33:33.123 January - - -- !query select col, date_format(col, 'L LL') from v -- !query schema @@ -179,20 +105,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'LLL') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 May -1969-12-31 15:00:00 Dec -1970-12-31 04:59:59.999 Dec -1996-03-31 07:03:33.123 Mar -2018-11-17 05:33:33.123 Nov -2019-12-31 09:33:33.123 Dec -2100-01-01 01:33:33.123 Jan - - -- !query select col, date_format(col, 'w ww') from v -- !query schema @@ -207,20 +119,6 @@ struct 2100-01-01 01:33:33.123 53 53 --- !query -select col, date_format(col, 'www') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 022 -1969-12-31 15:00:00 001 -1970-12-31 04:59:59.999 053 -1996-03-31 07:03:33.123 013 -2018-11-17 05:33:33.123 046 -2019-12-31 09:33:33.123 001 -2100-01-01 01:33:33.123 053 - - -- !query select col, date_format(col, 'W') from v -- !query schema @@ -235,20 +133,6 @@ struct 2100-01-01 01:33:33.123 0 --- !query -select col, date_format(col, 'WW') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 05 -1969-12-31 15:00:00 05 -1970-12-31 04:59:59.999 05 -1996-03-31 07:03:33.123 04 -2018-11-17 05:33:33.123 03 -2019-12-31 09:33:33.123 05 -2100-01-01 01:33:33.123 00 - - -- !query select col, date_format(col, 'u uu uuu uuuu') from v -- !query schema @@ -263,20 +147,6 @@ struct 2100-01-01 01:33:33.123 5 05 005 0005 --- !query -select col, date_format(col, 'uuuuu') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 00004 -1969-12-31 15:00:00 00003 -1970-12-31 04:59:59.999 00004 -1996-03-31 07:03:33.123 00007 -2018-11-17 05:33:33.123 00006 -2019-12-31 09:33:33.123 00002 -2100-01-01 01:33:33.123 00005 - - -- !query select col, date_format(col, 'E EE EEE EEEE') from v -- !query schema @@ -291,20 +161,6 @@ struct 2100-01-01 01:33:33.123 Fri Fri Fri Friday --- !query -select col, date_format(col, 'EEEEE') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 Thursday -1969-12-31 15:00:00 Wednesday -1970-12-31 04:59:59.999 Thursday -1996-03-31 07:03:33.123 Sunday -2018-11-17 05:33:33.123 Saturday -2019-12-31 09:33:33.123 Tuesday -2100-01-01 01:33:33.123 Friday - - -- !query select col, date_format(col, 'F') from v -- !query schema @@ -319,20 +175,6 @@ struct 2100-01-01 01:33:33.123 1 --- !query -select col, date_format(col, 'FF') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 05 -1969-12-31 15:00:00 05 -1970-12-31 04:59:59.999 05 -1996-03-31 07:03:33.123 05 -2018-11-17 05:33:33.123 03 -2019-12-31 09:33:33.123 05 -2100-01-01 01:33:33.123 01 - - -- !query select col, date_format(col, 'd dd') from v -- !query schema @@ -347,20 +189,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'ddd') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 031 -1969-12-31 15:00:00 031 -1970-12-31 04:59:59.999 031 -1996-03-31 07:03:33.123 031 -2018-11-17 05:33:33.123 017 -2019-12-31 09:33:33.123 031 -2100-01-01 01:33:33.123 001 - - -- !query select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles' -- !query schema @@ -383,34 +211,6 @@ struct 2100-01-01 01:33:33.123 1 001 --- !query -select col, date_format(col, 'DD') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 151 -1969-12-31 15:00:00 365 -1970-12-31 04:59:59.999 365 -1996-03-31 07:03:33.123 91 -2018-11-17 05:33:33.123 321 -2019-12-31 09:33:33.123 365 -2100-01-01 01:33:33.123 01 - - --- !query -select col, date_format(col, 'DDDD') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 0151 -1969-12-31 15:00:00 0365 -1970-12-31 04:59:59.999 0365 -1996-03-31 07:03:33.123 0091 -2018-11-17 05:33:33.123 0321 -2019-12-31 09:33:33.123 0365 -2100-01-01 01:33:33.123 0001 - - -- !query select col, date_format(col, 'H HH') from v -- !query schema @@ -425,20 +225,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'HHH') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 019 -1969-12-31 15:00:00 015 -1970-12-31 04:59:59.999 004 -1996-03-31 07:03:33.123 007 -2018-11-17 05:33:33.123 005 -2019-12-31 09:33:33.123 009 -2100-01-01 01:33:33.123 001 - - -- !query select col, date_format(col, 'h hh') from v -- !query schema @@ -453,20 +239,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'hhh') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 007 -1969-12-31 15:00:00 003 -1970-12-31 04:59:59.999 004 -1996-03-31 07:03:33.123 007 -2018-11-17 05:33:33.123 005 -2019-12-31 09:33:33.123 009 -2100-01-01 01:33:33.123 001 - - -- !query select col, date_format(col, 'k kk') from v -- !query schema @@ -481,20 +253,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'kkk') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 019 -1969-12-31 15:00:00 015 -1970-12-31 04:59:59.999 004 -1996-03-31 07:03:33.123 007 -2018-11-17 05:33:33.123 005 -2019-12-31 09:33:33.123 009 -2100-01-01 01:33:33.123 001 - - -- !query select col, date_format(col, 'K KK') from v -- !query schema @@ -509,20 +267,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'KKK') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 007 -1969-12-31 15:00:00 003 -1970-12-31 04:59:59.999 004 -1996-03-31 07:03:33.123 007 -2018-11-17 05:33:33.123 005 -2019-12-31 09:33:33.123 009 -2100-01-01 01:33:33.123 001 - - -- !query select col, date_format(col, 'm mm') from v -- !query schema @@ -537,20 +281,6 @@ struct 2100-01-01 01:33:33.123 33 33 --- !query -select col, date_format(col, 'mmm') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 040 -1969-12-31 15:00:00 000 -1970-12-31 04:59:59.999 059 -1996-03-31 07:03:33.123 003 -2018-11-17 05:33:33.123 033 -2019-12-31 09:33:33.123 033 -2100-01-01 01:33:33.123 033 - - -- !query select col, date_format(col, 's ss') from v -- !query schema @@ -565,20 +295,6 @@ struct 2100-01-01 01:33:33.123 33 33 --- !query -select col, date_format(col, 'sss') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 035 -1969-12-31 15:00:00 000 -1970-12-31 04:59:59.999 059 -1996-03-31 07:03:33.123 033 -2018-11-17 05:33:33.123 033 -2019-12-31 09:33:33.123 033 -2100-01-01 01:33:33.123 033 - - -- !query select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v -- !query schema @@ -594,37 +310,9 @@ struct --- !query output -1582-05-31 19:40:35.123 0000000123 -1969-12-31 15:00:00 0000000000 -1970-12-31 04:59:59.999 0000000999 -1996-03-31 07:03:33.123 0000000123 -2018-11-17 05:33:33.123 0000000123 -2019-12-31 09:33:33.123 0000000123 -2100-01-01 01:33:33.123 0000000123 - - --- !query -select col, date_format(col, 'a') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 PM -1969-12-31 15:00:00 PM -1970-12-31 04:59:59.999 AM -1996-03-31 07:03:33.123 AM -2018-11-17 05:33:33.123 AM -2019-12-31 09:33:33.123 AM -2100-01-01 01:33:33.123 AM - - --- !query -select col, date_format(col, 'aa') from v --- !query schema -struct +struct -- !query output 1582-05-31 19:40:35.123 PM 1969-12-31 15:00:00 PM @@ -644,15 +332,6 @@ java.lang.IllegalArgumentException Illegal pattern character 'V' --- !query -select col, date_format(col, 'V') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'V' - - -- !query select col, date_format(col, 'z zz zzz zzzz') from v -- !query schema @@ -667,20 +346,6 @@ struct 2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time --- !query -select col, date_format(col, 'zzzzz') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 Pacific Standard Time -1969-12-31 15:00:00 Pacific Standard Time -1970-12-31 04:59:59.999 Pacific Standard Time -1996-03-31 07:03:33.123 Pacific Standard Time -2018-11-17 05:33:33.123 Pacific Standard Time -2019-12-31 09:33:33.123 Pacific Standard Time -2100-01-01 01:33:33.123 Pacific Standard Time - - -- !query select col, date_format(col, 'X XX XXX') from v -- !query schema @@ -704,15 +369,6 @@ java.lang.IllegalArgumentException invalid ISO 8601 format: length=4 --- !query -select col, date_format(col, 'XXXXXX') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -invalid ISO 8601 format: length=6 - - -- !query select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v -- !query schema @@ -727,20 +383,6 @@ struct 2100-01-01 01:33:33.123 -0800 -0800 -0800 -0800 -0800 --- !query -select col, date_format(col, 'ZZZZZZ') from v --- !query schema -struct --- !query output -1582-05-31 19:40:35.123 -0800 -1969-12-31 15:00:00 -0800 -1970-12-31 04:59:59.999 -0800 -1996-03-31 07:03:33.123 -0800 -2018-11-17 05:33:33.123 -0800 -2019-12-31 09:33:33.123 -0800 -2100-01-01 01:33:33.123 -0800 - - -- !query select col, date_format(col, 'O OOOO') from v -- !query schema @@ -751,27 +393,37 @@ Illegal pattern character 'O' -- !query -select col, date_format(col, 'OO') from v +select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v -- !query schema struct<> -- !query output java.lang.IllegalArgumentException -Illegal pattern character 'O' +Illegal pattern character 'x' -- !query -select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v +select col, date_format(col, '[yyyy-MM-dd HH:mm:ss]') from v -- !query schema -struct<> +struct -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'x' +1582-05-31 19:40:35.123 [1582-05-31 19:40:35] +1969-12-31 15:00:00 [1969-12-31 15:00:00] +1970-12-31 04:59:59.999 [1970-12-31 04:59:59] +1996-03-31 07:03:33.123 [1996-03-31 07:03:33] +2018-11-17 05:33:33.123 [2018-11-17 05:33:33] +2019-12-31 09:33:33.123 [2019-12-31 09:33:33] +2100-01-01 01:33:33.123 [2100-01-01 01:33:33] -- !query -select col, date_format(col, 'xxxxxx') from v +select col, date_format(col, "姚123'GyYqQMLwWuEFDdhHmsSaVzZxXOV'") from v -- !query schema -struct<> +struct -- !query output -java.lang.IllegalArgumentException -Illegal pattern character 'x' +1582-05-31 19:40:35.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1969-12-31 15:00:00 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1970-12-31 04:59:59.999 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1996-03-31 07:03:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2018-11-17 05:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2019-12-31 09:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2100-01-01 01:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out index af042a588f0ef..6f7a18057d576 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 60 +-- Number of queries: 33 -- !query @@ -31,15 +31,6 @@ struct 2100-01-01 01:33:33.123 AD AD AD Anno Domini --- !query -select col, date_format(col, 'GGGGG') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'GGGGG' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'y yy yyy yyyy yyyyy yyyyyy yyyyyyy yyyyyyyy yyyyyyyyy yyyyyyyyyy') from v -- !query schema @@ -54,15 +45,6 @@ struct --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'yyyyyyyyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'Y YY YYY YYYY YYYYY YYYYYY YYYYYYY YYYYYYYY YYYYYYYYY YYYYYYYYYY') from v -- !query schema @@ -77,15 +59,6 @@ struct --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'YYYYYYYYYYY' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'q qq') from v -- !query schema @@ -100,15 +73,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'qqq') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Java 8 has a bug to support stand-alone form (3 or more 'L' or 'q' in the pattern string). Please use 'M' or 'Q' instead, or upgrade your Java version. For more details, please read https://bugs.openjdk.java.net/browse/JDK-8114833 - - -- !query select col, date_format(col, 'Q QQ QQQ QQQQ') from v -- !query schema @@ -123,15 +87,6 @@ struct 2100-01-01 01:33:33.123 1 01 Q1 1st quarter --- !query -select col, date_format(col, 'QQQQQ') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Too many pattern letters: Q - - -- !query select col, date_format(col, 'M MM MMM MMMM') from v -- !query schema @@ -146,15 +101,6 @@ struct 2100-01-01 01:33:33.123 1 01 Jan January --- !query -select col, date_format(col, 'MMMMM') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'MMMMM' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'L LL') from v -- !query schema @@ -169,15 +115,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'LLL') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'LLL' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'w ww') from v -- !query schema @@ -192,15 +129,6 @@ struct 2100-01-01 01:33:33.123 53 53 --- !query -select col, date_format(col, 'www') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'www' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'W') from v -- !query schema @@ -215,15 +143,6 @@ struct 2100-01-01 01:33:33.123 0 --- !query -select col, date_format(col, 'WW') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'WW' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'u uu uuu uuuu') from v -- !query schema @@ -238,15 +157,6 @@ struct 2100-01-01 01:33:33.123 5 05 Fri Friday --- !query -select col, date_format(col, 'uuuuu') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'uuuuu' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'E EE EEE EEEE') from v -- !query schema @@ -261,15 +171,6 @@ struct 2100-01-01 01:33:33.123 Fri Fri Fri Friday --- !query -select col, date_format(col, 'EEEEE') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'EEEEE' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'F') from v -- !query schema @@ -284,15 +185,6 @@ struct 2100-01-01 01:33:33.123 1 --- !query -select col, date_format(col, 'FF') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'FF' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'd dd') from v -- !query schema @@ -307,15 +199,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'ddd') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ddd' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'DD') from v where col = timestamp '2100-01-01 01:33:33.123America/Los_Angeles' -- !query schema @@ -338,24 +221,6 @@ struct 2100-01-01 01:33:33.123 1 001 --- !query -select col, date_format(col, 'DD') from v --- !query schema -struct<> --- !query output -java.time.DateTimeException -Field DayOfYear cannot be printed as the value 321 exceeds the maximum print width of 2 - - --- !query -select col, date_format(col, 'DDDD') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'DDDD' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'H HH') from v -- !query schema @@ -370,15 +235,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'HHH') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'HHH' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'h hh') from v -- !query schema @@ -393,15 +249,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'hhh') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'hhh' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'k kk') from v -- !query schema @@ -416,15 +263,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'kkk') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'kkk' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'K KK') from v -- !query schema @@ -439,15 +277,6 @@ struct 2100-01-01 01:33:33.123 1 01 --- !query -select col, date_format(col, 'KKK') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'KKK' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'm mm') from v -- !query schema @@ -462,15 +291,6 @@ struct 2100-01-01 01:33:33.123 33 33 --- !query -select col, date_format(col, 'mmm') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'mmm' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 's ss') from v -- !query schema @@ -485,15 +305,6 @@ struct 2100-01-01 01:33:33.123 33 33 --- !query -select col, date_format(col, 'sss') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'sss' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v -- !query schema @@ -509,18 +320,9 @@ struct --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'SSSSSSSSSS' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - --- !query -select col, date_format(col, 'a') from v --- !query schema -struct +struct -- !query output 1582-05-31 19:40:35.123 PM 1969-12-31 15:00:00 PM @@ -531,15 +333,6 @@ struct 2100-01-01 01:33:33.123 AM --- !query -select col, date_format(col, 'aa') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'aa' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'VV') from v -- !query schema @@ -554,15 +347,6 @@ struct 2100-01-01 01:33:33.123 America/Los_Angeles --- !query -select col, date_format(col, 'V') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Pattern letter count must be 2: V - - -- !query select col, date_format(col, 'z zz zzz zzzz') from v -- !query schema @@ -577,15 +361,6 @@ struct 2100-01-01 01:33:33.123 PST PST PST Pacific Standard Time --- !query -select col, date_format(col, 'zzzzz') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'zzzzz' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'X XX XXX') from v -- !query schema @@ -614,15 +389,6 @@ struct 2100-01-01 01:33:33.123 -0800 -08:00 --- !query -select col, date_format(col, 'XXXXXX') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Too many pattern letters: X - - -- !query select col, date_format(col, 'Z ZZ ZZZ ZZZZ ZZZZZ') from v -- !query schema @@ -637,15 +403,6 @@ struct 2100-01-01 01:33:33.123 -0800 -0800 -0800 GMT-08:00 -08:00 --- !query -select col, date_format(col, 'ZZZZZZ') from v --- !query schema -struct<> --- !query output -org.apache.spark.SparkUpgradeException -You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'ZZZZZZ' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html - - -- !query select col, date_format(col, 'O OOOO') from v -- !query schema @@ -660,15 +417,6 @@ struct 2100-01-01 01:33:33.123 GMT-8 GMT-08:00 --- !query -select col, date_format(col, 'OO') from v --- !query schema -struct<> --- !query output -java.lang.IllegalArgumentException -Pattern letter count must be 1 or 4: O - - -- !query select col, date_format(col, 'x xx xxx xxxx xxxx xxxxx') from v -- !query schema @@ -684,9 +432,28 @@ struct -- !query -select col, date_format(col, 'xxxxxx') from v +select col, date_format(col, '[yyyy-MM-dd HH:mm:ss]') from v -- !query schema -struct<> +struct +-- !query output +1582-05-31 19:40:35.123 1582-05-31 19:40:35 +1969-12-31 15:00:00 1969-12-31 15:00:00 +1970-12-31 04:59:59.999 1970-12-31 04:59:59 +1996-03-31 07:03:33.123 1996-03-31 07:03:33 +2018-11-17 05:33:33.123 2018-11-17 05:33:33 +2019-12-31 09:33:33.123 2019-12-31 09:33:33 +2100-01-01 01:33:33.123 2100-01-01 01:33:33 + + +-- !query +select col, date_format(col, "姚123'GyYqQMLwWuEFDdhHmsSaVzZxXOV'") from v +-- !query schema +struct -- !query output -java.lang.IllegalArgumentException -Too many pattern letters: x +1582-05-31 19:40:35.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1969-12-31 15:00:00 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1970-12-31 04:59:59.999 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +1996-03-31 07:03:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2018-11-17 05:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2019-12-31 09:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV +2100-01-01 01:33:33.123 姚123GyYqQMLwWuEFDdhHmsSaVzZxXOV From 11c96530a853d73a24e0c7a5a4c0fe0fe77a13f2 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 4 Jun 2020 01:21:40 +0800 Subject: [PATCH 09/10] address comments --- .../inputs/datetime-formatting-invalid.sql | 69 +++++++--------- .../datetime-formatting-invalid.sql.out | 82 +++++++------------ 2 files changed, 60 insertions(+), 91 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql index 9ea8e69dc218c..ddd5855165f3c 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql @@ -2,42 +2,35 @@ -- separating this from datetime-formatting.sql ,because the text form -- for patterns with 5 letters in SimpleDateFormat varies from different JDKs -create temporary view v as select col from values - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col); - -select col, date_format(col, 'GGGGG') from v; -select col, date_format(col, 'yyyyyyyyyyy') from v; -- pattern letter count can not be greater than 10 -select col, date_format(col, 'YYYYYYYYYYY') from v; +select date_format('2018-11-17 13:33:33.333', 'GGGGG'); +-- pattern letter count can not be greater than 10 +select date_format('2018-11-17 13:33:33.333', 'yyyyyyyyyyy'); +select date_format('2018-11-17 13:33:33.333', 'YYYYYYYYYYY'); -- q/L in JDK 8 will fail when the count is more than 2 -select col, date_format(col, 'qqqqq') from v; -select col, date_format(col, 'QQQQQ') from v; -select col, date_format(col, 'MMMMM') from v; -select col, date_format(col, 'LLLLL') from v; -select col, date_format(col, 'www') from v; -select col, date_format(col, 'WW') from v; -select col, date_format(col, 'uuuuu') from v; -select col, date_format(col, 'EEEEE') from v; -select col, date_format(col, 'FF') from v; -select col, date_format(col, 'ddd') from v; -select col, date_format(col, 'DD') from v; -select col, date_format(col, 'DDDD') from v; -select col, date_format(col, 'HHH') from v; -select col, date_format(col, 'hhh') from v; -select col, date_format(col, 'kkk') from v; -select col, date_format(col, 'KKK') from v; -select col, date_format(col, 'mmm') from v; -select col, date_format(col, 'sss') from v; -select col, date_format(col, 'SSSSSSSSSS') from v; -select col, date_format(col, 'aa') from v; -select col, date_format(col, 'V') from v; -select col, date_format(col, 'zzzzz') from v; -select col, date_format(col, 'XXXXXX') from v; -select col, date_format(col, 'ZZZZZZ') from v; -select col, date_format(col, 'OO') from v; -select col, date_format(col, 'xxxxxx') from v; +select date_format('2018-11-17 13:33:33.333', 'qqqqq'); +select date_format('2018-11-17 13:33:33.333', 'QQQQQ'); +select date_format('2018-11-17 13:33:33.333', 'MMMMM'); +select date_format('2018-11-17 13:33:33.333', 'LLLLL'); +select date_format('2018-11-17 13:33:33.333', 'www'); +select date_format('2018-11-17 13:33:33.333', 'WW'); +select date_format('2018-11-17 13:33:33.333', 'uuuuu'); +select date_format('2018-11-17 13:33:33.333', 'EEEEE'); +select date_format('2018-11-17 13:33:33.333', 'FF'); +select date_format('2018-11-17 13:33:33.333', 'ddd'); +-- DD is invalid in 8, but valid in 11 for the JDKs that PR builder uses +-- select date_format('2018-11-17 13:33:33.333', 'DD'); +select date_format('2018-11-17 13:33:33.333', 'DDDD'); +select date_format('2018-11-17 13:33:33.333', 'HHH'); +select date_format('2018-11-17 13:33:33.333', 'hhh'); +select date_format('2018-11-17 13:33:33.333', 'kkk'); +select date_format('2018-11-17 13:33:33.333', 'KKK'); +select date_format('2018-11-17 13:33:33.333', 'mmm'); +select date_format('2018-11-17 13:33:33.333', 'sss'); +select date_format('2018-11-17 13:33:33.333', 'SSSSSSSSSS'); +select date_format('2018-11-17 13:33:33.333', 'aa'); +select date_format('2018-11-17 13:33:33.333', 'V'); +select date_format('2018-11-17 13:33:33.333', 'zzzzz'); +select date_format('2018-11-17 13:33:33.333', 'XXXXXX'); +select date_format('2018-11-17 13:33:33.333', 'ZZZZZZ'); +select date_format('2018-11-17 13:33:33.333', 'OO'); +select date_format('2018-11-17 13:33:33.333', 'xxxxxx'); 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 0acec09c24d45..37e44fd0f6060 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 @@ -1,24 +1,9 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 30 +-- Number of queries: 28 -- !query -create temporary view v as select col from values - (timestamp '1582-06-01 11:33:33.123UTC+080000'), - (timestamp '1970-01-01 00:00:00.000Europe/Paris'), - (timestamp '1970-12-31 23:59:59.999Asia/Srednekolymsk'), - (timestamp '1996-04-01 00:33:33.123Australia/Darwin'), - (timestamp '2018-11-17 13:33:33.123Z'), - (timestamp '2020-01-01 01:33:33.123Asia/Shanghai'), - (timestamp '2100-01-01 01:33:33.123America/Los_Angeles') t(col) --- !query schema -struct<> --- !query output - - - --- !query -select col, date_format(col, 'GGGGG') from v +select date_format('2018-11-17 13:33:33.333', 'GGGGG') -- !query schema struct<> -- !query output @@ -27,7 +12,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'yyyyyyyyyyy') from v +select date_format('2018-11-17 13:33:33.333', 'yyyyyyyyyyy') -- !query schema struct<> -- !query output @@ -36,7 +21,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'YYYYYYYYYYY') from v +select date_format('2018-11-17 13:33:33.333', 'YYYYYYYYYYY') -- !query schema struct<> -- !query output @@ -45,7 +30,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'qqqqq') from v +select date_format('2018-11-17 13:33:33.333', 'qqqqq') -- !query schema struct<> -- !query output @@ -54,7 +39,7 @@ Too many pattern letters: q -- !query -select col, date_format(col, 'QQQQQ') from v +select date_format('2018-11-17 13:33:33.333', 'QQQQQ') -- !query schema struct<> -- !query output @@ -63,7 +48,7 @@ Too many pattern letters: Q -- !query -select col, date_format(col, 'MMMMM') from v +select date_format('2018-11-17 13:33:33.333', 'MMMMM') -- !query schema struct<> -- !query output @@ -72,7 +57,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'LLLLL') from v +select date_format('2018-11-17 13:33:33.333', 'LLLLL') -- !query schema struct<> -- !query output @@ -81,7 +66,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'www') from v +select date_format('2018-11-17 13:33:33.333', 'www') -- !query schema struct<> -- !query output @@ -90,7 +75,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'WW') from v +select date_format('2018-11-17 13:33:33.333', 'WW') -- !query schema struct<> -- !query output @@ -99,7 +84,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'uuuuu') from v +select date_format('2018-11-17 13:33:33.333', 'uuuuu') -- !query schema struct<> -- !query output @@ -108,7 +93,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'EEEEE') from v +select date_format('2018-11-17 13:33:33.333', 'EEEEE') -- !query schema struct<> -- !query output @@ -117,7 +102,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'FF') from v +select date_format('2018-11-17 13:33:33.333', 'FF') -- !query schema struct<> -- !query output @@ -126,7 +111,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'ddd') from v +select date_format('2018-11-17 13:33:33.333', 'ddd') -- !query schema struct<> -- !query output @@ -135,16 +120,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'DD') from v --- !query schema -struct<> --- !query output -java.time.DateTimeException -Field DayOfYear cannot be printed as the value 151 exceeds the maximum print width of 2 - - --- !query -select col, date_format(col, 'DDDD') from v +select date_format('2018-11-17 13:33:33.333', 'DDDD') -- !query schema struct<> -- !query output @@ -153,7 +129,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'HHH') from v +select date_format('2018-11-17 13:33:33.333', 'HHH') -- !query schema struct<> -- !query output @@ -162,7 +138,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'hhh') from v +select date_format('2018-11-17 13:33:33.333', 'hhh') -- !query schema struct<> -- !query output @@ -171,7 +147,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'kkk') from v +select date_format('2018-11-17 13:33:33.333', 'kkk') -- !query schema struct<> -- !query output @@ -180,7 +156,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'KKK') from v +select date_format('2018-11-17 13:33:33.333', 'KKK') -- !query schema struct<> -- !query output @@ -189,7 +165,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'mmm') from v +select date_format('2018-11-17 13:33:33.333', 'mmm') -- !query schema struct<> -- !query output @@ -198,7 +174,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'sss') from v +select date_format('2018-11-17 13:33:33.333', 'sss') -- !query schema struct<> -- !query output @@ -207,7 +183,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'SSSSSSSSSS') from v +select date_format('2018-11-17 13:33:33.333', 'SSSSSSSSSS') -- !query schema struct<> -- !query output @@ -216,7 +192,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'aa') from v +select date_format('2018-11-17 13:33:33.333', 'aa') -- !query schema struct<> -- !query output @@ -225,7 +201,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'V') from v +select date_format('2018-11-17 13:33:33.333', 'V') -- !query schema struct<> -- !query output @@ -234,7 +210,7 @@ Pattern letter count must be 2: V -- !query -select col, date_format(col, 'zzzzz') from v +select date_format('2018-11-17 13:33:33.333', 'zzzzz') -- !query schema struct<> -- !query output @@ -243,7 +219,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'XXXXXX') from v +select date_format('2018-11-17 13:33:33.333', 'XXXXXX') -- !query schema struct<> -- !query output @@ -252,7 +228,7 @@ Too many pattern letters: X -- !query -select col, date_format(col, 'ZZZZZZ') from v +select date_format('2018-11-17 13:33:33.333', 'ZZZZZZ') -- !query schema struct<> -- !query output @@ -261,7 +237,7 @@ You may get a different result due to the upgrading of Spark 3.0: Fail to recogn -- !query -select col, date_format(col, 'OO') from v +select date_format('2018-11-17 13:33:33.333', 'OO') -- !query schema struct<> -- !query output @@ -270,7 +246,7 @@ Pattern letter count must be 1 or 4: O -- !query -select col, date_format(col, 'xxxxxx') from v +select date_format('2018-11-17 13:33:33.333', 'xxxxxx') -- !query schema struct<> -- !query output From eeceba5156a55f886525c4f0f3e3503885747169 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Thu, 4 Jun 2020 01:55:18 +0800 Subject: [PATCH 10/10] style --- .../sql-tests/inputs/datetime-formatting-invalid.sql | 4 ++-- .../test/resources/sql-tests/inputs/datetime-formatting.sql | 3 +-- .../sql-tests/results/datetime-formatting-legacy.sql.out | 4 ++-- .../resources/sql-tests/results/datetime-formatting.sql.out | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql index ddd5855165f3c..120ebdec10853 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting-invalid.sql @@ -1,6 +1,6 @@ --- TESTS FOR DATETIME FORMATTING FUNCTIONS WITH INVALID PATTERNS --- --- separating this from datetime-formatting.sql ,because the text form +-- separating this from datetime-formatting.sql, because the text form -- for patterns with 5 letters in SimpleDateFormat varies from different JDKs select date_format('2018-11-17 13:33:33.333', 'GGGGG'); -- pattern letter count can not be greater than 10 @@ -17,7 +17,7 @@ select date_format('2018-11-17 13:33:33.333', 'uuuuu'); select date_format('2018-11-17 13:33:33.333', 'EEEEE'); select date_format('2018-11-17 13:33:33.333', 'FF'); select date_format('2018-11-17 13:33:33.333', 'ddd'); --- DD is invalid in 8, but valid in 11 for the JDKs that PR builder uses +-- DD is invalid if the day-of-year exceeds 100, but it becomes valid in Java 11 -- select date_format('2018-11-17 13:33:33.333', 'DD'); select date_format('2018-11-17 13:33:33.333', 'DDDD'); select date_format('2018-11-17 13:33:33.333', 'HHH'); diff --git a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql index 391e018627e93..462772a3d370d 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/datetime-formatting.sql @@ -52,8 +52,7 @@ select col, date_format(col, 's ss') from v; select col, date_format(col, 'S SS SSS SSSS SSSSS SSSSSS SSSSSSS SSSSSSSS SSSSSSSSS') from v; --- add upper function here to avoid -select col, upper(date_format(col, 'a')) from v; +select col, date_format(col, 'a') from v; select col, date_format(col, 'VV') from v; diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out index d84d3b02a4999..7224f3f68d7a2 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting-legacy.sql.out @@ -310,9 +310,9 @@ struct +struct -- !query output 1582-05-31 19:40:35.123 PM 1969-12-31 15:00:00 PM diff --git a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out index 6f7a18057d576..a066154e91f3c 100644 --- a/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/datetime-formatting.sql.out @@ -320,9 +320,9 @@ struct +struct -- !query output 1582-05-31 19:40:35.123 PM 1969-12-31 15:00:00 PM