Skip to content

Commit

Permalink
modify according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jackylk committed Feb 26, 2015
1 parent 981be52 commit d7acc18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def isLocal(self):
"""
return self._jdf.isLocal()

def show(self, numRows=20):
def show(self, n=20):
"""
Print the first n rows.
Expand All @@ -283,7 +283,7 @@ def show(self, numRows=20):
2 Alice
5 Bob
"""
print self._jdf.showString(numRows).encode('utf8', 'ignore')
print self._jdf.showString(n).encode('utf8', 'ignore')

def __repr__(self):
return "DataFrame[%s]" % (", ".join("%s: %s" % c for c in self.dtypes))
Expand Down
5 changes: 2 additions & 3 deletions sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ class DataFrame protected[sql](
* Internal API for Python
* @param numRows Number of rows to show
*/
private[sql] def showString(numRows: Int = 20): String = {
val size = count()
val data = if (numRows > size) collect() else take(numRows)
private[sql] def showString(numRows: Int): String = {
val data = take(numRows)
val numCols = schema.fieldNames.length

// For cells that are beyond 20 characters, replace it with the first 17 and "..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ public void testVarargMethods() {
df.groupBy().agg(countDistinct(col("key"), col("value")));
df.select(coalesce(col("key")));
}

@Test
public void testShow() {
DataFrame df = context.table("testData");
df.show(10);
df.show(1000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,8 @@ class DataFrameSuite extends QueryTest {
checkAnswer(df.select(df("key")), testData.select('key).collect().toSeq)
}

test("show") {
testData.select($"*").show()
testData.select($"*").show(1000)
}
}

0 comments on commit d7acc18

Please sign in to comment.