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

    https://github.com/apache/spark/pull/17230#discussion_r108307572
  
    --- Diff: core/src/main/scala/org/apache/spark/rdd/PipedRDD.scala ---
    @@ -198,17 +183,114 @@ private[spark] class PipedRDD[T: ClassTag](
             val t = childThreadException.get()
             if (t != null) {
               val commandRan = command.mkString(" ")
    -          logError(s"Caught exception while running pipe() operator. 
Command ran: $commandRan. " +
    -            s"Exception: ${t.getMessage}")
    -          proc.destroy()
    +          logError("Caught exception while running pipe() operator. " +
    +              s"Command ran: $commandRan.", t)
               cleanup()
    +          proc.destroy()
               throw t
             }
           }
         }
       }
     }
     
    +/** Specifies how to write the elements of the input [[RDD]] into the 
pipe. */
    +trait InputWriter[T] extends Serializable {
    +  def write(dos: DataOutput, elem: T): Unit
    +}
    +
    +/** Specifies how to read the elements from the pipe into the output 
[[RDD]]. */
    +trait OutputReader[T] extends Serializable {
    +  /**
    +   * Reads the next element.
    +   *
    +   * The input is guaranteed to have at least one byte.
    +   */
    +  def read(dis: DataInput): T
    +}
    +
    +class TextInputWriter[I](
    +    encoding: String = Codec.defaultCharsetCodec.name,
    +    printPipeContext: (String => Unit) => Unit = null,
    +    printRDDElement: (I, String => Unit) => Unit = null
    +) extends InputWriter[I] {
    +
    +  private[this] val lineSeparator = 
System.lineSeparator().getBytes(encoding)
    +  private[this] var initialized = printPipeContext == null
    +
    +  private def writeLine(dos: DataOutput, s: String): Unit = {
    +    dos.write(s.getBytes(encoding))
    +    dos.write(lineSeparator)
    +  }
    +
    +  override def write(dos: DataOutput, elem: I): Unit = {
    +    if (!initialized) {
    +      printPipeContext(writeLine(dos, _))
    +      initialized = true
    +    }
    +
    +    if (printRDDElement == null) {
    +      writeLine(dos, String.valueOf(elem))
    +    } else {
    +      printRDDElement(elem, writeLine(dos, _))
    +    }
    +  }
    +}
    +
    +class TextOutputReader(
    +    encoding: String = Codec.defaultCharsetCodec.name
    +) extends OutputReader[String] {
    +
    +  private[this] val lf = "\n".getBytes(encoding)
    +  private[this] val cr = "\r".getBytes(encoding)
    +  private[this] val crlf = cr ++ lf
    +  private[this] var buf = Array.ofDim[Byte](64)
    +  private[this] var used = 0
    +
    +  @inline
    +  /** Checks that the suffix of [[buf]] matches [[other]]. */
    +  private def endsWith(other: Array[Byte]): Boolean = {
    +    var i = used - 1
    +    var j = other.length - 1
    +    (j <= i) && {
    +      while (j >= 0) {
    +        if (buf(i) != other(j)) {
    +          return false
    +        }
    +        i -= 1
    +        j -= 1
    +      }
    +      true
    +    }
    +  }
    +
    +  override def read(dis: DataInput): String = {
    --- End diff --
    
    Could a `dis.readLine()` be used here and would it be more efficient?


---
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