scala> sql("EXPLAIN FORMATTED SELECT * FROM myTable").show
org.apache.spark.sql.catalyst.parser.ParseException:
Operation not allowed: EXPLAIN FORMATTED(line 1, pos 0)
== SQL ==
EXPLAIN FORMATTED SELECT * FROM myTable
^^^
at org.apache.spark.sql.catalyst.parser.ParserUtils$.operationNotAllowed(ParserUtils.scala:39)
at org.apache.spark.sql.execution.SparkSqlAstBuilder$$anonfun$visitExplain$1.apply(SparkSqlParser.scala:275)
at org.apache.spark.sql.execution.SparkSqlAstBuilder$$anonfun$visitExplain$1.apply(SparkSqlParser.scala:273)
at org.apache.spark.sql.catalyst.parser.ParserUtils$.withOrigin(ParserUtils.scala:93)
at org.apache.spark.sql.execution.SparkSqlAstBuilder.visitExplain(SparkSqlParser.scala:273)
at org.apache.spark.sql.execution.SparkSqlAstBuilder.visitExplain(SparkSqlParser.scala:53)
at org.apache.spark.sql.catalyst.parser.SqlBaseParser$ExplainContext.accept(SqlBaseParser.java:480)
at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:42)
at org.apache.spark.sql.catalyst.parser.AstBuilder$$anonfun$visitSingleStatement$1.apply(AstBuilder.scala:66)
at org.apache.spark.sql.catalyst.parser.AstBuilder$$anonfun$visitSingleStatement$1.apply(AstBuilder.scala:66)
at org.apache.spark.sql.catalyst.parser.ParserUtils$.withOrigin(ParserUtils.scala:93)
at org.apache.spark.sql.catalyst.parser.AstBuilder.visitSingleStatement(AstBuilder.scala:65)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser$$anonfun$parsePlan$1.apply(ParseDriver.scala:62)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser$$anonfun$parsePlan$1.apply(ParseDriver.scala:61)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parse(ParseDriver.scala:90)
at org.apache.spark.sql.execution.SparkSqlParser.parse(SparkSqlParser.scala:46)
at org.apache.spark.sql.catalyst.parser.AbstractSqlParser.parsePlan(ParseDriver.scala:61)
at org.apache.spark.sql.SparkSession.sql(SparkSession.scala:617)
... 48 elided
AstBuilder — ANTLR-based SQL Parser
AstBuilder
converts a SQL string into Spark SQL’s corresponding entity (i.e. DataType, Expression, LogicalPlan or TableIdentifier
) using visit callback methods.
AstBuilder
is the AST builder of AbstractSqlParser
(i.e. the base SQL parsing infrastructure in Spark SQL).
Tip
|
Spark SQL supports SQL queries as described in SqlBase.g4. Using the file can tell you (almost) exactly what Spark SQL supports at any given time. "Almost" being that although the grammar accepts a SQL statement it can be reported as not allowed by |
Note
|
Technically,
|
Callback Method | ANTLR rule / labeled alternative | Spark SQL Entity | ||
---|---|---|---|---|
|
DescribeTableCommand logical command for |
|||
|
|
|||
|
Supports multiple comma-separated relations (that all together build an condition-less INNER JOIN) with optional LATERAL VIEW. A relation can be one of the following or a combination thereof:
|
|||
|
|
|||
|
|
|||
|
LogicalPlan for a |
|||
|
||||
|
Takes the named expression and relays to visitNamedExpression |
|||
|
LogicalPlan from a single statement
|
|||
|
|
|||
|
|
|||
|
|
Parsing Handler | LogicalPlan Added | ||
---|---|---|---|
|
|||
Generate with UnresolvedGenerator and |
|||
Hint for
|
|||
Join for a FROM clause and relation alone. The following join types are supported:
The following join criteria are supported:
Joins can be |
|||
WithWindowDefinition for window aggregates (given Used for withQueryResultClauses and withQuerySpecification with
|
Note
|
AstBuilder belongs to org.apache.spark.sql.catalyst.parser package.
|
Function Examples
The examples are handled by visitFunctionCall.
import spark.sessionState.sqlParser
scala> sqlParser.parseExpression("foo()")
res0: org.apache.spark.sql.catalyst.expressions.Expression = 'foo()
scala> sqlParser.parseExpression("foo() OVER windowSpecRef")
res1: org.apache.spark.sql.catalyst.expressions.Expression = unresolvedwindowexpression('foo(), WindowSpecReference(windowSpecRef))
scala> sqlParser.parseExpression("foo() OVER (CLUSTER BY field)")
res2: org.apache.spark.sql.catalyst.expressions.Expression = 'foo() windowspecdefinition('field, UnspecifiedFrame)