You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2017/10/13 09:00:47 UTC

[GitHub] spark pull request #19363: [SPARK-22224][SQL]Override toString of KeyValue/R...

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

    https://github.com/apache/spark/pull/19363#discussion_r144500085
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/KeyValueGroupedDataset.scala ---
    @@ -564,4 +565,30 @@ class KeyValueGroupedDataset[K, V] private[sql](
           encoder: Encoder[R]): Dataset[R] = {
         cogroup(other)((key, left, right) => f.call(key, left.asJava, right.asJava).asScala)(encoder)
       }
    +
    +  override def toString: String = {
    +    try {
    +      val builder = new StringBuilder
    +      val kFields = kExprEnc.schema.map {
    +        case f => s"${f.name}: ${f.dataType.simpleString(2)}"
    +      }
    +      val vFields = vExprEnc.schema.map {
    +        case f => s"${f.name}: ${f.dataType.simpleString(2)}"
    +      }
    +      builder.append("[key: [")
    +      builder.append(kFields.take(2).mkString(", "))
    +      if (kFields.length > 2) {
    +        builder.append(" ... " + (kFields.length - 2) + " more field(s)")
    +      }
    +      builder.append("], value: [")
    +      builder.append(vFields.take(2).mkString(", "))
    +      if (vFields.length > 2) {
    +        builder.append(" ... " + (vFields.length - 2) + " more field(s)")
    +      }
    +      builder.append("]]").toString()
    +    } catch {
    +      case NonFatal(e) =>
    --- End diff --
    
    Although some methods of `StringBuilder` can throw exceptions, I didn't see simple `append` can throw exception. Access of `schema` should not throw exception at all. So I don't get why it is.


---

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