视频地址:http://pan.baidu.com/s/1dDEgKwD


这一节是讲师助教带着动手操作写简单的开发环境的部署和两个实例


开发环境的部署:http://www.cnblogs.com/admln/p/test-deployDevelopment.html


第一个实例就是wordcount


第二个实例

 package testHadoop;

 import java.io.IOException;

 import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; @SuppressWarnings("deprecation")
public class ReverseIndex extends Configured implements Tool{
enum Counter{
LINESKIP;
} public static class Map extends Mapper<LongWritable,Text,Text,Text> {
public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException {
String line = value.toString();
try {
String[] lineSplit = line.split(" ");
String anum = lineSplit[0];
String bnum = lineSplit[1]; context.write(new Text(bnum), new Text(anum));
}catch(java.lang.ArrayIndexOutOfBoundsException e) {
context.getCounter(Counter.LINESKIP).increment(1);
return;
} }
}
public static class Reduce extends Reducer<Text,Text,Text,Text> {
public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException {
String valueString;
String out = ""; for(Text value:values) {
valueString = value.toString();
out += valueString+"|";
}
context.write(key, new Text(out));
}
}
public int run(String[] args) throws Exception {
Configuration conf = getConf(); Job job = new Job(conf,"ReverseIndex");
job.setJarByClass(ReverseIndex.class); FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1])); job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
//job.setOutputFormatClass(TextOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class); job.waitForCompletion(true); return job.isSuccessful()?0:1; }
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new ReverseIndex(),args);
System.exit(res);
}
}

eclipse中运行没问题后打包用集群运行的时候遇到一个小问题

版本不合。原来我编译的时候在windows下面用的JDK7,Linux中hadoop JDK是1.6。

把源码在Linux上1.6编译一下就可以了。


实践过程中还学到一个小知识,在运行程序命令中输入输出路径如果用例如 input output这样的,就是默认在HDFS上/user/用户名/下面的input和output

如果用例如/input /output这样的路径就是在HDFS根目录下的input 和output


炼数成金hadoop视频干货05的更多相关文章

  1. 炼数成金hadoop视频干货03

    视频地址:http://pan.baidu.com/s/1dDEgKwD 着重介绍了HDFS 运行了示例程序wordcount,自己也试了一遍(用的伪分布式) 1.建立数据(和讲师的操作有些不一样,不 ...

  2. 炼数成金hadoop视频干货01

    视频地址:http://pan.baidu.com/s/1dDEgKwD 最开始还是讲hadoop的起源,但是和其他垃圾视频不同,不是照本宣科,听了还是受益.作者给人一种感觉就是他是确实把他的经验和体 ...

  3. 炼数成金hadoop视频干货06-10

    视频地址:http://pan.baidu.com/s/1dDEgKwD 第六课统讲了hadoop几个子项目和HBase,第七课还是讲的HBase 第八课讲了PIG 第九课讲了Hive和Zookeep ...

  4. 炼数成金hadoop视频干货02

    视频地址:http://pan.baidu.com/s/1dDEgKwD 这个视频理论性太强,不过倒是给了自己唯一的选项就是自己实践,不用像以前那样视频中敲一个字符,我也敲一个字符 讲到的内容: 介绍 ...

  5. 炼数成金hadoop视频干货04

    视频地址:http://pan.baidu.com/s/1dDEgKwD 这一节讲的全是理论 任务执行优化 : 1.推测式执行: 2.重用JVM: 3.忽略模式. 除了手动修改Log4J.proper ...

  6. 015_[小插曲]看黄老师《炼数成金Hadoop应用开发实战案例》笔记

    1.大数据金字塔结构 Data Source-->Data Warehouses/Data Marts-->data exploration-->Data Mining-->D ...

  7. dataguru(炼数成金)大数据培训基地印象

    dataguru访问地址:http://f.dataguru.cn/?fromuid=99611 课程优惠码:C4B6  这段时间一直在dataguru(炼数成金)上学习<hadoop数据分析平 ...

  8. 截图:【炼数成金】深度学习框架Tensorflow学习与应用

    创建图.启动图 Shift+Tab Tab 变量介绍: F etch Feed 简单的模型构造 :线性回归 MNIST数据集 Softmax函数 非线性回归神经网络   MINIST数据集分类器简单版 ...

  9. MapReduce工作原理图文详解 (炼数成金)

    MapReduce工作原理图文详解 1.Map-Reduce 工作机制剖析图: 1.首先,第一步,我们先编写好我们的map-reduce程序,然后在一个client 节点里面进行提交.(一般来说可以在 ...

随机推荐

  1. C#选择排序详解

    选择排序图解                         选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的 ...

  2. C++ 之高效使用STL ( STL 算法分类)

    http://blog.csdn.net/zhoukuo1981/article/details/3452118

  3. leetcode—Swap Nodes in Pairs

    1.题目描述 Given a linked list, swap every two adjacent nodes and return its head.   For example, Given ...

  4. Lucene学习笔记: 四,Lucene索引过程分析

    对于Lucene的索引过程,除了将词(Term)写入倒排表并最终写入Lucene的索引文件外,还包括分词(Analyzer)和合并段(merge segments)的过程,本次不包括这两部分,将在以后 ...

  5. [JS代码]如何判断ipad或者iphone是否为横屏或者竖屏 - portrait或者landscape

    //判断横屏或者竖屏 function orient() { //alert('gete'); if (window.orientation == 0 || window.orientation == ...

  6. homework-附加题:第12章基本数据类型阅读总结

    基本数据类型是构建其他所有数据类型的构造块,本人认为这部分是计算机编程的基础,值得得到大家的注意. 首先,在本章中作者提到了避免使用magic number.使用magic number这种做法是极其 ...

  7. Struts2零碎点整理

    1. 关于 Struts2 请求的扩展名问题 1). org.apache.struts2 包下的 default.properties 中配置了 Struts2 应用的一些常量 2). struts ...

  8. UVALive 7324 ASCII Addition (模拟)

    ASCII Addition 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/A Description Nowadays, th ...

  9. Spring Auto scanning components

    Normally you declare all the beans or components in XML bean configuration file, so that Spring cont ...

  10. CodeForces 589D Boulevard (数学,相遇)

    题意:给定 n 个的在 x 轴上的坐标,和开始时间,结束坐标,从起点向终点走,如果和其他人相遇,就互相打招乎,问你每人打招乎的次数. 析:其实这一个数学题,由于 n 比较小,我们就可以两两暴力,这两个 ...