Mapreduce构建hbase二级索引
2023-09-14 09:00:23 时间
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.MultiTableOutputFormat;
import org.apache.hadoop.hbase.mapreduce.TableInputFormat;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.GenericOptionsParser;
public class IndexBuilder {
private class MyMapper extends TableMapper ImmutableBytesWritable, Put {
private Map byte[], ImmutableBytesWritable indexes = new HashMap byte[], ImmutableBytesWritable
private String columnFamily;
@Override
protected void map(ImmutableBytesWritable key, Result value,
Context context) throws IOException, InterruptedException {
Set byte[] keys = indexes.keySet();
for (byte[] k : keys) {
ImmutableBytesWritable indexTableName = indexes.get(k);
byte[] val = value.getValue(Bytes.toBytes(columnFamily), k);
Put put = new Put(val);// 索引表的rowkey为原始表的值
put.add(Bytes.toBytes("f1"), Bytes.toBytes("id"), key.get());// 索引表的内容为原始表的rowkey
context.write(indexTableName, put);
}
}
@Override
protected void setup(Context context) throws IOException,
InterruptedException {
Configuration conf = context.getConfiguration();
String tableName = conf.get("tableName");
columnFamily = conf.get("columnFamily");
String[] qualifiers = conf.getStrings("qualifiers");
// indexes的key为列名,value为索引表名
for (String q : qualifiers) {
indexes.put(
Bytes.toBytes(q),
new ImmutableBytesWritable(Bytes.toBytes(tableName
+ "-" + q)));
}
}
}
public static void main(String[] args) throws IOException,
ClassNotFoundException, InterruptedException {
Configuration conf = HBaseConfiguration.create();
String[] otherargs = new GenericOptionsParser(conf, args)
.getRemainingArgs();// 去除掉没有用的命令行参数
// 输入参数:表名,列族名,列名
if (otherargs.length 3) {
System.exit(-1);
}
String tableName = otherargs[0];
String columnFamily = otherargs[1];
conf.set("tableName", tableName);
conf.set("columnFamily", columnFamily);
String[] qualifiers = new String[otherargs.length - 2];
for (int i = 0; i qualifiers.length; i++) {
qualifiers[i] = otherargs[i + 2];
}
conf.setStrings("qualifiers", qualifiers);
Job job = new Job(conf, tableName);
job.setJarByClass(IndexBuilder.class);
job.setMapperClass(MyMapper.class);
job.setNumReduceTasks(0);
job.setInputFormatClass(TableInputFormat.class);
// 可以输出多张表
job.setOutputFormatClass(MultiTableOutputFormat.class);
Scan scan = new Scan();
scan.setCaching(1000);
TableMapReduceUtil.initTableMapperJob(tableName, scan, MyMapper.class,
ImmutableBytesWritable.class, Put.class, job);
job.waitForCompletion(true);
}
}
hbase构建二级索引解决方案 HBase的一级索引就是rowkey,我们仅仅能通过rowkey进行检索。假设我们相对Hbase里面列族的列列进行一些组合查询,就只能全表扫描了。表如果较大的话,代价是不可接受的,所以要提出二级索引的方案。
基于HBase构建千亿级文本数据相似度计算与快速去重系统 随着大数据时代的到来,数据信息在给我们生活带来便利的同时,同样也给我们带来了一系列的考验与挑战。本文主要介绍了基于 Apache HBase 与 Google SimHash 等多种算法共同实现的一套支持百亿级文本数据相似度计算与快速去重系统的设计与实现。该方案在公司业务层面彻底解决了多主题海量文本数据所面临的存储与计算慢的问题。 一. 面临的问题 1. 如何选择文本的相似度计算或去重算法? 常见的有余弦夹角算法、欧式距离、Jaccard 相似度、最长公共子串、编辑距离等。这些算法对于待比较的文本数据不多时还比较好用,但在海量数据背景下,如果每天产生的数据以千万计算,我们如何对于这些海
第十二届 BigData NoSQL Meetup — 基于hbase的New sql落地实践 立即下载
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1699774
hbase构建二级索引解决方案 HBase的一级索引就是rowkey,我们仅仅能通过rowkey进行检索。假设我们相对Hbase里面列族的列列进行一些组合查询,就只能全表扫描了。表如果较大的话,代价是不可接受的,所以要提出二级索引的方案。
基于HBase构建千亿级文本数据相似度计算与快速去重系统 随着大数据时代的到来,数据信息在给我们生活带来便利的同时,同样也给我们带来了一系列的考验与挑战。本文主要介绍了基于 Apache HBase 与 Google SimHash 等多种算法共同实现的一套支持百亿级文本数据相似度计算与快速去重系统的设计与实现。该方案在公司业务层面彻底解决了多主题海量文本数据所面临的存储与计算慢的问题。 一. 面临的问题 1. 如何选择文本的相似度计算或去重算法? 常见的有余弦夹角算法、欧式距离、Jaccard 相似度、最长公共子串、编辑距离等。这些算法对于待比较的文本数据不多时还比较好用,但在海量数据背景下,如果每天产生的数据以千万计算,我们如何对于这些海
第十二届 BigData NoSQL Meetup — 基于hbase的New sql落地实践 立即下载
相关文章
- HBase参数配置及说明
- HBase-0.90.4集群安装配置
- HBase数据模型剖析
- Hadoop生态上几个技术的关系与区别:hive、pig、hbase 关系与区别 Pig
- Hbase 学习(三)Coprocessors
- Hbase 学习(八) 使用MapReduce&华为二级索引(原理)
- k8s minikube部署hbase
- 启动HBase抛出org.apache.hadoop.hbase.ClockOutOfSyncException异常:hmaster正常,节点hregionserver启动失败
- HBase与时空索引技术
- HBase单机版安装详细步骤
- 【华为云技术分享】HBase与AI/用户画像/推荐系统的结合:CloudTable标签索引特性介绍
- HBase 基本入门篇
- Hbase总结(五)-hbase常识及habse适合什么场景
- 都是 HBase 上的 SQL 引擎,Kylin 和 Phoenix 有什么不同?——Kylin 利用 MapReduce/Spark 将原始数据进行聚合计算,转成了 OLAP Cube 并加载到 HBase 中,以 Key-Value 的形式存储。Cube 按照时间范围划分为多个 segment,每个 segment 是一张 HBase 表,每张表会根据数据大小切分成多个 region
- 为什么连接HBase报错:Will not attempt to authenticate using SASL (unknown error)?
- 单机模式启动Hbase失败
- hbase_学习_HBase环境搭建(单机)
- HBase写吞吐场景资源消耗量化分析及优化
- 【记录】win环境下hbase启动报错 master.HMaster: hbase:meta,,1.1588230740 is NOT online
- 大数据大比拼:Hive vs HBase,你知道两者的区别和适用场景吗?
- 大数据技术之Hbase