-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12164] [SQL] Decode the encoded values and then display #10215
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 2 commits
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ package org.apache.spark.sql.execution | |
|
|
||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.commons.lang3.StringUtils | ||
| import org.apache.spark.sql.SQLContext | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
|
|
@@ -42,4 +43,67 @@ private[sql] trait Queryable { | |
| def explain(extended: Boolean): Unit | ||
|
|
||
| def explain(): Unit | ||
|
|
||
| private[sql] def showString(_numRows: Int, truncate: Boolean = true): String | ||
|
|
||
| /** | ||
| * Format the string representing rows for output | ||
| * @param rows The rows to show | ||
| * @param numRows Number of rows to show | ||
| * @param hasMoreData Whether some rows are not shown due to the limit | ||
| * @param truncate Whether truncate long strings and align cells right | ||
| * | ||
| */ | ||
| private[sql] def formatString (rows: Seq[Seq[String]], | ||
|
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 indenting is wrong. https://cwiki.apache.org/confluence/display/SPARK/Spark+Code+Style+Guide#SparkCodeStyleGuide-Indentation 4 space for function args that wrap.
Member
Author
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. Sorry, correct it now. |
||
| numRows: Int, | ||
| hasMoreData : Boolean, | ||
| truncate: Boolean = true): String = { | ||
| val sb = new StringBuilder | ||
| val numCols = schema.fieldNames.length | ||
|
|
||
| // Initialise the width of each column to a minimum value of '3' | ||
| val colWidths = Array.fill(numCols)(3) | ||
|
|
||
| // Compute the width of each column | ||
| for (row <- rows) { | ||
| for ((cell, i) <- row.zipWithIndex) { | ||
| colWidths(i) = math.max(colWidths(i), cell.length) | ||
| } | ||
| } | ||
|
|
||
| // Create SeparateLine | ||
| val sep: String = colWidths.map("-" * _).addString(sb, "+", "+", "+\n").toString() | ||
|
|
||
| // column names | ||
| rows.head.zipWithIndex.map { case (cell, i) => | ||
| if (truncate) { | ||
| StringUtils.leftPad(cell, colWidths(i)) | ||
| } else { | ||
| StringUtils.rightPad(cell, colWidths(i)) | ||
| } | ||
| }.addString(sb, "|", "|", "|\n") | ||
|
|
||
| sb.append(sep) | ||
|
|
||
| // data | ||
| rows.tail.map { | ||
| _.zipWithIndex.map { case (cell, i) => | ||
| if (truncate) { | ||
| StringUtils.leftPad(cell.toString, colWidths(i)) | ||
| } else { | ||
| StringUtils.rightPad(cell.toString, colWidths(i)) | ||
| } | ||
| }.addString(sb, "|", "|", "|\n") | ||
| } | ||
|
|
||
| sb.append(sep) | ||
|
|
||
| // For Data that has more than "numRows" records | ||
| if (hasMoreData) { | ||
| val rowsString = if (numRows == 1) "row" else "rows" | ||
| sb.append(s"only showing top $numRows $rowsString\n") | ||
| } | ||
|
|
||
| sb.toString() | ||
| } | ||
| } | ||
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.
we should use javadoc style instead of scaladoc. i.e.
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.
Yeah. Will correct all these. Thanks!