Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16086#discussion_r90452307
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala ---
    @@ -275,36 +308,43 @@ class Dataset[T] private[sql](
         val numCols = schema.fieldNames.length
     
         // Initialise the width of each column to a minimum value of '3'
    -    val colWidths = Array.fill(numCols)(3)
    +    val colMaxWidths = Array.fill(numCols)(3)
    +    val colWidths = Array.ofDim[Int](rows.length, numCols)
     
         // Compute the width of each column
    +    var j = 0
         for (row <- rows) {
           for ((cell, i) <- row.zipWithIndex) {
    -        colWidths(i) = math.max(colWidths(i), cell.length)
    +        val width = unicodeWidth(cell)
    +        colWidths(j)(i) = width
    +        colMaxWidths(i) = math.max(colMaxWidths(i), width)
           }
    +      j = j + 1
         }
     
         // Create SeparateLine
    -    val sep: String = colWidths.map("-" * _).addString(sb, "+", "+", 
"+\n").toString()
    +    val sep: String = colMaxWidths.map("-" * _).addString(sb, "+", "+", 
"+\n").toString()
     
         // column names
         rows.head.zipWithIndex.map { case (cell, i) =>
           if (truncate > 0) {
    -        StringUtils.leftPad(cell, colWidths(i))
    +        repeatPadding(colMaxWidths(i) - colWidths(0)(i)).append(cell)
    --- End diff --
    
    oh. Got it.
    
    For this purpose, current `repeatPadding` looks verbose. If you just want 
to create exact number of spaces, you can use `" " * n`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to