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

    https://github.com/apache/spark/pull/3920#discussion_r23413908
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/pythonconverters/HBaseConverters.scala
 ---
    @@ -23,15 +23,27 @@ 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 =>
    +        
"{'columnFamliy':'%s','qualifier':'%s','timestamp':'%s','type':'%s','value':'%s'}".format(
    +          Bytes.toStringBinary(CellUtil.cloneFamily(cell)),
    +          Bytes.toStringBinary(CellUtil.cloneQualifier(cell)),
    +          cell.getTimestamp.toString,
    +          Type.codeToType(cell.getTypeByte),
    +          Bytes.toStringBinary(CellUtil.cloneValue(cell))
    +        )
    +    )   
    +    output.mkString(" ")
    --- End diff --
    
    In fact, in HBase a A *{row, columnFamily:qualifier, version}* tuple 
exactly specifies a cell (a record) in HBase. So there are usually several 
records per column family in a row. 
    In fact, HBase `Result` contains all the information about a HBase table 
and `Result.listCells` returns all the cells as a java list of `hbase.Cell` 
which contains all the information about a cell.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to