[SPARK-1778] [SQL] Add 'limit' transformation to SchemaRDD.
Add `limit` transformation to `SchemaRDD`. Author: Takuya UESHIN <ueshin@happy-camper.st> Closes #711 from ueshin/issues/SPARK-1778 and squashes the following commits: 33169df [Takuya UESHIN] Add 'limit' transformation to SchemaRDD.
This commit is contained in:
parent
4d60553298
commit
8e94d2721a
|
@ -178,6 +178,15 @@ class SchemaRDD(
|
|||
def orderBy(sortExprs: SortOrder*): SchemaRDD =
|
||||
new SchemaRDD(sqlContext, Sort(sortExprs, logicalPlan))
|
||||
|
||||
/**
|
||||
* Limits the results by the given expressions.
|
||||
* {{{
|
||||
* schemaRDD.limit(10)
|
||||
* }}}
|
||||
*/
|
||||
def limit(limitExpr: Expression): SchemaRDD =
|
||||
new SchemaRDD(sqlContext, Limit(limitExpr, logicalPlan))
|
||||
|
||||
/**
|
||||
* Performs a grouping followed by an aggregation.
|
||||
*
|
||||
|
|
|
@ -71,6 +71,12 @@ class DslQuerySuite extends QueryTest {
|
|||
Seq((3,1), (3,2), (2,1), (2,2), (1,1), (1,2)))
|
||||
}
|
||||
|
||||
test("limit") {
|
||||
checkAnswer(
|
||||
testData.limit(10),
|
||||
testData.take(10).toSeq)
|
||||
}
|
||||
|
||||
test("average") {
|
||||
checkAnswer(
|
||||
testData2.groupBy()(Average('a)),
|
||||
|
|
Loading…
Reference in a new issue