-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-7319][SQL] Improve the output from DataFrame.show() #5865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
d11d5b9
baf839b
7d62368
30ac311
b6e690b
ced487a
7394fd5
03ef434
159b3d5
84aec3e
734369c
a1338f6
c79204b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ class DataFrame private[sql]( | |
| * @param numRows Number of rows to show | ||
| */ | ||
| private[sql] def showString(numRows: Int): String = { | ||
| val sb = new StringBuilder | ||
| val data = take(numRows) | ||
| val numCols = schema.fieldNames.length | ||
|
|
||
|
|
@@ -194,12 +195,34 @@ class DataFrame private[sql]( | |
| } | ||
| } | ||
|
|
||
| // Pad the cells | ||
| rows.map { row => | ||
| row.zipWithIndex.map { case (cell, i) => | ||
| String.format(s"%-${colWidths(i)}s", cell) | ||
| }.mkString(" ") | ||
| }.mkString("\n") | ||
| // Create SeparateLine | ||
| val sep:String = { | ||
| "+" + colWidths.map { | ||
| size => | ||
| val columnSep = new Array[Char](size) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole block is really just "-" * size |
||
| for (i <- 0 until size) | ||
| columnSep(i) = '-' | ||
| String.valueOf(columnSep) | ||
| }.mkString("+") + "+\n" | ||
| } | ||
|
|
||
| sb.append(sep) | ||
|
|
||
| // append column names | ||
| sb.append("|").append(rows.head.zipWithIndex.map { case (cell, i) => | ||
| String.format(s"%${colWidths(i)}s", cell) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use the padding function on string directly, rather than doing the format. |
||
| }.mkString("|")).append("|\n") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation here is off, and it is very confusing to have it wrapping this way |
||
|
|
||
| // append data | ||
| sb.append(rows.tail.map { row => | ||
| "|" + row.zipWithIndex.map { case (cell, i) => | ||
| String.format(s"%${colWidths(i)}s", cell) | ||
| }.mkString("|") + "|" | ||
| }.mkString("\n")).append("\n") | ||
|
|
||
| sb.append(sep) | ||
|
|
||
| sb.toString() | ||
| } | ||
|
|
||
| override def toString: String = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great to create unit test for showString in DataFrameSuite.