Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-38384 Improve error messages of ParseException from ANTLR
  3. SPARK-38385

Improve error messages of 'mismatched input' cases from ANTLR

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3.0
    • 3.3.0
    • SQL
    • None

    Description

      Please view the parent task description for the general idea: https://issues.apache.org/jira/browse/SPARK-38384

      Mismatched Input

      Case 1

      Before

      ParseException: 
      mismatched input 'sel' expecting {'(', 'APPLY', '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', 'SYNC', 'TABLE', 'TRUNCATE', 'UNCACHE', 'UNLOCK', 'UPDATE', 'USE', 'VALUES', 'WITH'}(line 1, pos 0)
      
      == SQL ==
      sel 1
      ^^^ 

      After

      ParseException: 
      syntax error at or near 'sel'(line 1, pos 0)
      
      == SQL ==
      sel 1
      ^^^ 

      Changes:

      1. Adjust the words, from ‘mismatched input {}’ to more readable one, ‘syntax error at or near {}.’. This also aligns with the PostgreSQL error messages. 
      2. Remove the expecting full list.

      Case 2

      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 empty SQL statement(line 1, pos 0)
      
      == SQL ==
      
      ^^^

      Changes:

      1. For empty query, output a specific error message ‘syntax error, unexpected empty SQL statement’

      Case 3

      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:

      1. For the faulty token <EOF>, substitute it to a readable string ‘end of input’.

      Attachments

        Activity

          People

            xyyu Xinyi Yu
            xyyu Xinyi Yu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: