You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by hv...@apache.org on 2016/02/11 08:31:17 UTC
spark git commit: [SPARK-13276] Catch bad characters at the end of a
Table Identifier/Expression string
Repository: spark
Updated Branches:
refs/heads/master 8f744fe3d -> 1842c55d8
[SPARK-13276] Catch bad characters at the end of a Table Identifier/Expression string
The parser currently parses the following strings without a hitch:
* Table Identifier:
* `a.b.c` should fail, but results in the following table identifier `a.b`
* `table!#` should fail, but results in the following table identifier `table`
* Expression
* `1+2 r+e` should fail, but results in the following expression `1 + 2`
This PR fixes this by adding terminated rules for both expression parsing and table identifier parsing.
cc cloud-fan (we discussed this in https://github.com/apache/spark/pull/10649) jayadevanmurali (this causes your PR https://github.com/apache/spark/pull/11051 to fail)
Author: Herman van Hovell <hv...@questtec.nl>
Closes #11159 from hvanhovell/SPARK-13276.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/1842c55d
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/1842c55d
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/1842c55d
Branch: refs/heads/master
Commit: 1842c55d89ae99a610a955ce61633a9084e000f2
Parents: 8f744fe
Author: Herman van Hovell <hv...@questtec.nl>
Authored: Thu Feb 11 08:30:58 2016 +0100
Committer: Herman van Hovell <hv...@questtec.nl>
Committed: Thu Feb 11 08:30:58 2016 +0100
----------------------------------------------------------------------
.../apache/spark/sql/catalyst/parser/SparkSqlParser.g | 12 ++++++++++++
.../apache/spark/sql/catalyst/parser/ParseDriver.scala | 4 ++--
.../org/apache/spark/sql/catalyst/CatalystQlSuite.scala | 5 +++--
3 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/1842c55d/sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g b/sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g
index 9935678..9f2a5eb 100644
--- a/sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g
+++ b/sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g
@@ -722,6 +722,18 @@ statement
| (KW_SET)=> KW_SET -> ^(TOK_SETCONFIG)
;
+// Rule for expression parsing
+singleNamedExpression
+ :
+ namedExpression EOF
+ ;
+
+// Rule for table name parsing
+singleTableName
+ :
+ tableName EOF
+ ;
+
explainStatement
@init { pushMsg("explain statement", state); }
@after { popMsg(state); }
http://git-wip-us.apache.org/repos/asf/spark/blob/1842c55d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala
index f8e4f21..9ff41f5 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala
@@ -35,12 +35,12 @@ object ParseDriver extends Logging {
/** Create an Expression ASTNode from a SQL command. */
def parseExpression(command: String, conf: ParserConf): ASTNode = parse(command, conf) { parser =>
- parser.namedExpression().getTree
+ parser.singleNamedExpression().getTree
}
/** Create an TableIdentifier ASTNode from a SQL command. */
def parseTableName(command: String, conf: ParserConf): ASTNode = parse(command, conf) { parser =>
- parser.tableName().getTree
+ parser.singleTableName().getTree
}
private def parse(
http://git-wip-us.apache.org/repos/asf/spark/blob/1842c55d/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala
index 6d25de9..682b77d 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/CatalystQlSuite.scala
@@ -134,14 +134,15 @@ class CatalystQlSuite extends PlanTest {
Literal("o") ::
UnresolvedFunction("o", UnresolvedAttribute("bar") :: Nil, false) ::
Nil, false)))
+
+ intercept[AnalysisException](parser.parseExpression("1 - f('o', o(bar)) hello * world"))
}
test("table identifier") {
assert(TableIdentifier("q") === parser.parseTableIdentifier("q"))
assert(TableIdentifier("q", Some("d")) === parser.parseTableIdentifier("d.q"))
intercept[AnalysisException](parser.parseTableIdentifier(""))
- // TODO parser swallows third identifier.
- // intercept[AnalysisException](parser.parseTableIdentifier("d.q.g"))
+ intercept[AnalysisException](parser.parseTableIdentifier("d.q.g"))
}
test("parse union/except/intersect") {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org