栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

以编程方式将数据批量加载到HBase的最快方法是什么?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

以编程方式将数据批量加载到HBase的最快方法是什么?

我经历的过程可能与您尝试找到一种将MR中的数据加载到Hbase的有效方法的过程非常相似。我发现工作的是

HFileOutputFormat
用作MR的OutputFormatClass。

以下是我必须生成的代码的基础

job
以及
map
写出数据的Mapper 函数。很快
我们不再使用它,因此我手边没有数字,但是在一分钟内大约有250万条记录。

这是我编写的(分解后的)函数,用于为MapReduce流程生成作业以将数据放入Hbase

private Job createCubeJob(...) {    //Build and Configure Job    Job job = new Job(conf);    job.setJobName(jobName);    job.setMapOutputKeyClass(ImmutableBytesWritable.class);    job.setMapOutputValueClass(Put.class);    job.setMapperClass(HiveToHbaseMapper.class);//Custom Mapper    job.setJarByClass(CubeBuilderDriver.class);    job.setInputFormatClass(TextInputFormat.class);    job.setOutputFormatClass(HFileOutputFormat.class);    TextInputFormat.setInputPaths(job, hiveOutputDir);    HFileOutputFormat.setOutputPath(job, cubeOutputPath);    Configuration hConf = HbaseConfiguration.create(conf);    hConf.set("hbase.zookeeper.quorum", hbaseZookeeperQuorum);    hConf.set("hbase.zookeeper.property.clientPort", hbaseZookeeperClientPort);    HTable hTable = new HTable(hConf, tableName);    HFileOutputFormat.configureIncrementalLoad(job, hTable);    return job;}

这是我来自

HiveToHbaseMapper
该类的地图函数(略作编辑)。

public void map(WritableComparable key, Writable val, Context context)        throws IOException, InterruptedException {    try{        Configuration config = context.getConfiguration();        String[] strs = val.toString().split(Constants.HIVE_RECORD_COLUMN_SEPARATOR);        String family = config.get(Constants.CUBEBUILDER_CONFIGURATION_FAMILY);        String column = strs[COLUMN_INDEX];        String Value = strs[VALUE_INDEX];        String sKey = generateKey(strs, config);        byte[] bKey = Bytes.toBytes(sKey);        Put put = new Put(bKey);        put.add(Bytes.toBytes(family), Bytes.toBytes(column), (value <= 0)   ? Bytes.toBytes(Double.MIN_VALUE)  : Bytes.toBytes(value));        ImmutableBytesWritable ibKey = new ImmutableBytesWritable(bKey);        context.write(ibKey, put);        context.getCounter(CubeBuilderContextCounters.CompletedMapExecutions).increment(1);    }    catch(Exception e){        context.getCounter(CubeBuilderContextCounters.FailedMapExecutions).increment(1);        }}

我很确定这不会成为您的复制粘贴解决方案。显然,我在这里使用的数据不需要任何自定义处理(在此之前在MR作业中完成)。我要提供的主要内容是

HFileOutputFormat
。其余只是我如何使用它的一个示例。:)
我希望它能使您踏上寻求良好解决方案的坚实道路。:



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/446583.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号