Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example
- import java.io.IOException
- import org.apache.hadoop.conf.Configuration
- import org.apache.hadoop.io._
- import scala.collection.JavaConversions._
- import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat
- import org.apache.hadoop.mapreduce.Job
- import org.apache.hadoop.mapreduce.Reducer
- import org.apache.hadoop.mapreduce.Mapper
- import org.apache.hadoop.hbase.HBaseConfiguration
- import org.apache.hadoop.hbase.client.HBaseAdmin
- import org.apache.hadoop.hbase.client.HConnectionManager
- import org.apache.hadoop.hbase.client.HConnection
- import org.apache.hadoop.hbase.client.HTableInterface
- import org.apache.hadoop.hbase.client.HTable
- import org.apache.hadoop.hbase.HTableDescriptor
- import org.apache.hadoop.hbase.util.Bytes
- import org.apache.hadoop.hbase.HColumnDescriptor
- import org.apache.hadoop.hbase.client.Put
- import java.util.logging.Logger
- case class HString(name: String) {
- lazy val bytes = name.getBytes
- override def toString = name
- }
- object HString {
- import scala.language.implicitConversions
- implicit def hstring2String(src: HString): String = src.name
- implicit def hstring2Bytes(src: HString): Array[Byte] = src.bytes
- }
- object Families {
- val stream = HString("stream")
- val identity = HString("identity")
- val cf = HString("cf")
- }
- object Qualifiers {
- val title = HString("title")
- val url = HString("url")
- val media = HString("media")
- val media_source = HString("media_source")
- val content = HString("content")
- val nolimitid_timestamp = HString("nolimitid.timestamp")
- val original_id = HString("original_id")
- val timestamp = HString("timestamp")
- val date_created = HString("date_created")
- val count = HString("count")
- }
- object Tables {
- val rawstream100 = HString("raw_stream_1.0.0")
- val rawstream = HString("rawCopy")
- }
- object Hello {
- val hbaseConfig = {
- val conf = HBaseConfiguration.create()
- conf.set("hbase.master", "127.0.0.1:60000")
- conf.set("hbase.zookeeper.quorum", "127.0.0.1")
- conf.set("hbase.zookeeper.property.clientPort", "2181")
- conf
- }
- val hbaseAdmin = new HBaseAdmin(hbaseConfig)
- val connection = HConnectionManager.createConnection(hbaseConfig)
- def createInterface(connection: HConnection, tableName: String, tableFamily: List[String]): HTableInterface = {
- checkTable(tableName, tableFamily)
- val table = connection.getTable(tableName)
- return table
- }
- def createTable(tableName: String, tableFamily: List[String]): HTable = {
- checkTable(tableName, tableFamily)
- val table = new HTable(hbaseConfig, tableName)
- return table
- }
- def checkTable(tableName: String, tableFamily: List[String]) {
- // if (!hbaseAdmin.tableExists(tableName)) {
- val desc = new HTableDescriptor(tableName)
- tableFamily.foreach(n => desc.addFamily(new HColumnDescriptor(Bytes.toBytes(n))))
- hbaseAdmin.createTable(desc)
- // }
- }
- def main(args: Array[String]): Unit = {
- //
- val conf = HBaseConfiguration.create()
- conf.set("hbase.master", "127.0.0.1:60000")
- conf.set("hbase.zookeeper.quorum", "127.0.0.1")
- //conf.set("hbase.zookeeper.property.clientPort", "2181")
- val table = new HTable(conf, Bytes.toBytes("table1"))
- val p = new Put(Bytes.toBytes("row1"))
- p.add(Bytes.toBytes("fam1"), Bytes.toBytes("qul1"),
- Bytes.toBytes("asolole"))
- table.put(p)
- table.flushCommits()
- table.close()
- var putObj = new Put(Bytes.toBytes("tes1"))
- putObj.add(
- Bytes.toBytes("data"),
- Bytes.toBytes("id"),
- Bytes.toBytes(212)
- )
- //htablei.put(putObj)
- //htablei.flushCommits()
- //htablei.close()
- println("endcode")
- //
- }
- }
- class Hello {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement