@@ -23,15 +23,27 @@ import org.apache.spark.api.python.Converter
23
23
import org .apache .hadoop .hbase .client .{Put , Result }
24
24
import org .apache .hadoop .hbase .io .ImmutableBytesWritable
25
25
import org .apache .hadoop .hbase .util .Bytes
26
+ import org .apache .hadoop .hbase .KeyValue .Type
27
+ import org .apache .hadoop .hbase .CellUtil
26
28
27
29
/**
28
- * Implementation of [[org.apache.spark.api.python.Converter ]] that converts an
29
- * HBase Result to a String
30
+ * Implementation of [[org.apache.spark.api.python.Converter ]] that converts all
31
+ * the records in an HBase Result to a String
30
32
*/
31
33
class HBaseResultToStringConverter extends Converter [Any , String ] {
32
34
override def convert (obj : Any ): String = {
35
+ import collection .JavaConverters ._
33
36
val result = obj.asInstanceOf [Result ]
34
- Bytes .toStringBinary(result.value())
37
+ val output = result.listCells.asScala.map(cell =>
38
+ " {'columnFamliy':'%s','qualifier':'%s','timestamp':'%s','type':'%s','value':'%s'}" .format(
39
+ Bytes .toStringBinary(CellUtil .cloneFamily(cell)),
40
+ Bytes .toStringBinary(CellUtil .cloneQualifier(cell)),
41
+ cell.getTimestamp.toString,
42
+ Type .codeToType(cell.getTypeByte),
43
+ Bytes .toStringBinary(CellUtil .cloneValue(cell))
44
+ )
45
+ )
46
+ output.mkString(" " )
35
47
}
36
48
}
37
49
0 commit comments