Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-19472

[SQL]SQLParser fails to resolve nested CASE WHEN statement with parentheses

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.0.3, 2.1.1, 2.2.0
    • Component/s: SQL
    • Labels:
      None

      Description

      SQLParser fails to resolve nested CASE WHEN statement like this:

      select case when
      (1) +
      case when 1>0 then 1 else 0 end = 2
      then 1 else 0 end
      from tb

      ==================== Exception ====================
      Exception in thread "main" org.apache.spark.sql.catalyst.parser.ParseException:
      mismatched input 'then' expecting

      {'.', '[', 'OR', 'AND', 'IN', NOT, 'BETWEEN', 'LIKE', RLIKE, 'IS', 'WHEN', EQ, '<=>', '<>', '!=', '<', LTE, '>', GTE, '+', '-', '*', '/', '%', 'DIV', '&', '|', '^'}

      (line 5, pos 0)

      == SQL ==

      select case when
      (1) +
      case when 1>0 then 1 else 0 end = 2
      then 1 else 0 end
      ^^^
      from tb

      But,remove parentheses will be fine:

      select case when
      1 +
      case when 1>0 then 1 else 0 end = 2
      then 1 else 0 end
      from tb

        Attachments

          Activity

            People

            • Assignee:
              hvanhovell Herman van Hovell
              Reporter:
              stanzhai StanZhai
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: