Skip to content

Commit 208bf5e

Browse files
committed
More idiomatic naming of DSL functions.
* subquery => as * for join condition => on, i.e., `r.join(s, condition = 'a == 'b)` =>`r.join(s, on = 'a == 'b)`
1 parent 87211ce commit 208bf5e

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class SchemaRDD(
157157
def join(
158158
otherPlan: SchemaRDD,
159159
joinType: JoinType = Inner,
160-
condition: Option[Expression] = None): SchemaRDD =
161-
new SchemaRDD(sqlContext, Join(logicalPlan, otherPlan.logicalPlan, joinType, condition))
160+
on: Option[Expression] = None): SchemaRDD =
161+
new SchemaRDD(sqlContext, Join(logicalPlan, otherPlan.logicalPlan, joinType, on))
162162

163163
/**
164164
* Sorts the results by the given expressions.
@@ -195,14 +195,14 @@ class SchemaRDD(
195195
* with the same name, for example, when peforming self-joins.
196196
*
197197
* {{{
198-
* val x = schemaRDD.where('a === 1).subquery('x)
199-
* val y = schemaRDD.where('a === 2).subquery('y)
198+
* val x = schemaRDD.where('a === 1).as('x)
199+
* val y = schemaRDD.where('a === 2).as('y)
200200
* x.join(y).where("x.a".attr === "y.a".attr),
201201
* }}}
202202
*
203203
* @group Query
204204
*/
205-
def subquery(alias: Symbol) =
205+
def as(alias: Symbol) =
206206
new SchemaRDD(sqlContext, Subquery(alias.name, logicalPlan))
207207

208208
/**

sql/core/src/test/scala/org/apache/spark/sql/DslQuerySuite.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class DslQuerySuite extends QueryTest {
119119
}
120120

121121
test("inner join, where, multiple matches") {
122-
val x = testData2.where('a === 1).subquery('x)
123-
val y = testData2.where('a === 1).subquery('y)
122+
val x = testData2.where('a === 1).as('x)
123+
val y = testData2.where('a === 1).as('y)
124124
checkAnswer(
125125
x.join(y).where("x.a".attr === "y.a".attr),
126126
(1,1,1,1) ::
@@ -131,17 +131,17 @@ class DslQuerySuite extends QueryTest {
131131
}
132132

133133
test("inner join, no matches") {
134-
val x = testData2.where('a === 1).subquery('x)
135-
val y = testData2.where('a === 2).subquery('y)
134+
val x = testData2.where('a === 1).as('x)
135+
val y = testData2.where('a === 2).as('y)
136136
checkAnswer(
137137
x.join(y).where("x.a".attr === "y.a".attr),
138138
Nil)
139139
}
140140

141141
test("big inner join, 4 matches per row") {
142142
val bigData = testData.unionAll(testData).unionAll(testData).unionAll(testData)
143-
val bigDataX = bigData.subquery('x)
144-
val bigDataY = bigData.subquery('y)
143+
val bigDataX = bigData.as('x)
144+
val bigDataY = bigData.as('y)
145145

146146
checkAnswer(
147147
bigDataX.join(bigDataY).where("x.key".attr === "y.key".attr),
@@ -181,8 +181,8 @@ class DslQuerySuite extends QueryTest {
181181
}
182182

183183
test("full outer join") {
184-
val left = upperCaseData.where('N <= 4).subquery('left)
185-
val right = upperCaseData.where('N >= 3).subquery('right)
184+
val left = upperCaseData.where('N <= 4).as('left)
185+
val right = upperCaseData.where('N >= 3).as('right)
186186

187187
checkAnswer(
188188
left.join(right, FullOuter, Some("left.N".attr === "right.N".attr)),

sql/core/src/test/scala/org/apache/spark/sql/parquet/ParquetQuerySuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class ParquetQuerySuite extends FunSuite with BeforeAndAfterAll {
5656
}
5757

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

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

0 commit comments

Comments
 (0)