数据导入(二):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打包 ...
随机推荐
- 【BZOJ4337】BJOI2015 树的同构 括号序列
[BZOJ4337]BJOI2015 树的同构 Description 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱 ...
- 详解Go语言中的屏蔽现象
在刚开始学习Go语言的过程中,难免会遇到一些问题,尤其是从其他语言转向Go开发的人员,面对语法及其内部实现的差异,在使用Go开发时也避免不了会踩"坑".本文主要针对Go设计中的屏蔽 ...
- 百度地图API开发----手机地图做导航功能
第一种方式:手机网页点击打开直接进百度地图APP <a href="baidumap://map/direction?mode=[transit:公交,driving:驾车]& ...
- ffmpeg 推送、保存rtmp 流命令
1.将文件当做直播送至live ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName 2.将直播媒体保存至本 ...
- pta 习题集5-19 列车厢调度
1 ====== <--移动方向 / 3 ===== \ 2 ====== -->移动方向 大家或许在某些数据结构教材上见到过"列车厢调度问题"(当然没见过也不要紧). ...
- Andrew Ng机器学习公开课笔记 -- 朴素贝叶斯算法
网易公开课,第5,6课 notes,http://cs229.stanford.edu/notes/cs229-notes2.pdf 前面讨论了高斯判别分析,是一种生成学习算法,其中x是连续值 这里要 ...
- Doing Homework---hdu1074(状态压缩&&记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 有n(n<=15)门课需要做作业,每门课所需时间是used_time以及每门课作业上交的最 ...
- 构造HTTP请求Header实现“伪造来源IP”(转)
原文:http://zhangxugg-163-com.iteye.com/blog/1663687 构造 HTTP请求 Header 实现“伪造来源 IP ” 在阅读本文前,大家要有一个概念,在实现 ...
- 【Python】sasa版:文件中csv读取在写入csv读取的数据和执行是否成功。
sasa写的文件(包含解析文字) # coding=utf- from selenium import webdriver from time import sleep import keyword ...
- 纯css3加载动画
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name= ...