数据导入(二):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打包 ...
随机推荐
- Mac/Xcode - 开发技巧快捷键
Xcode是iPhone和iPad开发者用来编码或者开发iOS app的IDE.Xcode有很多小巧但很有用的功能,很多时候我们可能没有注意到它们,也或者我们没有在合适的水平使用这些功能简化我们的iO ...
- 一致性哈希算法(consistent hashing)(转)
http://blog.csdn.net/cywosp/article/details/23397179
- 再谈js的作用域
再谈js的作用域 面试中遇到的题目: 题目一: var word = "hello world"; (function(){ alert(word); var word = ...
- postgresql----根据现有表创建新表
除普通的建表语句"create table table_name(columns);"之外,还可以根据现有表快速的创建新表: 一.使用create table ... (like ...
- Oracle下Insert的介绍
Insert是插入语句 insert into table(colname1,colname2) values(value1,valu2) 插入无效的会提示失败 数值类型在插入的时候不需要加引号,但是 ...
- ubuntu 下安装 jdk
1. 下载 jdk : https://www.oracle.com/technetwork/java/javase/downloads/index.html 2. 解压 jdk 到系统默认 jdk ...
- Linux环境下proc的配置c/c++操作数据库简单示例
在虚拟机上装了oracle11g数据库,原本想利用c/c++学习操作数据库.结果感觉摊上了一个大坑.从安装好oracle数据库到配置好proc的编译选项整整花了二天.但让我意识到自己自己几点薄弱:1. ...
- 动态修改Python类和实例的方法(转)
相信很多朋友在编程的时候都会想修改一下已经写好的程序行为代码,而最常见的方式就是通过子类来重写父类的一些不满足需求的方法.比如说下面这个例子. class Dog: def bark(self): p ...
- request对象的常用属性和方法
request的属性 /* 1.HttpRequest.GET 一个类似于字典的对象,包含 HTTP GET 的所有参数.详情请参考 QueryDict 对象. 2.HttpRequest.POST ...
- DrawLayout使用侧滑抽屉
布局:fg_left_drawer <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...