Skip to content
Snippets Groups Projects
Commit 9b6ebe33 authored by ravipesala's avatar ravipesala Committed by Michael Armbrust
Browse files

[SPARK-4120][SQL] Join of multiple tables with syntax like SELECT .. FROM...

[SPARK-4120][SQL] Join of multiple tables with syntax like SELECT .. FROM T1,T2,T3.. does not work in SparkSQL

Right now it works for only 2 tables like below query.
sql("SELECT * FROM records1 as a,records2 as b where a.key=b.key ")

But it does not work for more than 2 tables like below query
sql("SELECT * FROM records1 as a,records2 as b,records3 as c where a.key=b.key and a.key=c.key").

Author: ravipesala <ravindra.pesala@huawei.com>

Closes #2987 from ravipesala/multijoin and squashes the following commits:

429b005 [ravipesala] Support multiple joins
parent 68cb69da
No related branches found
No related tags found
No related merge requests found
......@@ -166,7 +166,8 @@ class SqlParser extends AbstractSparkSQLParser {
// 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 ~ ("," ~> relation) ^^ { case r1 ~ r2 => Join(r1, r2, Inner, None) }
( relation ~ rep1("," ~> relation) ^^ {
case r1 ~ joins => joins.foldLeft(r1) { case(lhs, r) => Join(lhs, r, Inner, None) } }
| relation
)
......
......@@ -899,4 +899,14 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
test("SPARK-3814 Support Bitwise ~ operator") {
checkAnswer(sql("SELECT ~key FROM testData WHERE key = 1 "), -2)
}
test("SPARK-4120 Join of multiple tables does not work in SparkSQL") {
checkAnswer(
sql(
"""SELECT a.key, b.key, c.key
|FROM testData a,testData b,testData c
|where a.key = b.key and a.key = c.key
""".stripMargin),
(1 to 100).map(i => Seq(i, i, i)))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment