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的更多相关文章

  1. MapReduce将HDFS文本数据导入HBase中

    HBase本身提供了很多种数据导入的方式,通常有两种常用方式: 使用HBase提供的TableOutputFormat,原理是通过一个Mapreduce作业将数据导入HBase 另一种方式就是使用HB ...

  2. geotrellis使用(十二)再记录一次惨痛的伪BUG调试经历(数据导入以及读取瓦片)

    Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 BUG还原 查找BUG 解决方案 总结 后记 一.前 ...

  3. 将Excel中数据导入数据库(二)

    在上篇文章中介绍到将Excel中数据导入到数据库中,但上篇文章例子只出现了nvachar类型,且数据量很小.今天碰到将Excel中数据导入数据库中的Excel有6419行,其中每行均有48个字段,有i ...

  4. R语言基础入门之二:数据导入和描述统计

    by 写长城的诗 • October 30, 2011 • Comments Off This post was kindly contributed by 数据科学与R语言 - go there t ...

  5. 使用MapReduce将HDFS数据导入Mysql

    使用MapReduce将Mysql数据导入HDFS代码链接 将HDFS数据导入Mysql,代码示例 package com.zhen.mysqlToHDFS; import java.io.DataI ...

  6. 使用MapReduce将mysql数据导入HDFS

    package com.zhen.mysqlToHDFS; import java.io.DataInput; import java.io.DataOutput; import java.io.IO ...

  7. java大数据最全课程学习笔记(6)--MapReduce精通(二)--MapReduce框架原理

    目前CSDN,博客园,简书同步发表中,更多精彩欢迎访问我的gitee pages 目录 MapReduce精通(二) MapReduce框架原理 MapReduce工作流程 InputFormat数据 ...

  8. NPOI EXECL数据导入,日期格式调用DateCellValue取值时,二次或后续调用出现报错!

    NPOI version:2.5.1 EXCEL数据导入功能,第一次调用DateCellValue获得日期值OK,二次或后续调用出现报错"函数求值需要运行所有线程" 初步怀疑是版本 ...

  9. Java实现大批量数据导入导出(100W以上) -(二)导出

    使用POI或JXLS导出大数据量(百万级)Excel报表常常面临两个问题: 1. 服务器内存溢出: 2. 一次从数据库查询出这么大数据,查询缓慢. 当然也可以分页查询出数据,分别生成多个Excel打包 ...

随机推荐

  1. IOS深入学习(20)之Object modeling

    1 前言 本节简单的介绍了对象建模,以及需要注意的事项. 2 详述 对象建模是对设计通过一个面向对象应用检测和操作服务的对象或者类的加工.许多模型技术是可能的:Cocoa开发环境不推荐歧义性. 典型地 ...

  2. JS-运动基础——案例应用:淡入淡出效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. LeetCode——First Bad Version

    Description: You are a product manager and currently leading a team to develop a new product. Unfort ...

  4. 微信Tinker的一切都在这里,包括源码(一)

    版权声明:本文由张绍文原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/101 来源:腾云阁 https://www.qclo ...

  5. Minix2.0操作系统kernel文件分析

    详细分析  MINIX消息机制的核心: mpx386.s start.c proc.c 保护模式分析: src/kernel/exception.c src/kernel/protect.c src/ ...

  6. Egret3D初步学习笔记四 (地形使用)

    一 导出地形 Skinedmesh没反应.得选择导出scene. 二 直接报错  三 修改错误 选择关闭程序后,仍然可以导出完成. 由于地图的lightmap.exr没法解析报错. 在获得MapCon ...

  7. OC开发_Storyboard——多线程、UIScrollView

    一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...

  8. ionic+cordova开发!

    这里是一些学习的过程中纪录的: 官方网站: http://www.ionic-china.com/ 参考文章: https://blog.csdn.net/xyzz609/article/detail ...

  9. 03.JMS深入

    1.JMS API     JMS API可以分为3个主要部分:公共API.点对点API和发布/订阅API.在JMS1.1中,公共API可被用于向一个队列或主题发送消息,或从其中接收消息.点对点API ...

  10. 170515、mybatis批量操作

    //Java代码 public void batchAdd(){ SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession(); Stud ...