[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:
Takuya UESHIN 2014-05-10 12:03:27 -07:00 committed by Patrick Wendell
parent 4d60553298
commit 8e94d2721a
2 changed files with 15 additions and 0 deletions

View file

@ -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.
*

View file

@ -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)),