Skip to content

Commit

Permalink
More idiomatic naming of DSL functions.
Browse files Browse the repository at this point in the history
* subquery => as
* for join condition => on, i.e., `r.join(s, condition = 'a == 'b)` =>`r.join(s, on = 'a == 'b)`
  • Loading branch information
marmbrus committed Apr 4, 2014
1 parent 87211ce commit 208bf5e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class SchemaRDD(
def join(
otherPlan: SchemaRDD,
joinType: JoinType = Inner,
condition: Option[Expression] = None): SchemaRDD =
new SchemaRDD(sqlContext, Join(logicalPlan, otherPlan.logicalPlan, joinType, condition))
on: Option[Expression] = None): SchemaRDD =
new SchemaRDD(sqlContext, Join(logicalPlan, otherPlan.logicalPlan, joinType, on))

/**
* Sorts the results by the given expressions.
Expand Down Expand Up @@ -195,14 +195,14 @@ class SchemaRDD(
* with the same name, for example, when peforming self-joins.
*
* {{{
* val x = schemaRDD.where('a === 1).subquery('x)
* val y = schemaRDD.where('a === 2).subquery('y)
* val x = schemaRDD.where('a === 1).as('x)
* val y = schemaRDD.where('a === 2).as('y)
* x.join(y).where("x.a".attr === "y.a".attr),
* }}}
*
* @group Query
*/
def subquery(alias: Symbol) =
def as(alias: Symbol) =
new SchemaRDD(sqlContext, Subquery(alias.name, logicalPlan))

/**
Expand Down
16 changes: 8 additions & 8 deletions sql/core/src/test/scala/org/apache/spark/sql/DslQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class DslQuerySuite extends QueryTest {
}

test("inner join, where, multiple matches") {
val x = testData2.where('a === 1).subquery('x)
val y = testData2.where('a === 1).subquery('y)
val x = testData2.where('a === 1).as('x)
val y = testData2.where('a === 1).as('y)
checkAnswer(
x.join(y).where("x.a".attr === "y.a".attr),
(1,1,1,1) ::
Expand All @@ -131,17 +131,17 @@ class DslQuerySuite extends QueryTest {
}

test("inner join, no matches") {
val x = testData2.where('a === 1).subquery('x)
val y = testData2.where('a === 2).subquery('y)
val x = testData2.where('a === 1).as('x)
val y = testData2.where('a === 2).as('y)
checkAnswer(
x.join(y).where("x.a".attr === "y.a".attr),
Nil)
}

test("big inner join, 4 matches per row") {
val bigData = testData.unionAll(testData).unionAll(testData).unionAll(testData)
val bigDataX = bigData.subquery('x)
val bigDataY = bigData.subquery('y)
val bigDataX = bigData.as('x)
val bigDataY = bigData.as('y)

checkAnswer(
bigDataX.join(bigDataY).where("x.key".attr === "y.key".attr),
Expand Down Expand Up @@ -181,8 +181,8 @@ class DslQuerySuite extends QueryTest {
}

test("full outer join") {
val left = upperCaseData.where('N <= 4).subquery('left)
val right = upperCaseData.where('N >= 3).subquery('right)
val left = upperCaseData.where('N <= 4).as('left)
val right = upperCaseData.where('N >= 3).as('right)

checkAnswer(
left.join(right, FullOuter, Some("left.N".attr === "right.N".attr)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class ParquetQuerySuite extends FunSuite with BeforeAndAfterAll {
}

test("self-join parquet files") {
val x = ParquetTestData.testData.subquery('x)
val y = ParquetTestData.testData.subquery('y)
val x = ParquetTestData.testData.as('x)
val y = ParquetTestData.testData.as('y)
val query = x.join(y).where("x.myint".attr === "y.myint".attr)

// Check to make sure that the attributes from either side of the join have unique expression
Expand Down

0 comments on commit 208bf5e

Please sign in to comment.