diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql index 4068a27fcb2a..1e2424fe47ca 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/higher-order-functions.sql @@ -1 +1 @@ ---import higher-order-functions.sql +--IMPORT higher-order-functions.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql index 215ee7c074fa..087914eebb07 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/interval.sql @@ -1,4 +1,4 @@ ---import interval.sql +--IMPORT interval.sql -- the `interval` keyword can be omitted with ansi mode select 1 year 2 days; diff --git a/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql b/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql index 170690ea699c..698e8fa88630 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/ansi/literals.sql @@ -1,2 +1,2 @@ --- malformed interval literal with ansi mode ---import literals.sql +--IMPORT literals.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/interval-display-iso_8601.sql b/sql/core/src/test/resources/sql-tests/inputs/interval-display-iso_8601.sql index 62f3f43bd2c4..3b63c715a6aa 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/interval-display-iso_8601.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/interval-display-iso_8601.sql @@ -1,3 +1,3 @@ -- tests for interval output style with iso_8601 format --SET spark.sql.intervalOutputStyle = ISO_8601 ---import interval-display.sql +--IMPORT interval-display.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/interval-display-sql_standard.sql b/sql/core/src/test/resources/sql-tests/inputs/interval-display-sql_standard.sql index 375b4899e760..d96865b160bb 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/interval-display-sql_standard.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/interval-display-sql_standard.sql @@ -1,3 +1,3 @@ -- tests for interval output style with sql standard format --SET spark.sql.intervalOutputStyle = SQL_STANDARD ---import interval-display.sql +--IMPORT interval-display.sql diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index d693ff0da33c..ae0ccf556fbc 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -65,7 +65,7 @@ import org.apache.spark.tags.ExtendedSQLTest * 1. A list of SQL queries separated by semicolon. * 2. Lines starting with -- are treated as comments and ignored. * 3. Lines starting with --SET are used to run the file with the following set of configs. - * 4. Lines starting with --import are used to load queries from another test file. + * 4. Lines starting with --IMPORT are used to load queries from another test file. * * For example: * {{{ @@ -265,9 +265,9 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { val (comments, code) = input.split("\n").partition(_.trim.startsWith("--")) - // If `--import` found, load code from another test case file, then insert them + // If `--IMPORT` found, load code from another test case file, then insert them // into the head in this test. - val importedTestCaseName = comments.filter(_.startsWith("--import ")).map(_.substring(9)) + val importedTestCaseName = comments.filter(_.startsWith("--IMPORT ")).map(_.substring(9)) val importedCode = importedTestCaseName.flatMap { testCaseName => listTestCases.find(_.name == testCaseName).map { testCase => val input = fileToString(new File(testCase.inputFile)) @@ -283,13 +283,17 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession { // Fix misplacement when comment is at the end of the query. .map(_.split("\n").filterNot(_.startsWith("--")).mkString("\n")).map(_.trim).filter(_ != "") - // When we are regenerating the golden files, we don't need to set any config as they - // all need to return the same result - if (regenerateGoldenFiles || !isTestWithConfigSets) { + // When we are regenerating the golden files for test cases without '--IMPORT' specified, or + // running test cases against [[ThriftServerQueryTestSuite], we don't need to set any config as + // they all need to return the same result. + // When we use '--SET' and '--IMPORT' together for those import queries, we want to run the + // same queries from the original file but with different settings and save the answers. So the + // `--SET` will be respected in this case. + if ((regenerateGoldenFiles && importedTestCaseName.isEmpty) || !isTestWithConfigSets) { runQueries(queries, testCase, None) } else { val configSets = { - val configLines = comments.filter(_.startsWith("--SET")).map(_.substring(5)) + val configLines = comments.filter(_.startsWith("--SET ")).map(_.substring(6)) val configs = configLines.map(_.split(",").map { confAndValue => val (conf, value) = confAndValue.span(_ != '=') conf.trim -> value.substring(1).trim