Hadoop (十六) --------- MapReduce 阶段常见错误

  1. 导包容易出错。尤其 Text 和 CombineTextInputFormat。

  2. Mapper中第一个输入的参数必须是 LongWritable 或者 NullWritable,不可以是 IntWritable,否则报的错误是类型转换异常。

  3. java.lang.Exception: java.io.IOException: Illegal partition for 13926435656 (4),说明 Partition 和 ReduceTask个数没对上,调整 ReduceTask 个数。

  4. 如果分区数不是1,但是 reducetask 为1,是否执行分区过程。答案是:不执行分区过程。因为在MapTask的源码中,执行分区的前提是先判断ReduceNum个数是否大于1。不大于1肯定不执行。

  5. 在Windows环境编译的jar包导入到Linux环境中运行,
    hadoop jar wc.jar com.fancy.mapreduce.wordcount.WordCountDriver /user/fancy/ /user/fancyry/output
    报如下错误:
    Exception in thread "main" java.lang.UnsupportedClassVersionError: com/fancy/mapreduce/wordcount/WordCountDriver : Unsupported major.minor version 52.0
    原因是 Windows 环境用的 jdk1.7,Linux 环境用的 jdk1.8。
    解决方案:统一 jdk 版本。

  6. 缓存pd.txt小文件案例中,报找不到pd.txt文件
    原因:大部分为路径书写错误。还有就是要检查pd.txt.txt的问题。还有个别电脑写相对路径找不到pd.txt,可以修改为绝对路径。

  7. 报类型转换异常。
    通常都是在驱动函数中设置 Map 输出和最终输出时编写错误。
    Map输出的 key 如果没有排序,也会报类型转换异常。

  8. 集群中运行wc.jar时出现了无法获得输入文件。
    原因:WordCount案例的输入文件不能放用 HDFS 集群的根目录。

  9. 出现了如下相关异常
    Exception in thread "main" java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z at org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method) at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:609) at org.apache.hadoop.fs.FileUtil.canRead(FileUtil.java:977) java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries. at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:356) at org.apache.hadoop.util.Shell.getWinUtilsPath(Shell.java:371) at org.apache.hadoop.util.Shell.<clinit>(Shell.java:364)
    方案一:拷贝hadoop.dll文件到Windows目录C:\Windows\System32。个别同学电脑还需要修改Hadoop源码。
    方案二:创建如下包名,并将NativeIO.java拷贝到该包名下
    在这里插入图片描述

  10. 自定义 Outputformat 时,注意在 RecordWirter 中的 close 方法必须关闭流资源。否则输出的文件内容中数据为空。

@Override
public void close(TaskAttemptContext context) throws IOException, InterruptedException {
	if (atguigufos != null) {
		atguigufos.close();
	}
	if (otherfos != null) {
		otherfos.close();
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在森林中麋了鹿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值