Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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