From 02c33524028921bc08f0f55a940b2e943595cd93 Mon Sep 17 00:00:00 2001 From: yangjie01 Date: Mon, 27 Mar 2023 11:19:56 +0900 Subject: [PATCH] [SPARK-42921][SQL][TESTS] Split `timestampNTZ/datetime-special.sql` into w/ and w/o `ansi` suffix to pass sql analyzer test in ansi mode ### What changes were proposed in this pull request? After https://github.com/apache/spark/pull/40496, run ``` SPARK_ANSI_SQL_MODE=true build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite" ``` There is one test faild with `spark.sql.ansi.enabled = true` ``` [info] - timestampNTZ/datetime-special.sql_analyzer_test *** FAILED *** (11 milliseconds) [info] timestampNTZ/datetime-special.sql_analyzer_test [info] Expected "...date(999999, 3, 18, [false) AS make_date(999999, 3, 18)#x, make_date(-1, 1, 28, fals]e) AS make_date(-1, ...", but got "...date(999999, 3, 18, [true) AS make_date(999999, 3, 18)#x, make_date(-1, 1, 28, tru]e) AS make_date(-1, ..." Result did not match for query #1 [info] select make_date(999999, 3, 18), make_date(-1, 1, 28) (SQLQueryTestSuite.scala:777) [info] org.scalatest.exceptions.TestFailedException: ``` The failure reason is the last parameter of function `MakeDate` is `failOnError: Boolean = SQLConf.get.ansiEnabled`. So this pr split `timestampNTZ/datetime-special.sql` into w/ and w/o ansi to mask this test difference. ### Why are the changes needed? Make SQLQueryTestSuite test pass with `spark.sql.ansi.enabled = true`. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass GitHub Actions - Manual checked `SPARK_ANSI_SQL_MODE=true build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"` Closes #40552 from LuciferYang/SPARK-42921. Authored-by: yangjie01 Signed-off-by: Hyukjin Kwon --- .../datetime-special-ansi.sql.out | 26 ++++++++++++++++ .../timestampNTZ/datetime-special-ansi.sql | 2 ++ .../inputs/timestampNTZ/datetime-special.sql | 1 + .../datetime-special-ansi.sql.out | 31 +++++++++++++++++++ .../ThriftServerQueryTestSuite.scala | 4 ++- 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/datetime-special-ansi.sql.out create mode 100644 sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special-ansi.sql create mode 100644 sql/core/src/test/resources/sql-tests/results/timestampNTZ/datetime-special-ansi.sql.out diff --git a/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/datetime-special-ansi.sql.out b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/datetime-special-ansi.sql.out new file mode 100644 index 0000000000000..0f8ad6eb2ccfb --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/analyzer-results/timestampNTZ/datetime-special-ansi.sql.out @@ -0,0 +1,26 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +select date'999999-03-18', date'-0001-1-28', date'0015' +-- !query analysis +[Analyzer test output redacted due to nondeterminism] + + +-- !query +select make_date(999999, 3, 18), make_date(-1, 1, 28) +-- !query analysis +Project [make_date(999999, 3, 18, true) AS make_date(999999, 3, 18)#x, make_date(-1, 1, 28, true) AS make_date(-1, 1, 28)#x] ++- OneRowRelation + + +-- !query +select timestamp'-1969-12-31 16:00:00', timestamp'-0015-03-18 16:00:00', timestamp'-000001', timestamp'99999-03-18T12:03:17' +-- !query analysis +Project [-1969-12-31 16:00:00 AS TIMESTAMP_NTZ '-1969-12-31 16:00:00'#x, -0015-03-18 16:00:00 AS TIMESTAMP_NTZ '-0015-03-18 16:00:00'#x, -0001-01-01 00:00:00 AS TIMESTAMP_NTZ '-0001-01-01 00:00:00'#x, +99999-03-18 12:03:17 AS TIMESTAMP_NTZ '+99999-03-18 12:03:17'#x] ++- OneRowRelation + + +-- !query +select make_timestamp(-1969, 12, 31, 16, 0, 0.0), make_timestamp(-15, 3, 18, 16, 0, 0.0), make_timestamp(99999, 3, 18, 12, 3, 17.0) +-- !query analysis +Project [make_timestamp(-1969, 12, 31, 16, 0, cast(0.0 as decimal(16,6)), None, Some(America/Los_Angeles), true, TimestampNTZType) AS make_timestamp(-1969, 12, 31, 16, 0, 0.0)#x, make_timestamp(-15, 3, 18, 16, 0, cast(0.0 as decimal(16,6)), None, Some(America/Los_Angeles), true, TimestampNTZType) AS make_timestamp(-15, 3, 18, 16, 0, 0.0)#x, make_timestamp(99999, 3, 18, 12, 3, cast(17.0 as decimal(16,6)), None, Some(America/Los_Angeles), true, TimestampNTZType) AS make_timestamp(99999, 3, 18, 12, 3, 17.0)#x] ++- OneRowRelation diff --git a/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special-ansi.sql b/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special-ansi.sql new file mode 100644 index 0000000000000..527f81fa5abff --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special-ansi.sql @@ -0,0 +1,2 @@ +--SET spark.sql.ansi.enabled = true +--IMPORT datetime-special.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special.sql b/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special.sql index 87a5986ae9a9c..a9aa3f3f6a3ac 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/timestampNTZ/datetime-special.sql @@ -1 +1,2 @@ +--SET spark.sql.ansi.enabled = false --IMPORT datetime-special.sql diff --git a/sql/core/src/test/resources/sql-tests/results/timestampNTZ/datetime-special-ansi.sql.out b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/datetime-special-ansi.sql.out new file mode 100644 index 0000000000000..c8cdec4eeb984 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/timestampNTZ/datetime-special-ansi.sql.out @@ -0,0 +1,31 @@ +-- Automatically generated by SQLQueryTestSuite +-- !query +select date'999999-03-18', date'-0001-1-28', date'0015' +-- !query schema +struct +-- !query output ++999999-03-18 -0001-01-28 0015-01-01 + + +-- !query +select make_date(999999, 3, 18), make_date(-1, 1, 28) +-- !query schema +struct +-- !query output ++999999-03-18 -0001-01-28 + + +-- !query +select timestamp'-1969-12-31 16:00:00', timestamp'-0015-03-18 16:00:00', timestamp'-000001', timestamp'99999-03-18T12:03:17' +-- !query schema +struct +-- !query output +-1969-12-31 16:00:00 -0015-03-18 16:00:00 -0001-01-01 00:00:00 +99999-03-18 12:03:17 + + +-- !query +select make_timestamp(-1969, 12, 31, 16, 0, 0.0), make_timestamp(-15, 3, 18, 16, 0, 0.0), make_timestamp(99999, 3, 18, 12, 3, 17.0) +-- !query schema +struct +-- !query output +-1969-12-31 16:00:00 -0015-03-18 16:00:00 +99999-03-18 12:03:17 diff --git a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala index cf0184f6608da..5eebd751a3c5f 100644 --- a/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala +++ b/sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerQueryTestSuite.scala @@ -98,7 +98,9 @@ class ThriftServerQueryTestSuite extends SQLQueryTestSuite with SharedThriftServ "subquery/in-subquery/in-group-by.sql", "subquery/in-subquery/simple-in.sql", "subquery/in-subquery/in-order-by.sql", - "subquery/in-subquery/in-set-operations.sql" + "subquery/in-subquery/in-set-operations.sql", + // SPARK-42921 + "timestampNTZ/datetime-special-ansi.sql" ) override def runQueries(