File tree Expand file tree Collapse file tree 2 files changed +31
-8
lines changed
main/scala/org/apache/spark/sql
test/scala/org/apache/spark/sql Expand file tree Collapse file tree 2 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,7 @@ class DataFrame private[sql](
175175 * @param numRows Number of rows to show
176176 */
177177 private [sql] def showString (numRows : Int ): String = {
178+ val sb = new StringBuilder
178179 val data = take(numRows)
179180 val numCols = schema.fieldNames.length
180181
@@ -194,12 +195,34 @@ class DataFrame private[sql](
194195 }
195196 }
196197
197- // Pad the cells
198- rows.map { row =>
199- row.zipWithIndex.map { case (cell, i) =>
200- String .format(s " %- ${colWidths(i)}s " , cell)
201- }.mkString(" " )
202- }.mkString(" \n " )
198+ // Create SeparateLine
199+ val sep : String = {
200+ " +" + colWidths.map {
201+ size =>
202+ val columnSep = new Array [Char ](size)
203+ for (i <- 0 until size)
204+ columnSep(i) = '-'
205+ String .valueOf(columnSep)
206+ }.mkString(" +" ) + " +\n "
207+ }
208+
209+ sb.append(sep)
210+
211+ // append column names
212+ sb.append(" |" ).append(rows.head.zipWithIndex.map { case (cell, i) =>
213+ String .format(s " % ${colWidths(i)}s " , cell)
214+ }.mkString(" |" )).append(" |\n " )
215+
216+ // append data
217+ sb.append(rows.tail.map { row =>
218+ " |" + row.zipWithIndex.map { case (cell, i) =>
219+ String .format(s " % ${colWidths(i)}s " , cell)
220+ }.mkString(" |" ) + " |"
221+ }.mkString(" \n " )).append(" \n " )
222+
223+ sb.append(sep)
224+
225+ sb.toString()
203226 }
204227
205228 override def toString : String = {
Original file line number Diff line number Diff line change @@ -592,10 +592,10 @@ class DataFrameSuite extends QueryTest {
592592 checkAnswer(df.select(df(" key" )), testData.select(' key ).collect().toSeq)
593593 }
594594
595- ignore (" show" ) {
595+ test (" show" ) {
596596 // This test case is intended ignored, but to make sure it compiles correctly
597597 testData.select($" *" ).show()
598- testData.select($" *" ).show(1000 )
598+ // testData.select($"*").show(1000)
599599 }
600600
601601 test(" createDataFrame(RDD[Row], StructType) should convert UDTs (SPARK-6672)" ) {
You can’t perform that action at this time.
0 commit comments