数据导入(二):MapReduce
package test091201; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; public class Demo3 {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
//设置hbase表名称
conf.set(TableOutputFormat.OUTPUT_TABLE, "waln2");
//将该值改大,防止hbase超时退出
conf.set("dfs.socket.timeout", "180000");
conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");
conf.set("hbase.zookeeper.quorum", "ncst"); Job job = Job.getInstance(conf);
job.setJarByClass(Demo3.class); job.setMapperClass(Demo3Mapper.class);
job.setReducerClass(Demo3Reduce.class); //设置map的输出,不设置reduce的输出类型
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class); job.setInputFormatClass(TextInputFormat.class);
//不再设置输出路径,而是设置输出格式类型
job.setOutputFormatClass(TableOutputFormat.class); FileInputFormat.setInputPaths(job, new Path("hdfs://10.16.17.182:9000/test/wal_log"));
job.waitForCompletion(true);
} //map
public static class Demo3Mapper extends Mapper<LongWritable, Text, Text, Text>{
@Override
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String[] splited = value.toString().split("\t"); SimpleDateFormat dataformat = new SimpleDateFormat("yyyyMMddHHmmss");
String string = splited[0];
long parseLong = Long.parseLong(string.trim());
Date date = new Date(parseLong);
String format = dataformat.format(date); //Key=>TelNum:Date Value=>Line
context.write(new Text(splited[1]+":"+format), value);
}
} //reduce
public static class Demo3Reduce extends TableReducer<Text, Text, NullWritable>{
@Override
protected void reduce(Text key, Iterable<Text> v2s, Context context)
throws IOException, InterruptedException {
Put put = new Put(key.toString().getBytes());
for (Text text : v2s) {
String[] splited = text.toString().split("\t");
put.add("info".getBytes(), "date".getBytes(), splited[0].getBytes());
put.add("info".getBytes(), "tel".getBytes(), splited[1].getBytes());
put.add("info".getBytes(), "upPack".getBytes(), splited[6].getBytes());
put.add("info".getBytes(), "downPack".getBytes(), splited[7].getBytes());
put.add("info".getBytes(), "upPay".getBytes(), splited[8].getBytes());
put.add("info".getBytes(), "downPay".getBytes(), splited[9].getBytes());
}
context.write(NullWritable.get(), put);
}
}
}
数据导入(二):MapReduce的更多相关文章
- MapReduce将HDFS文本数据导入HBase中
HBase本身提供了很多种数据导入的方式,通常有两种常用方式: 使用HBase提供的TableOutputFormat,原理是通过一个Mapreduce作业将数据导入HBase 另一种方式就是使用HB ...
- geotrellis使用(十二)再记录一次惨痛的伪BUG调试经历(数据导入以及读取瓦片)
Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 BUG还原 查找BUG 解决方案 总结 后记 一.前 ...
- 将Excel中数据导入数据库(二)
在上篇文章中介绍到将Excel中数据导入到数据库中,但上篇文章例子只出现了nvachar类型,且数据量很小.今天碰到将Excel中数据导入数据库中的Excel有6419行,其中每行均有48个字段,有i ...
- R语言基础入门之二:数据导入和描述统计
by 写长城的诗 • October 30, 2011 • Comments Off This post was kindly contributed by 数据科学与R语言 - go there t ...
- 使用MapReduce将HDFS数据导入Mysql
使用MapReduce将Mysql数据导入HDFS代码链接 将HDFS数据导入Mysql,代码示例 package com.zhen.mysqlToHDFS; import java.io.DataI ...
- 使用MapReduce将mysql数据导入HDFS
package com.zhen.mysqlToHDFS; import java.io.DataInput; import java.io.DataOutput; import java.io.IO ...
- java大数据最全课程学习笔记(6)--MapReduce精通(二)--MapReduce框架原理
目前CSDN,博客园,简书同步发表中,更多精彩欢迎访问我的gitee pages 目录 MapReduce精通(二) MapReduce框架原理 MapReduce工作流程 InputFormat数据 ...
- NPOI EXECL数据导入,日期格式调用DateCellValue取值时,二次或后续调用出现报错!
NPOI version:2.5.1 EXCEL数据导入功能,第一次调用DateCellValue获得日期值OK,二次或后续调用出现报错"函数求值需要运行所有线程" 初步怀疑是版本 ...
- Java实现大批量数据导入导出(100W以上) -(二)导出
使用POI或JXLS导出大数据量(百万级)Excel报表常常面临两个问题: 1. 服务器内存溢出: 2. 一次从数据库查询出这么大数据,查询缓慢. 当然也可以分页查询出数据,分别生成多个Excel打包 ...
随机推荐
- 在fedora 18中将普通用户设置为sudo权限
将一般的用户加入sudo组is not in the sudoers file. This incident will be reported 解决方法 在一般用户下执行sudo命令提示xxx is ...
- win8.1简单快速安装phpnow的方法
工具/原料 phpnow 1.5.6 管理员身份登陆系统 方法/步骤 下载phpnow 这是必须的,大家可以自行百度下载,然后我们将phpnow放到一个文件夹,可以是根目录,也可以不是,但一定要知 ...
- jQuery的无new构建
正常面向对象的写法: var cJquery = function(){ //构造函数体 }; cJquery.prototype = { name : function(alert("ch ...
- type 、instanceof、in 和 hasOwnproperty
typeof可以检测的类型有:string.number.boolean.undefined.不可以用typeof检测null typeof也可以用来检测function,但是在IE8及跟早的浏览器中 ...
- window.location.href和document.location.href、document.URL的区别
1.document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象. 所以一个窗口下只有一个window.location.href,但是可能有多个documen ...
- GOOGLE和百度的长域名
GOOGLE的变态域名:www.mamashuojiusuannizhucedeyumingzaichanggoogledounengsousuochulai.cn/中文拼音:“妈妈说就算你注册的域名 ...
- iOS - 初学iPad开发入门
iPad是一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑MacBook产品之间跟iPhone一样,搭载的是iOS操作系统 iPhone和iPad开发的区别 屏幕的 ...
- Redis构建处理海量数据的大型购物网站
本系列教程内容提要 Java工程师之Redis实战系列教程教程是一个学习教程,是关于Java工程师的Redis知识的实战系列教程,本系列教程均以解决特定问题为目标,使用Redis快速解决在实际生产中的 ...
- 热力图实现-heatmap.js 代码示例
Heatmap.js – 最强大的 Web 动态热图 最新公司项目需要用到热力图,在百度上搜下,了解到heatmap.js这款神器.然后搜了下例子,却很难搜到马上出效果的例子,特此写一篇heatma ...
- xplan-打印执行顺序
-- ------------------------------------------------------------------------------------------------- ...