hadoop wordcount 分步按照value降序排序

本文介绍了如何将Hadoop的Wordcount默认排序替换为按照value降序排序,通过讲解并提供@DecreasingComparator.java、@Submit.java、@SortMapper.java和@SortReducer.java等关键代码,帮助读者一步步实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

面向有wordcount输出结果的,经过默认排序的

由于wordcount自带的是按照字母表顺序排序的,所以我们第一步就是要把自带排序给替换成按照value降序排序的

@DecreasingComparator.java

public class DecreasingComparator extends Text.Comparator {
   
   
    @SuppressWarnings("rawtypes")
    public int compare(WritableComparable a, WritableComparable b){
   
   
        return -super.compare(a, b);
    }
    public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
   
   
        return -super.compare(b1, s1, l1, b2, s2, l2);
    }
}

来源@木子木泗 链接

@Submite.java

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
im
2025-06-12 15:11:36,476 INFO mapreduce.Job: Job job_1749712196980_0001 failed with state FAILED due to: Application application_1749712196980_0001 failed 2 times due to AM Container for appattempt_1749712196980_0001_000002 exited with exitCode: 1 Failing this attempt.Diagnostics: [2025-06-12 15:11:26.955]Exception from container-launch. Container id: container_1749712196980_0001_02_000001 Exit code: 1 [2025-06-12 15:11:26.963]Container exited with a non-zero exit code 1. Error file: prelaunch.err. Last 4096 bytes of prelaunch.err : Last 4096 bytes of stderr : Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster Please check whether your <HADOOP_HOME>/etc/hadoop/mapred-site.xml contains the below configuration: <property> <name>yarn.app.mapreduce.am.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> <property> <name>mapreduce.map.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> <property> <name>mapreduce.reduce.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> [2025-06-12 15:11:26.963]Container exited with a non-zero exit code 1. Error file: prelaunch.err. Last 4096 bytes of prelaunch.err : Last 4096 bytes of stderr : Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster Please check whether your <HADOOP_HOME>/etc/hadoop/mapred-site.xml contains the below configuration: <property> <name>yarn.app.mapreduce.am.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> <property> <name>mapreduce.map.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> <property> <name>mapreduce.reduce.env</name> <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value> </property> For more detailed output, check the application tracking page: http://192.168.181.130:8099/cluster/app/application_1749712196980_0001 Then click on links to logs of each attempt. . Failing the application. 2025-06-12 15:11:36,523 INFO mapreduce.Job: Counters: 0
06-14
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值