You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/08 23:18:26 UTC

[GitHub] [spark] anchovYu opened a new pull request #35777: [SPARK-38385][SQL] Improve error messages of empty statement and in ParseException

anchovYu opened a new pull request #35777:
URL: https://github.com/apache/spark/pull/35777


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   This PR handles the case 2 and 3 mentioned in https://issues.apache.org/jira/browse/SPARK-38385.
   Specially,
   1. For empty query, output a specific error message ‘syntax error, unexpected SQL statement’
       * Before
           ```
           ParseException: 
           mismatched input '<EOF>' expecting {'(', 'CONVERT', 'COPY', 'OPTIMIZE', 'RESTORE', '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 ==
           
           ^^^ 
           ```
       * After
           ```
           ParseException: 
           syntax error, unexpected SQL statement(line 1, pos 0)
           
           == SQL ==
           
           ^^^
           ```
   
   2. For the faulty token <EOF>, substitute it to a readable string ‘end of input’.
       * Before
           ```
           ParseException: 
           mismatched input '<EOF>' expecting {'APPLY', 'CALLED', 'CHANGES', 'CLONE', 'COLLECT', 'CONTAINS', 'CONVERT', 'COPY', 'COPY_OPTIONS', 'CREDENTIAL', 'CREDENTIALS', 'DEEP', 'DEFINER', 'DELTA', 'DETERMINISTIC', 'ENCRYPTION', 'EXPECT', 'FAIL', 'FILES',… (omit long message) 'TRIM', 'TRUE', 'TRUNCATE', 'TRY_CAST', 'TYPE', 'UNARCHIVE', 'UNBOUNDED', 'UNCACHE', 'UNION', 'UNIQUE', 'UNKNOWN', 'UNLOCK', 'UNSET', 'UPDATE', 'USE', 'USER', 'USING', 'VALUES', 'VERSION', 'VIEW', 'VIEWS', 'WHEN', 'WHERE', 'WINDOW', 'WITH', 'WITHIN', 'YEAR', 'ZONE', IDENTIFIER, BACKQUOTED_IDENTIFIER}(line 1, pos 11)
           
           == SQL ==
           select 1  (
           -----------^^^ 
           ```
       * After
           ```
           ParseException: 
           syntax error at or near end of input(line 1, pos 11)
           
           == SQL ==
           select 1  (
           -----------^^^
           ```
   
   
   #### Changes in code
   * error-class.json
       Define a new type of error `PARSE_EMPTY_STATEMENT`
       ```json
         "PARSE_EMPTY_STATEMENT" : {
           "message" : [ "Syntax error, unexpected empty statement" ],
           "sqlState" : "42000"
         },
       ```
   
   * ParserDriver.scala
       Let the `PARSE_EMPTY_STATEMENT` error class overrides the `PARSE_INPUT_MISMATCHED` when cmd (the SQL) is empty. That way, the error messages for empty queries would be "unexpected empty statement".
   
   * SparkParserErrorStrategy.scala
       Define a new dictionary from the input jargon words to user-facing words. In the current mismatch input error, substitute the token to user-facing language. That way, there would be no '<EOF>'.
   
   * test suites
       Add two more testcases testing the above cases.
   
   ### Why are the changes needed?
   https://issues.apache.org/jira/browse/SPARK-38384 The description states the reason for the change.
   TLDR, the error messages of ParseException directly coming from ANTLR are not user-friendly and we want to improve it.
   
   
   ### Does this PR introduce _any_ user-facing change?
   If the error messages change are considered as user-facing change, then yes.
   The changes in the error message:
   1.  For empty query, output a specific error message ‘syntax error, unexpected SQL statement’
   2. For the faulty token <EOF>, substitute it to a readable string ‘end of input’.
   
   Example cases are listed in the top of this PR description.
   
   ### How was this patch tested?
   Unit tests.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #35777: [SPARK-38385][SQL] Improve error messages of empty statement and in ParseException

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #35777:
URL: https://github.com/apache/spark/pull/35777#issuecomment-1063595518


   Can one of the admins verify this patch?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan closed pull request #35777: [SPARK-38385][SQL] Improve error messages of empty statement and in ParseException

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #35777:
URL: https://github.com/apache/spark/pull/35777


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] anchovYu commented on a change in pull request #35777: [SPARK-38385][SQL] Improve error messages of empty statement and in ParseException

Posted by GitBox <gi...@apache.org>.
anchovYu commented on a change in pull request #35777:
URL: https://github.com/apache/spark/pull/35777#discussion_r822156954



##########
File path: sql/core/src/test/resources/sql-tests/results/show-tables.sql.out
##########
@@ -168,7 +168,7 @@ struct<>
 -- !query output
 org.apache.spark.sql.catalyst.parser.ParseException
 
-Syntax error at or near '<EOF>'(line 1, pos 19)
+Syntax error at or near end of input(line 1, pos 19)

Review comment:
       This is a example of the EOF change.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on pull request #35777: [SPARK-38385][SQL] Improve error messages of empty statement and in ParseException

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35777:
URL: https://github.com/apache/spark/pull/35777#issuecomment-1063609373


   thanks, merging to master!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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