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

Improve error message for unaliased subqueries in FROM clause

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.0
    • Fix Version/s: 2.3.0
    • Component/s: SQL
    • Labels:
      None

      Description

      The following query parses in branch-2.2, but doesn't parse correctly as of today's master:

      SELECT x FROM (SELECT 1 AS x)
      

      It still parses if you name the subquery in the FROM clause:

      SELECT x FROM (SELECT 1 AS x) t
      

      In master, this gives the following error:

      scala> sql("""SELECT x FROM (SELECT 1 AS x)""")
      org.apache.spark.sql.catalyst.parser.ParseException:
      mismatched input 'FROM' expecting {<EOF>, 'WHERE', 'GROUP', 'ORDER', 'HAVING', 'LIMIT', 'LATERAL', 'WINDOW', 'UNION', 'EXCEPT', 'MINUS', 'INTERSECT', 'SORT', 'CLUSTER', 'DISTRIBUTE'}(line 1, pos 9)
      
      == SQL ==
      SELECT x FROM (SELECT 1 AS x)
      ---------^^^
      
        at org.apache.spark.sql.catalyst.parser.ParseException.withCommand(ParseDriver.scala:217)
        at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:114)
        at org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:48)
        at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parsePlan(ParseDriver.scala:68)
        at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:623)
        ... 48 elided
      

      It looks like this change is intentional due to SPARK-20690, but the error message that we give here isn't very clear. I think that we should improve it so as not to confuse users.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                viirya Liang-Chi Hsieh
                Reporter:
                joshrosen Josh Rosen
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: