Spark Shell 读取HBase数据

val conf = org.apache.hadoop.hbase.HBaseConfiguration.create()
conf.set("hbase.zookeeper.quorum","s1sl11,s1ma11,s1sl22")
conf.set(org.apache.hadoop.hbase.mapreduce.TableInputFormat.INPUT_TABLE,"MOBILE2CMPAYID")
val hbaseRDD = sc.newAPIHadoopRDD(conf, 
classOf[org.apache.hadoop.hbase.mapreduce.TableInputFormat], 
classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable],
classOf[org.apache.hadoop.hbase.client.Result])
hbaseRDD.count()
import org.apache.hadoop.hbase.util.Bytes
val m2cRDD=hbaseRDD.map(r=>(
Bytes.toString(r._2.getValue(Bytes.toBytes("cf"),Bytes.toBytes("mobile_no"))),
Bytes.toString(r._2.getValue(Bytes.toBytes("cf"),Bytes.toBytes("user_id")))
))

你可能感兴趣的:(Spark Shell 读取HBase数据)