设为首页 加入收藏

TOP

HBase之普通BulkLoad(二)
2015-11-21 01:51:05 来源: 作者: 【 】 浏览:1
Tags:HBase 普通 BulkLoad
import yeepay.util.HdfsUtil; import yeepay.util.YeepayConstant; import java.util.Date; public abstract class AbstractJobBulkLoad { public static Configuration conf = HBaseConfiguration.create(); public void run(String[] args) throws Exception { if (args.length < 2) { System.err.println("please set input dir"); System.exit(-1); return; } String txtPath = args[0]; String tableName = args[1]; Job job = new Job(conf, "txt2HBase"); HTable htable = null; try { htable = new HTable(conf, tableName); //set table name // 根据region的数量来决定reduce的数量以及每个reduce覆盖的rowkey范围 HFileOutputFormat.configureIncrementalLoad(job, htable); htable.close(); job.setJarByClass(AbstractJobBulkLoad.class); FileSystem fs = FileSystem.get(conf); System.out.println("input file :" + txtPath); Path inputFile = new Path(txtPath); if (!fs.exists(inputFile)) { System.err.println("inputFile " + txtPath + " not exist."); throw new RuntimeException("inputFile " + txtPath + " not exist."); } FileInputFormat.addInputPath(job, inputFile); // job.setMapperClass(getMapperClass()); job.setMapOutputKeyClass(ImmutableBytesWritable.class); job.setMapOutputValueClass(Text.class); job.setInputFormatClass(TextInputFormat.class); // job.setReducerClass(getReducerClass()); Date now = new Date(); Path output = new Path("/output/" + tableName + "/" + now.getTime()); System.out.println("/output/" + tableName + "/" + now.getTime()); FileOutputFormat.setOutputPath(job, output); job.waitForCompletion(true); //执行BulkLoad HdfsUtil.chmod(conf, output.toString()); HdfsUtil.chmod(conf, output + "/" + YeepayConstant.COMMON_FAMILY); htable = new HTable(conf, tableName); new LoadIncrementalHFiles(conf).doBulkLoad(output, htable); htable.close(); System.out.println("HFile data load success!"); System.out.println(getJobName() + " end!"); } catch (Throwable t) { throw new RuntimeException(t); } } protected abstract Class getMapperClass(); protected abstract Class getReducerClass(); protected abstract String getTableName(); protected abstract String getJobName(); }
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇运行hbm2java工具和hbm2ddl工具 下一篇数据库调优教程(四)Explain性能..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: