Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package test
  2. import org.apache.spark._
  3. import org.apache.hadoop.hbase.client.{HBaseAdmin, Result}
  4. import org.apache.hadoop.hbase.{ HBaseConfiguration, HTableDescriptor }
  5. import org.apache.hadoop.hbase.mapreduce.TableInputFormat
  6. import org.apache.hadoop.hbase.io.ImmutableBytesWritable
  7.  
  8. object Main {
  9. def main(args: Array[String]) {
  10. //Initiate spark context with spark master URL. You can modify the URL per your environment.
  11. var a = 0
  12. val conf1 = new SparkConf().setAppName("WordCounter").setMaster("yarn-client")
  13. val sc = new SparkContext(conf1)
  14. //val sparkConf = new SparkConf().setAppName("HBaseApp").setMaster("local[2]")
  15. //val sc = new SparkContext(sparkConf)
  16. val conf = HBaseConfiguration.create()
  17. val tableName = "webpage"
  18.  
  19. //System.setProperty("user.name", "hdfs")
  20. //System.setProperty("HADOOP_USER_NAME", "hdfs")
  21. conf.set("hbase.master", "localhost:60000")
  22. conf.setInt("timeout", 100000)
  23. conf.set("hbase.zookeeper.quorum", "localhost")
  24. conf.set("zookeeper.znode.parent", "/hbase-unsecure")
  25. conf.set(TableInputFormat.INPUT_TABLE, tableName)
  26.  
  27. val admin = new HBaseAdmin(conf)
  28. if (!admin.isTableAvailable(tableName)) {
  29. val tableDesc = new HTableDescriptor(tableName)
  30. admin.createTable(tableDesc)
  31. }
  32.  
  33. val hBaseRDD = sc.newAPIHadoopRDD(conf, classOf[TableInputFormat], classOf[ImmutableBytesWritable], classOf[Result])
  34. println("Number of Records found : " + hBaseRDD.count())
  35. sc.stop()
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement