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
2 changes: 1 addition & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Dataset[T] private[sql](
*/
private[sql] def showString(
_numRows: Int, truncate: Int = 20, vertical: Boolean = false): String = {
val numRows = _numRows.max(0)
val numRows = _numRows.max(0).min(Int.MaxValue - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but now you return one fewer row than expected when it's possible to return Int.MaxValue. Granted this is an extreme corner case, but that seems less compelling than just skipping the display of "more elements" in this case.

Copy link
Member Author

@maropu maropu Oct 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I see. Both is okay to me and WDYT? cc: @gatorsmile
IMHO it might be still okay to set [0, Int.MaxValue) as valid range for show cuz this is a corner case.

Copy link
Member

@gatorsmile gatorsmile Oct 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataFrame.show() does not work when the number of rows is close to Int.MaxValue. The driver will be OOM before finishing the command. Thus, I do not think we can hit this extreme case.

val takeResult = toDF().take(numRows + 1)
val hasMoreData = takeResult.length > numRows
val data = takeResult.take(numRows)
Expand Down
12 changes: 12 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,18 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
assert(testData.select($"*").showString(0) === expectedAnswer)
}

test("showString(Int.MaxValue)") {
val df = Seq((1, 2), (3, 4)).toDF("a", "b")
val expectedAnswer = """+---+---+
|| a| b|
|+---+---+
|| 1| 2|
|| 3| 4|
|+---+---+
|""".stripMargin
assert(df.showString(Int.MaxValue) === expectedAnswer)
}

test("showString(0), vertical = true") {
val expectedAnswer = "(0 rows)\n"
assert(testData.select($"*").showString(0, vertical = true) === expectedAnswer)
Expand Down