You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ya...@apache.org on 2020/03/26 23:10:13 UTC

[spark] branch master updated: [SPARK-31262][SQL][TESTS] Fix bug tests imported bracketed comments

This is an automated email from the ASF dual-hosted git repository.

yamamuro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e0fee9  [SPARK-31262][SQL][TESTS] Fix bug tests imported bracketed comments
9e0fee9 is described below

commit 9e0fee933e62eb309d4aa32bb1e5126125d0bf9f
Author: beliefer <be...@163.com>
AuthorDate: Fri Mar 27 08:09:17 2020 +0900

    [SPARK-31262][SQL][TESTS] Fix bug tests imported bracketed comments
    
    ### What changes were proposed in this pull request?
    This PR related to https://github.com/apache/spark/pull/27481.
    If test case A uses `--IMPORT` to import test case B contains bracketed comments, the output can't display bracketed comments in golden files well.
    The content of `nested-comments.sql` show below:
    ```
    -- This test case just used to test imported bracketed comments.
    
    -- the first case of bracketed comment
    --QUERY-DELIMITER-START
    /* This is the first example of bracketed comment.
    SELECT 'ommented out content' AS first;
    */
    SELECT 'selected content' AS first;
    --QUERY-DELIMITER-END
    ```
    The test case `comments.sql` imports `nested-comments.sql` below:
    `--IMPORT nested-comments.sql`
    Before this PR, the output will be:
    ```
    -- !query
    /* This is the first example of bracketed comment.
    SELECT 'ommented out content' AS first
    -- !query schema
    struct<>
    -- !query output
    org.apache.spark.sql.catalyst.parser.ParseException
    
    mismatched input '/' expecting {'(', 'ADD', 'ALTER', 'ANALYZE', 'CACHE', 'CLEAR', 'COMMENT', 'COMMIT', 'CREATE', 'DELETE', 'DESC', 'DESCRIBE', 'DFS', 'DROP',
    'EXPLAIN', 'EXPORT', 'FROM', 'GRANT', 'IMPORT', 'INSERT', 'LIST', 'LOAD', 'LOCK', 'MAP', 'MERGE', 'MSCK', 'REDUCE', 'REFRESH', 'REPLACE', 'RESET', 'REVOKE', '
    ROLLBACK', 'SELECT', 'SET', 'SHOW', 'START', 'TABLE', 'TRUNCATE', 'UNCACHE', 'UNLOCK', 'UPDATE', 'USE', 'VALUES', 'WITH'}(line 1, pos 0)
    
    == SQL ==
    /* This is the first example of bracketed comment.
    ^^^
    SELECT 'ommented out content' AS first
    
    -- !query
    */
    SELECT 'selected content' AS first
    -- !query schema
    struct<>
    -- !query output
    org.apache.spark.sql.catalyst.parser.ParseException
    
    extraneous input '*/' expecting {'(', 'ADD', 'ALTER', 'ANALYZE', 'CACHE', 'CLEAR', 'COMMENT', 'COMMIT', 'CREATE', 'DELETE', 'DESC', 'DESCRIBE', 'DFS', 'DROP', 'EXPLAIN', 'EXPORT', 'FROM', 'GRANT', 'IMPORT', 'INSERT', 'LIST', 'LOAD', 'LOCK', 'MAP', 'MERGE', 'MSCK', 'REDUCE', 'REFRESH', 'REPLACE', 'RESET', 'REVOKE', 'ROLLBACK', 'SELECT', 'SET', 'SHOW', 'START', 'TABLE', 'TRUNCATE', 'UNCACHE', 'UNLOCK', 'UPDATE', 'USE', 'VALUES', 'WITH'}(line 1, pos 0)
    
    == SQL ==
    */
    ^^^
    SELECT 'selected content' AS first
    ```
    After this PR, the output will be:
    ```
    -- !query
    /* This is the first example of bracketed comment.
    SELECT 'ommented out content' AS first;
    */
    SELECT 'selected content' AS first
    -- !query schema
    struct<first:string>
    -- !query output
    selected content
    ```
    
    ### Why are the changes needed?
    Golden files can't display the bracketed comments in imported test cases.
    
    ### Does this PR introduce any user-facing change?
    'No'.
    
    ### How was this patch tested?
    New UT.
    
    Closes #28018 from beliefer/fix-bug-tests-imported-bracketed-comments.
    
    Authored-by: beliefer <be...@163.com>
    Signed-off-by: Takeshi Yamamuro <ya...@apache.org>
---
 .../src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala  | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

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 6c66166..848966a 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
@@ -256,20 +256,23 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession {
     def splitWithSemicolon(seq: Seq[String]) = {
       seq.mkString("\n").split("(?<=[^\\\\]);")
     }
-    val input = fileToString(new File(testCase.inputFile))
 
-    val (comments, code) = input.split("\n").partition { line =>
+    def splitCommentsAndCodes(input: String) = input.split("\n").partition { line =>
       val newLine = line.trim
       newLine.startsWith("--") && !newLine.startsWith("--QUERY-DELIMITER")
     }
 
+    val input = fileToString(new File(testCase.inputFile))
+
+    val (comments, code) = splitCommentsAndCodes(input)
+
     // 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 importedCode = importedTestCaseName.flatMap { testCaseName =>
       listTestCases.find(_.name == testCaseName).map { testCase =>
         val input = fileToString(new File(testCase.inputFile))
-        val (_, code) = input.split("\n").partition(_.trim.startsWith("--"))
+        val (_, code) = splitCommentsAndCodes(input)
         code
       }
     }.flatten


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org