Skip to content

Commit d9ded1f

Browse files
committed
[SPARK-6744][SQL] Add support for CROSS JOIN syntax.
1 parent 67d0688 commit d9ded1f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SqlParser extends AbstractSparkSQLParser with DataTypeParser {
6161
protected val CAST = Keyword("CAST")
6262
protected val COALESCE = Keyword("COALESCE")
6363
protected val COUNT = Keyword("COUNT")
64+
protected val CROSS = Keyword("CROSS")
6465
protected val DESC = Keyword("DESC")
6566
protected val DISTINCT = Keyword("DISTINCT")
6667
protected val ELSE = Keyword("ELSE")
@@ -164,7 +165,7 @@ class SqlParser extends AbstractSparkSQLParser with DataTypeParser {
164165
// Based very loosely on the MySQL Grammar.
165166
// http://dev.mysql.com/doc/refman/5.0/en/join.html
166167
protected lazy val relations: Parser[LogicalPlan] =
167-
( relation ~ rep1("," ~> relation) ^^ {
168+
( relation ~ rep1(("," | CROSS ~ JOIN) ~> relation) ^^ {
168169
case r1 ~ joins => joins.foldLeft(r1) { case(lhs, r) => Join(lhs, r, Inner, None) } }
169170
| relation
170171
)

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/SqlParserSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ class SqlParserSuite extends FunSuite {
5858
assert(TestCommand("NotRealCommand") === parser("execute NotRealCommand"))
5959
assert(TestCommand("NotRealCommand") === parser("exEcute NotRealCommand"))
6060
}
61+
62+
test("cross join") {
63+
val parser = new SqlParser
64+
assert(parser("SELECT * FROM t1, t2") === parser("SELECT * FROM t1 CROSS JOIN t2"))
65+
intercept[RuntimeException](parser("SELECT * FROM t1 CROSS JOIN t2 ON t1.a = t2.a"))
66+
}
67+
6168
}

0 commit comments

Comments
 (0)