Skip to content

Commit

Permalink
SPARK-1822: Some minor cleanup work on SchemaRDD.count()
Browse files Browse the repository at this point in the history
Minor cleanup following mesos#841.

Author: Reynold Xin <[email protected]>

Closes mesos#868 from rxin/schema-count and squashes the following commits:

5442651 [Reynold Xin] SPARK-1822: Some minor cleanup work on SchemaRDD.count()
  • Loading branch information
rxin committed May 25, 2014
1 parent 5c7faec commit d66642e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/pyspark/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ def saveAsTable(self, tableName):

def count(self):
"""
Return the number of elements in this RDD.
Return the number of elements in this RDD. Unlike the base RDD
implementation of count, this implementation leverages the query
optimizer to compute the count on the SchemaRDD, which supports
features such as filter pushdown.
>>> srdd = sqlCtx.inferSchema(rdd)
>>> srdd.count()
Expand Down
8 changes: 4 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ class SchemaRDD(

/**
* :: Experimental ::
* Overriding base RDD implementation to leverage query optimizer
* Return the number of elements in the RDD. Unlike the base RDD implementation of count, this
* implementation leverages the query optimizer to compute the count on the SchemaRDD, which
* supports features such as filter pushdown.
*/
@Experimental
override def count(): Long = {
groupBy()(Count(Literal(1))).collect().head.getLong(0)
}
override def count(): Long = groupBy()(Count(Literal(1))).collect().head.getLong(0)

/**
* :: Experimental ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DslQuerySuite extends QueryTest {
}

test("zero count") {
assert(testData4.count() === 0)
assert(emptyTableData.count() === 0)
}

test("inner join where, one match per row") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object TestData {
(1, null) ::
(2, 2) :: Nil)

val testData4 = logical.LocalRelation('a.int, 'b.int)
val emptyTableData = logical.LocalRelation('a.int, 'b.int)

case class UpperCaseData(N: Int, L: String)
val upperCaseData =
Expand Down

0 comments on commit d66642e

Please sign in to comment.