Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SqlParser extends AbstractSparkSQLParser with DataTypeParser {
protected val CAST = Keyword("CAST")
protected val COALESCE = Keyword("COALESCE")
protected val COUNT = Keyword("COUNT")
protected val CROSS = Keyword("CROSS")
protected val DESC = Keyword("DESC")
protected val DISTINCT = Keyword("DISTINCT")
protected val ELSE = Keyword("ELSE")
Expand Down Expand Up @@ -164,7 +165,7 @@ class SqlParser extends AbstractSparkSQLParser with DataTypeParser {
// Based very loosely on the MySQL Grammar.
// http://dev.mysql.com/doc/refman/5.0/en/join.html
protected lazy val relations: Parser[LogicalPlan] =
( relation ~ rep1("," ~> relation) ^^ {
( relation ~ rep1(("," | CROSS ~ JOIN) ~> relation) ^^ {
case r1 ~ joins => joins.foldLeft(r1) { case(lhs, r) => Join(lhs, r, Inner, None) } }
| relation
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ class SqlParserSuite extends FunSuite {
assert(TestCommand("NotRealCommand") === parser("execute NotRealCommand"))
assert(TestCommand("NotRealCommand") === parser("exEcute NotRealCommand"))
}

test("cross join") {
val parser = new SqlParser
assert(parser("SELECT * FROM t1, t2") === parser("SELECT * FROM t1 CROSS JOIN t2"))
intercept[RuntimeException](parser("SELECT * FROM t1 CROSS JOIN t2 ON t1.a = t2.a"))
}

}