spark 操作 hbase

添加hbase 的jar 包,在{SPARK_HOME}/conf/spark-env.sh 中添加<span style="white-space:pre">	</span>
<span style="white-space:pre"></span><pre name="code" class="plain">export SPARK_CLASSPATH=/usr/local/hbase/hbase-0.96.2-hadoop2/lib/*


spark 操作 hbase 跟 java 操作hbase 一樣一樣的。
import org.apache.spark._  
import org.apache.spark.rdd.NewHadoopRDD 
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.mapreduce.TableInputFormat 
import org.apache.hadoop.hbase.client.HBaseAdmin
val configuration = HBaseConfiguration.create();  
configuration.set("hbase.zookeeper.property.clientPort", "2181");
configuration.set("hbase.zookeeper.quorum", "ubuntu3,ubuntu1,ubuntu2");   
configuration.set("hbase.master", "ubuntu1:60000");  //設置hbase master  
configuration.addResource("/usr/local/hbase/hbase-0.96.2-hadoop2/conf/hbase-site.xml")  
configuration.set(TableInputFormat.INPUT_TABLE, "person")
val hadmin = new HBaseAdmin(configuration); 
val hrdd=sc.newAPIHadoopRDD(configuration,classOf[TableInputFormat],classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable],classOf[org.apache.hadoop.hbase.client.Result]) 

hrdd.count 
</pre><pre name="code" class="java">

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章