• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala HBaseAdmin类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.apache.hadoop.hbase.client.HBaseAdmin的典型用法代码示例。如果您正苦于以下问题:Scala HBaseAdmin类的具体用法?Scala HBaseAdmin怎么用?Scala HBaseAdmin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HBaseAdmin类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: HBaseHelloWorld

//设置package包名称以及导入依赖的类
import org.apache.spark._
import org.apache.hadoop._

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.hbase.client.{HBaseAdmin,HTable,Put,Get}
import org.apache.hadoop.hbase.util.Bytes

object HBaseHelloWorld {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("HBaseRead")
    val sc = new SparkContext(sparkConf)
    val conf = HBaseConfiguration.create()
    val tableName = "enterprises"

    conf.set("hbase.master", "localhost:60000")
    conf.setInt("timeout", 120000)
    conf.set(TableInputFormat.INPUT_TABLE, tableName)

    val admin = new HBaseAdmin(conf)
    if (!admin.isTableAvailable(tableName)) {
      val tableDesc = new HTableDescriptor(tableName)
      admin.createTable(tableDesc)
    }

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

    val pairs = hBaseRDD.map(s => (s, 1))
    val counts = pairs.reduceByKey((a, b) => a + b)

    sc.stop()
  }
} 
开发者ID:octoai,项目名称:octo-spark,代码行数:38,代码来源:HBaseHelloWorld.scala


示例2: Employee

//设置package包名称以及导入依赖的类
package com.zaloni.mgohain.sparkHbaseIntegration.services

import org.apache.hadoop.hbase.client.{HBaseAdmin, HTable, Put}
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.{HBaseConfiguration, HColumnDescriptor, HTableDescriptor}

object Employee {
  def main(args: Array[String]) {
    if (args.length != 1) {
      System.err.println("In correct number of arguments " + args.length)
      System.out.println("Please provide correct arguments.")
      System.exit(1)
    }
    val hbaseConf = HBaseConfiguration.create()
    val tableName = "employee"
    hbaseConf.set(TableOutputFormat.OUTPUT_TABLE, tableName)
    hbaseConf.set("hbase.zookeeper.quorum","quickstart.cloudera")
    hbaseConf.set("hbase.zookeeper.property.client.port","2181")
    val admin = new HBaseAdmin(hbaseConf)
    val cfProfessionalData = Bytes.toBytes("professional_data")
    val cfPersonalData = Bytes.toBytes("personal_data")
    if (!admin.isTableAvailable(tableName)) {
      val tableDesc = new HTableDescriptor(tableName)
      tableDesc.addFamily(new HColumnDescriptor(cfProfessionalData))
      tableDesc.addFamily(new HColumnDescriptor(cfPersonalData))
    }
    val hTable = new HTable(hbaseConf,tableName)
    //val records = sc.textFile(args(0))
    val put = new Put(Bytes.toBytes("e_1"))
    val eId = Bytes.toBytes("Emp_id")
    val name = Bytes.toBytes("Name")
    val dsgtn = Bytes.toBytes("Designation")
    val doj = Bytes.toBytes("DOJ")
    val addr = Bytes.toBytes("Address")
    val phn = Bytes.toBytes("Phone")
    val dob = Bytes.toBytes("DOB")
    put.add(cfProfessionalData, eId, Bytes.toBytes(1))
    put.add(cfProfessionalData, name, Bytes.toBytes("Mridul Gohain"))
    put.add(cfProfessionalData, dsgtn, Bytes.toBytes("SE"))
    put.add(cfProfessionalData, doj, Bytes.toBytes("15-07-2015"))
    put.add(cfPersonalData, addr, Bytes.toBytes("Chabua"))
    put.add(cfPersonalData, phn, Bytes.toBytes("9859559606"))
    put.add(cfPersonalData, dob, Bytes.toBytes("04-10-1991"))
    hTable.put(put)
    hTable.close()
  }
} 
开发者ID:mridulZaloni,项目名称:sparkStreaming,代码行数:49,代码来源:Employee.scala


示例3: HBaseSetup

//设置package包名称以及导入依赖的类
package uk.co.odinconsultants.bitcoin.hbase

import org.apache.hadoop.hbase.{HColumnDescriptor, HTableDescriptor, TableName}
import org.apache.hadoop.hbase.client.HBaseAdmin

object HBaseSetup {

  val metaTable: String   = "Addresses"
  val tableName: TableName = TableName.valueOf(metaTable)
  val familyName: String  = "familyName"

  def createAddressesTable(admin: HBaseAdmin): Unit = {
    createTable(admin, metaTable, familyName)
  }

  private def createTable(admin: HBaseAdmin, tableName: String, familyName: String): Unit = {
    val tableDescriptor = new HTableDescriptor(tableName)
    val colDescriptor   = new HColumnDescriptor(familyName)
    tableDescriptor.addFamily(colDescriptor)
    if (!admin.tableExists(tableName)) {
      admin.createTable(tableDescriptor)
    }
  }

} 
开发者ID:PhillHenry,项目名称:Cryptorigin,代码行数:26,代码来源:HBaseSetup.scala


示例4: HBaseReader

//设置package包名称以及导入依赖的类
import org.apache.hadoop.hbase.client.{ HBaseAdmin, Result }
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.mapreduce.TableInputFormat
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.hbase.util.Bytes



object HBaseReader {

  def main(args: Array[String]) {

    if(args.size != 1){
      println("Usage: HBaseReader <table name>")
      System.exit(-1)
    }
    
    val tableName = args(0)
    val master = ""

    val sc = Connection.createSparkConf()
    val conf = Connection.createHBaseConf()

    val admin = new HBaseAdmin(conf)
    if (!admin.isTableAvailable(tableName)) {
      val tableDesc = new HTableDescriptor(tableName)
      admin.createTable(tableDesc)
    }
    
    conf.set(TableInputFormat.INPUT_TABLE, tableName)
    val hBaseRDD = sc.newAPIHadoopRDD(conf, classOf[TableInputFormat],
      classOf[ImmutableBytesWritable],
      classOf[Result])

    println("Number of Records found : " + hBaseRDD.count())

    val stocksRdd = hBaseRDD.map {
      case (key: ImmutableBytesWritable, value: Result) =>
        Stock(
          new String(key.get),
          new String(value.getValue(Bytes.toBytes("prices"), Bytes.toBytes("Open"))),
          new String(value.getValue(Bytes.toBytes("prices"), Bytes.toBytes("Close"))),
          new String(value.getValue(Bytes.toBytes("prices"), Bytes.toBytes("High"))),
          new String(value.getValue(Bytes.toBytes("prices"), Bytes.toBytes("Low"))),
          new String(value.getValue(Bytes.toBytes("prices"), Bytes.toBytes("AdjClose"))),
          new String(value.getValue(Bytes.toBytes("volume"), Bytes.toBytes("vol"))))
    }
    stocksRdd.take(10).foreach(println)

  }
} 
开发者ID:Einext,项目名称:spark-projects,代码行数:52,代码来源:HBaseReader.scala


示例5: HbaseExample

//设置package包名称以及导入依赖的类
package com.hortonworks.examples

import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{Get, HBaseAdmin, HTable}
import org.apache.hadoop.hbase.mapreduce.{TableInputFormat, TableOutputFormat}
import org.apache.hadoop.hbase.util.Bytes
import org.apache.spark.{SparkConf, SparkContext}

object HbaseExample {

  def main(arg: Array[String]) {

    if (arg.length < 2) {
      System.err.println("Usage: HbaseExample Hbase-Table RowKey")
      System.exit(1)
    }

    val jobName = "SparkHBaseTest"
    val conf = new SparkConf().setAppName(jobName)
    val sc = new SparkContext(conf)

    val hbaseTable = arg(0)
    val rowKey = arg(1)

    println("hbase table: " + hbaseTable)
    println("row key to get: " + rowKey)

    runTest(hbaseTable, rowKey, sc)
  }

  def runTest(hbaseTable: String, rowKey: String, sc: SparkContext): Null = {
    val hconf = HBaseConfiguration.create()

    hconf.set(TableOutputFormat.OUTPUT_TABLE, hbaseTable)
    hconf.set(TableInputFormat.INPUT_TABLE, hbaseTable)
    HBaseAdmin.checkHBaseAvailable(hconf)
    val htable = new HTable(hconf, hbaseTable)
    println("Hbase table connection established")
    println(htable.getTableDescriptor)
    println(htable.get(new Get(Bytes.toBytes(rowKey))).getMap)
    println("Getting count of records in table now...")
    val hBaseRDD = sc.newAPIHadoopRDD(hconf, classOf[TableInputFormat],
      classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable],
      classOf[org.apache.hadoop.hbase.client.Result])
    println(hBaseRDD.count())
    println("Done!")
    null
  }
} 
开发者ID:clukasikhw,项目名称:kerberized-spark-hbase-hdp2.4-example,代码行数:50,代码来源:HbaseExample.scala



注:本文中的org.apache.hadoop.hbase.client.HBaseAdmin类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ClassFinder类代码示例发布时间:2022-05-23
下一篇:
Scala PCA类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap