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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.1.0
    • 2.0.3, 2.1.1, 2.2.0
    • SQL
    • 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

            hvanhovell Herman van Hövell
            stanzhai StanZhai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: