Skip to content

Commit

Permalink
Adds multiple join support for SQLContext
Browse files Browse the repository at this point in the history
  • Loading branch information
liancheng committed Oct 14, 2014
1 parent 9eb49d4 commit 9dc0d18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ class SqlParser extends AbstractSparkSQLParser {
)

protected lazy val joinedRelation: Parser[LogicalPlan] =
relationFactor ~ joinType.? ~ (JOIN ~> relationFactor) ~ joinConditions.? ^^ {
case r1 ~ jt ~ r2 ~ cond =>
Join(r1, r2, joinType = jt.getOrElse(Inner), cond)
relationFactor ~ rep1(joinType.? ~ (JOIN ~> relationFactor) ~ joinConditions.?) ^^ {
case r1 ~ joins =>
joins.foldLeft(r1) { case (lhs, jt ~ rhs ~ cond) =>
Join(lhs, rhs, joinType = jt.getOrElse(Inner), cond)
}
}

protected lazy val joinConditions: Parser[Expression] =
Expand Down
11 changes: 11 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,15 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
checkAggregation("SELECT key + 2, COUNT(*) FROM testData GROUP BY key + 1")
checkAggregation("SELECT key + 1 + 1, COUNT(*) FROM testData GROUP BY key + 1", false)
}

test("Multiple join") {
checkAnswer(
sql(
"""SELECT a.key, b.key, c.key
|FROM testData a
|JOIN testData b ON a.key = b.key
|JOIN testData c ON a.key = c.key
""".stripMargin),
(1 to 100).map(i => Seq(i, i, i)))
}
}

0 comments on commit 9dc0d18

Please sign in to comment.