Member since
01-17-2017
2
Posts
0
Kudos Received
0
Solutions
01-17-2017
09:10 PM
Yes. I think it should. I have not done it specifically but I have used Result.java class so it should work as it is the same class. Here is how I have done it. // create hbase configuration
Configuration configuration = HBaseConfiguration.create();
configuration.addResource(new Path("/etc/hbase/conf/hbase-site.xml"));
configuration.set(TableInputFormat.INPUT_TABLE, hbaseTableName);
// create java hbase context
JavaHBaseContext javaHBaseContext = new JavaHBaseContext(javaSparkContext, configuration);
JavaPairRDD<ImmutableBytesWritable, Result> hbaseRDD =
javaSparkContext.newAPIHadoopRDD(configuration, TableInputFormat.class, ImmutableBytesWritable.class, Result.class);
JavaRDD<Row> rowJavaRDD = hbaseRDD.map(new Function<Tuple2<ImmutableBytesWritable, Result>, Row >() {
private static final long serialVersionUID = -2021713021648730786L;
public Row call(Tuple2<ImmutableBytesWritable, Result> tuple) throws Exception {
Object[] rowObject = new Object[namearr.length];
for (int i=0; i<namearr.length; i++) {
Result result = tuple._2;
// handle each data type we support
if (typesarr[i].equals("string")) {
String str = Bytes.toString(result.getValue(Bytes.toBytes(cfarr[i]), Bytes.toBytes(namearr[i])));
rowObject[i] = str;
}
}
... View more