Skip to content

Commit 10b59ba

Browse files
ueshinmarmbrus
authored andcommitted
[SPARK-2428][SQL] Add except and intersect methods to SchemaRDD.
Author: Takuya UESHIN <[email protected]> Closes apache#1355 from ueshin/issues/SPARK-2428 and squashes the following commits: b6fa264 [Takuya UESHIN] Add except and intersect methods to SchemaRDD.
1 parent f5abd27 commit 10b59ba

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,26 @@ class SchemaRDD(
256256
def unionAll(otherPlan: SchemaRDD) =
257257
new SchemaRDD(sqlContext, Union(logicalPlan, otherPlan.logicalPlan))
258258

259+
/**
260+
* Performs a relational except on two SchemaRDDs
261+
*
262+
* @param otherPlan the [[SchemaRDD]] that should be excepted from this one.
263+
*
264+
* @group Query
265+
*/
266+
def except(otherPlan: SchemaRDD): SchemaRDD =
267+
new SchemaRDD(sqlContext, Except(logicalPlan, otherPlan.logicalPlan))
268+
269+
/**
270+
* Performs a relational intersect on two SchemaRDDs
271+
*
272+
* @param otherPlan the [[SchemaRDD]] that should be intersected with this one.
273+
*
274+
* @group Query
275+
*/
276+
def intersect(otherPlan: SchemaRDD): SchemaRDD =
277+
new SchemaRDD(sqlContext, Intersect(logicalPlan, otherPlan.logicalPlan))
278+
259279
/**
260280
* Filters tuples using a function over the value of the specified column.
261281
*

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,25 @@ class DslQuerySuite extends QueryTest {
168168
test("zero count") {
169169
assert(emptyTableData.count() === 0)
170170
}
171+
172+
test("except") {
173+
checkAnswer(
174+
lowerCaseData.except(upperCaseData),
175+
(1, "a") ::
176+
(2, "b") ::
177+
(3, "c") ::
178+
(4, "d") :: Nil)
179+
checkAnswer(lowerCaseData.except(lowerCaseData), Nil)
180+
checkAnswer(upperCaseData.except(upperCaseData), Nil)
181+
}
182+
183+
test("intersect") {
184+
checkAnswer(
185+
lowerCaseData.intersect(lowerCaseData),
186+
(1, "a") ::
187+
(2, "b") ::
188+
(3, "c") ::
189+
(4, "d") :: Nil)
190+
checkAnswer(lowerCaseData.intersect(upperCaseData), Nil)
191+
}
171192
}

0 commit comments

Comments
 (0)