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

    https://github.com/apache/spark/pull/3920#discussion_r25180080
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/pythonconverters/HBaseConverters.scala
 ---
    @@ -18,20 +18,34 @@
     package org.apache.spark.examples.pythonconverters
     
     import scala.collection.JavaConversions._
    +import scala.util.parsing.json._
     
     import org.apache.spark.api.python.Converter
     import org.apache.hadoop.hbase.client.{Put, Result}
     import org.apache.hadoop.hbase.io.ImmutableBytesWritable
     import org.apache.hadoop.hbase.util.Bytes
    +import org.apache.hadoop.hbase.KeyValue.Type
    +import org.apache.hadoop.hbase.CellUtil
     
     /**
    - * Implementation of [[org.apache.spark.api.python.Converter]] that 
converts an
    - * HBase Result to a String
    + * Implementation of [[org.apache.spark.api.python.Converter]] that 
converts all
    + * the records in an HBase Result to a String
      */
     class HBaseResultToStringConverter extends Converter[Any, String] {
       override def convert(obj: Any): String = {
    +    import collection.JavaConverters._
         val result = obj.asInstanceOf[Result]
    -    Bytes.toStringBinary(result.value())
    +    val output = result.listCells.asScala.map(cell =>
    +        Map(
    +          "row" -> Bytes.toStringBinary(CellUtil.cloneRow(cell)),
    +          "columnFamily" -> 
Bytes.toStringBinary(CellUtil.cloneFamily(cell)),
    +          "qualifier" -> 
Bytes.toStringBinary(CellUtil.cloneQualifier(cell)),
    +          "timestamp" -> cell.getTimestamp.toString,
    +          "type" -> Type.codeToType(cell.getTypeByte).toString,
    +          "value" -> Bytes.toStringBinary(CellUtil.cloneValue(cell))
    +        )
    +    )
    +    output.map(JSONObject(_).toString()).mkString("\n")
    --- End diff --
    
    That make sense. JSON will escape the `\n` in String, so it's safe to have 
`\n` as separator.


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