b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c语言清空文件中数据 HBase的协处理器开发编码实例(8)

电脑杂谈  发布时间:2018-01-09 17:07:34  来源:网络整理

* 写入另一张二级索引表index_ob_table,可以提高对于特定字段的查询效率

*/

@SuppressWarnings(“deprecation”)

public class PutObserver extends BaseRegionObserver{

@Override

public void postPut(ObserverContext《RegionCoprocessorEnvironment》 e,

Put put, WALEdit edit, Durability durability) throws IOException {

// 获取二级索引表

HTableInterface table = e.getEnvironment().getTable(TableName.valueOf(“index_ob_table”));

// 获取值

List《Cell》 cellList1 = put.get(Bytes.toBytes(“info”), Bytes.toBytes(“name”));

List《Cell》 cellList2 = put.get(Bytes.toBytes(“info”), Bytes.toBytes(“score”));

// 将数据插入二级索引表

for (Cell cell1 : cellList1) {

// 列info:name的值作为二级索引表的rowkey

Put indexPut = new Put(CellUtil.cloneValue(cell1));

for (Cell cell2 : cellList2) {

// 列info:score的值作为二级索引表中列info:score的值

indexPut.add(Bytes.toBytes(“info”), Bytes.toBytes(“score”), CellUtil.cloneValue(cell2));

}

// 数据插入二级索引表

table.put(indexPut);

}

// 关闭资源

table.close();

}

}

5.2 加载Observer

// 将PutObserver类打包后上传到HDFS

$ hadoopfs -put ovserver_put.jar /input

// 启动hbase shell

$hbase shell

// 创建数据表ob_table

》 create‘ob_table’,‘info’

// 创建二级索引表ob_table

》 create‘index_ob_table’,‘info’

// 加载协处理器

》disable ‘ob_table’

》 alter‘ob_table’,METHOD =》‘table_att’,‘coprocessor’ =》‘hdfs://localhost:9000/input/observer_put.jar|com.hbase.demo.observer.PutObserver|100’

》 enable‘ob_table’


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-59353-8.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 荣俊梅
      荣俊梅

      一剑之仇终将报

    • 颜粲
      颜粲

      才能具备基本的判断分析能力

    热点图片
    拼命载入中...