本文整理汇总了Scala中org.apache.hadoop.hbase.HColumnDescriptor类的典型用法代码示例。如果您正苦于以下问题:Scala HColumnDescriptor类的具体用法?Scala HColumnDescriptor怎么用?Scala HColumnDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HColumnDescriptor类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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()
}
}
示例3: twr
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.hbase.internal
import java.io.Closeable
import akka.stream.stage.StageLogging
import org.apache.hadoop.hbase.{HColumnDescriptor, HTableDescriptor, TableName}
import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory, Table}
import org.apache.hadoop.conf.Configuration
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, Future}
import scala.util.{Failure, Success, Try}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.postfixOps
private[internal] trait HBaseCapabilities { this: StageLogging =>
def twr[A <: Closeable, B](resource: A)(doWork: A => B): Try[B] =
try {
Success(doWork(resource))
} catch {
case e: Exception => Failure(e)
} finally {
try {
if (resource != null) {
resource.close()
}
} catch {
case e: Exception => log.error(e, e.getMessage) // should be logged
}
}
def connect(conf: Configuration, timeout: Int = 10) =
Await.result(Future(ConnectionFactory.createConnection(conf)), timeout seconds)
private[internal] def getOrCreateTable(tableName: TableName, columnFamilies: Seq[String])(
implicit connection: Connection
): Try[Table] = twr(connection.getAdmin) { admin =>
val table =
if (admin.isTableAvailable(tableName))
connection.getTable(tableName)
else {
val tableDescriptor: HTableDescriptor = new HTableDescriptor(tableName)
columnFamilies.foreach { cf =>
tableDescriptor.addFamily(new HColumnDescriptor(cf))
}
admin.createTable(tableDescriptor)
log.info(s"Table $tableName created with cfs: $columnFamilies.")
connection.getTable(tableName)
}
table
}
}
示例4: 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)
}
}
示例5: 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)
}
}
}