当前位置: 首页>>代码示例>>Scala>>正文


Scala ImmutableBytesWritable类代码示例

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


在下文中一共展示了ImmutableBytesWritable类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: HBaseWriter

//设置package包名称以及导入依赖的类
import org.apache.hadoop.hbase.client.Put
import org.apache.hadoop.hbase.io.ImmutableBytesWritable
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat



object HBaseWriter {

  def toStock(rec: String): Stock = {
    val splits = rec.split(",")
    Stock(splits(0), splits(1), splits(2), splits(3), splits(4), splits(5), splits(6))
  }

  def toPut(stock: Stock): (ImmutableBytesWritable, Put) = {
    val rowKey = stock.pdate
    val put = new Put(Bytes.toBytes(rowKey))

    put.add(StockHBaseType.cfPrices, StockHBaseType.colOpen, Bytes.toBytes(stock.open))
    put.add(StockHBaseType.cfPrices, StockHBaseType.colHigh, Bytes.toBytes(stock.high))
    put.add(StockHBaseType.cfPrices, StockHBaseType.colLow, Bytes.toBytes(stock.low))
    put.add(StockHBaseType.cfPrices, StockHBaseType.colClose, Bytes.toBytes(stock.close))
    put.add(StockHBaseType.cfPrices, StockHBaseType.colAdjClose, Bytes.toBytes(stock.adjClose))
    put.add(StockHBaseType.cfVolume, StockHBaseType.colVol, Bytes.toBytes(stock.volume))

    (new ImmutableBytesWritable(Bytes.toBytes(rowKey)), put)
  }
  
  
  
  def main(args: Array[String]): Unit = {
    if(args.size != 3){
      println("Usage: HBaseConnector <data source> <table name> <number of thread>")
      System.exit(-1)
    }
    
    val sourceFile = args(0)
    val tableName = args(1)
    val numThread = args(2).toInt
    // This parameters controls how many parallel load occurs.
    // More is better, but more thread creates more pressure to HBase heap memory.
    
    val sc = Connection.createSparkConf()
    val hbaseConf = Connection.createHBaseConf()

    
    hbaseConf.set(TableOutputFormat.OUTPUT_TABLE, tableName)
    
    sc.textFile(sourceFile).
        filter(line => line.split(",").size == 7 && !line.startsWith("Date")).
        repartition(numThread).
        map(toStock).
        map(toPut).
        saveAsNewAPIHadoopFile("/user/user01/out",
            classOf[ImmutableBytesWritable], 
            classOf[Put], 
            classOf[TableOutputFormat[Put]], 
            hbaseConf)
  }

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

示例3: PartitionSorter

//设置package包名称以及导入依赖的类
package com.blogspot.yetanothercoders.hfile

import org.apache.hadoop.hbase.KeyValue
import org.apache.hadoop.hbase.io.ImmutableBytesWritable


object PartitionSorter {
  def sortPartition[A <: ImmutableBytesWritable, T <: KeyValue](p: Iterator[(A,T)]): Iterator[(A,T)] = {
    implicit def keyValueOrdering: Ordering[(A,T)] = new Ordering[(A,T)] {
      def compare(x: (A,T), y: (A,T)): Int = {
        new KeyValue.KVComparator().compare(x._2, y._2)
      }
    }
    p.toStream.sorted.toIterator
  }
} 
开发者ID:dawidwys,项目名称:phoenix-on-spark,代码行数:17,代码来源:PartitionSorter.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


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