HBaseRead using spark - scala


#1

import org.apache.hadoop.hbase.client.{HBaseAdmin, Result}
import org.apache.hadoop.hbase.{ HBaseConfiguration, HTableDescriptor }
import org.apache.hadoop.hbase.mapreduce.TableInputFormat
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.{HBaseConfiguration, TableName}
import org.apache.hadoop.hbase.client._
import org.apache.hadoop.hbase.util.Bytes
import org.apache.spark._
import scala.io.Source

object HBaseRead {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setAppName(“HBaseRead”)
val sc = new SparkContext(sparkConf)
val conf = HBaseConfiguration.create()
// val tableName = “test:hbasedemo”

conf.set(TableInputFormat.INPUT_TABLE, "test:hbasedemo")
conf.set(TableInputFormat.SCAN_CACHEDROWS, "1000")
conf.set(TableInputFormat.SCAN_COLUMNS, "cf1:column1 cf1:column2 cf1:column4")
conf.set(TableInputFormat.SCAN_CACHEBLOCKS, "false")

val hBaseRDD = sc.newAPIHadoopRDD(conf, classOf[TableInputFormat], classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable],classOf[org.apache.hadoop.hbase.client.Result])
println("Number of Records found : " + hBaseRDD.count())

// sc.stop()
}
}

print(“Before end”);
exit()

Anythig wrong in my code, not getting the number of records from println("Number of Records found : " + hBaseRDD.count())

but getting BEfore end from print(“Before end”);


#2

Anyway done with this program… Got the output