本文整理汇总了Scala中org.apache.hadoop.hbase.HBaseConfiguration类的典型用法代码示例。如果您正苦于以下问题:Scala HBaseConfiguration类的具体用法?Scala HBaseConfiguration怎么用?Scala HBaseConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HBaseConfiguration类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CreateSaltedTable
//设置package包名称以及导入依赖的类
package com.cloudera.sa.apptrans.setup.hbase
import java.io.File
import org.apache.commons.lang.StringUtils
import org.apache.hadoop.hbase.{HBaseConfiguration, HColumnDescriptor, HTableDescriptor, TableName}
import org.apache.hadoop.hbase.client.ConnectionFactory
import org.apache.hadoop.hbase.io.compress.Compression
import org.apache.hadoop.hbase.regionserver.{BloomType, ConstantSizeRegionSplitPolicy}
import org.apache.hadoop.hbase.util.Bytes
import scala.collection.mutable
object CreateSaltedTable {
def main(args:Array[String]): Unit = {
if (args.length == 0) {
println("<tableName> <columnFamily> <regionCount> <numOfSalts> <hbaseConfigFolder>")
}
val tableName = args(0)
val columnFamilyName = args(1)
val regionCount = args(2).toInt
val numOfSalts = args(3).toInt
val hbaseConfigFolder = args(4)
val conf = HBaseConfiguration.create()
conf.addResource(new File(hbaseConfigFolder + "hbase-site.xml").toURI.toURL)
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin
val tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName))
val columnDescriptor = new HColumnDescriptor(columnFamilyName)
columnDescriptor.setCompressionType(Compression.Algorithm.SNAPPY)
columnDescriptor.setBlocksize(64 * 1024)
columnDescriptor.setBloomFilterType(BloomType.ROW)
tableDescriptor.addFamily(columnDescriptor)
tableDescriptor.setMaxFileSize(Long.MaxValue)
tableDescriptor.setRegionSplitPolicyClassName(classOf[ConstantSizeRegionSplitPolicy].getName)
val splitKeys = new mutable.MutableList[Array[Byte]]
for (i <- 0 to regionCount) {
val regionSplitStr = StringUtils.leftPad((i*(numOfSalts/regionCount)).toString, 4, "0")
splitKeys += Bytes.toBytes(regionSplitStr)
}
admin.createTable(tableDescriptor, splitKeys.toArray)
}
}
示例2: 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()
}
}
示例3: 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()
}
}
示例4: HBaseRestServer
//设置package包名称以及导入依赖的类
package com.hadooparchitecturebook.taxi360.server.hbase
import java.io.File
import com.sun.jersey.spi.container.servlet.ServletContainer
import org.apache.hadoop.hbase.HBaseConfiguration
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.{Context, ServletHolder}
object HBaseRestServer {
def main(args:Array[String]): Unit = {
if (args.length == 0) {
println("<port> <configDir> <numberOfSalts> <customerTableName>")
}
val port = args(0).toInt
val hbaseConfigFolder = args(1)
val numberOfSalts = args(2).toInt
val appEventTableName = args(3)
val conf = HBaseConfiguration.create()
conf.addResource(new File(hbaseConfigFolder + "hbase-site.xml").toURI.toURL)
HBaseGlobalValues.init(conf, numberOfSalts,
appEventTableName)
val server = new Server(port)
val sh = new ServletHolder(classOf[ServletContainer])
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig")
sh.setInitParameter("com.sun.jersey.config.property.packages", "com.hadooparchitecturebook.taxi360.server.hbase")
sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true")
val context = new Context(server, "/", Context.SESSIONS)
context.addServlet(sh, "/*")
println("starting HBase Rest Server")
server.start()
println("started HBase Rest Sserver")
server.join()
}
}
示例5: CreateSaltedTable
//设置package包名称以及导入依赖的类
package com.hadooparchitecturebook.taxi360.setup.hbase
import java.io.File
import org.apache.commons.lang.StringUtils
import org.apache.hadoop.hbase.{HBaseConfiguration, HColumnDescriptor, HTableDescriptor, TableName}
import org.apache.hadoop.hbase.client.ConnectionFactory
import org.apache.hadoop.hbase.io.compress.Compression
import org.apache.hadoop.hbase.regionserver.{BloomType, ConstantSizeRegionSplitPolicy}
import org.apache.hadoop.hbase.util.Bytes
import scala.collection.mutable
object CreateSaltedTable {
def main(args:Array[String]): Unit = {
if (args.length == 0) {
println("<tableName> <columnFamily> <regionCount> <numOfSalts> <hbaseConfigFolder>")
}
val tableName = args(0)
val columnFamilyName = args(1)
val regionCount = args(2).toInt
val numOfSalts = args(3).toInt
val hbaseConfigFolder = args(4)
val conf = HBaseConfiguration.create()
conf.addResource(new File(hbaseConfigFolder + "hbase-site.xml").toURI.toURL)
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin
val tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName))
val columnDescriptor = new HColumnDescriptor(columnFamilyName)
columnDescriptor.setCompressionType(Compression.Algorithm.SNAPPY)
columnDescriptor.setBlocksize(64 * 1024)
columnDescriptor.setBloomFilterType(BloomType.ROW)
tableDescriptor.addFamily(columnDescriptor)
tableDescriptor.setMaxFileSize(Long.MaxValue)
tableDescriptor.setRegionSplitPolicyClassName(classOf[ConstantSizeRegionSplitPolicy].getName)
val splitKeys = new mutable.MutableList[Array[Byte]]
for (i <- 0 to regionCount) {
val regionSplitStr = StringUtils.leftPad((i*(numOfSalts/regionCount)).toString, 4, "0")
splitKeys += Bytes.toBytes(regionSplitStr)
}
admin.createTable(tableDescriptor, splitKeys.toArray)
}
}
示例6: HBaseRestServer
//设置package包名称以及导入依赖的类
package com.cloudera.sa.apptrans.server.hbase
import java.io.File
import com.sun.jersey.spi.container.servlet.ServletContainer
import org.apache.hadoop.hbase.HBaseConfiguration
import org.mortbay.jetty.Server
import org.mortbay.jetty.servlet.{Context, ServletHolder}
object HBaseRestServer {
def main(args:Array[String]): Unit = {
if (args.length == 0) {
println("<port> <configDir> <numberOfSalts> <customerTableName>")
}
val port = args(0).toInt
val hbaseConfigFolder = args(1)
val numberOfSalts = args(2).toInt
val appEventTableName = args(3)
val accountMartTableName = args(4)
val conf = HBaseConfiguration.create()
conf.addResource(new File(hbaseConfigFolder + "hbase-site.xml").toURI.toURL)
HBaseGlobalValues.init(conf, numberOfSalts,
appEventTableName, accountMartTableName)
val server = new Server(port)
val sh = new ServletHolder(classOf[ServletContainer])
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig")
sh.setInitParameter("com.sun.jersey.config.property.packages", "com.cloudera.sa.example.card.server.hbase")
sh.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true")
val context = new Context(server, "/", Context.SESSIONS)
context.addServlet(sh, "/*")
println("starting HBase Rest Server")
server.start()
println("started HBase Rest Sserver")
server.join()
}
}
示例7: insertInto
//设置package包名称以及导入依赖的类
package swiss.army.knife.io
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.{TableName, HBaseConfiguration}
import org.apache.hadoop.hbase.client.{Put, Table, ConnectionFactory, Connection}
import org.apache.spark.sql.DataFrame
import scala.collection.mutable.ListBuffer
import scala.collection.JavaConverters._
def insertInto(dataFrame: DataFrame, tableName: String, family: String, qualifier: String, partLen: Int) : Unit = {
dataFrame.foreachPartition(partitionOfRecords => {
// ?????hbase??
val hConfig: Configuration = HBaseConfiguration.create()
val connection: Connection = ConnectionFactory.createConnection(hConfig)
val table: Table = connection.getTable(TableName.valueOf(tableName))
var puts: ListBuffer[Put] = ListBuffer[Put]()
var cnt: Int = 0
try {
while(partitionOfRecords.hasNext) {
val row = partitionOfRecords.next
val put : Put = new Put(Bytes.toBytes(row(0).toString))
put.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(row(1).toString))
puts += put
cnt = cnt + 1
if(cnt == partLen) {
table.put(puts.toList.asJava)
puts = ListBuffer[Put]()
cnt = 0
}
}
table.put(puts.toList.asJava)
} catch {
case e: Exception => e.printStackTrace
}
finally {
if(table != null){
table.close()}
if(connection != null){
connection.close()}
}
})
}
}
示例8: HbRddConfig
//设置package包名称以及导入依赖的类
package top.spoofer.hbrdd.config
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
class HbRddConfig(config: Configuration) extends Serializable {
def getHbaseConfig = HBaseConfiguration.create(config)
}
object HbRddConfig {
type configOption = (String, String)
private[HbRddConfig] case class HbaseOption(name: String, value: String)
def apply(config: Configuration): HbRddConfig = new HbRddConfig(config)
def apply(configs: configOption*): HbRddConfig = {
val hbConfig = HBaseConfiguration.create()
for {
option <- configs
hbOption = HbaseOption(option._1, option._2) //????case class ??????????
} hbConfig.set(hbOption.name, hbOption.value)
this.apply(hbConfig)
}
def apply(configs: { def rootDir: String; def quorum: String }): HbRddConfig = {
apply(
"hbase.rootdir" -> configs.rootDir,
"hbase.zookeeper.quorum" -> configs.quorum
)
}
def apply(configs: Map[String, String]): HbRddConfig = {
val hbConfig = HBaseConfiguration.create()
configs.keys foreach { name =>
hbConfig.set(name, configs(name))
}
this.apply(hbConfig)
}
def apply(configs: TraversableOnce[configOption]): HbRddConfig = {
val hbConfig = HBaseConfiguration.create()
configs foreach { option =>
val hbOption = HbaseOption(option._1, option._2)
hbConfig.set(hbOption.name, hbOption.value)
}
this.apply(hbConfig)
}
}
示例9: 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
}
}