gpt4 book ai didi

java - 不使用 JobConf 运行 Hadoop 作业

转载 作者:IT老高 更新时间:2023-10-28 20:40:14 25 4
gpt4 key购买 nike

我找不到提交不使用已弃用 JobConf 类的 Hadoop 作业的单个示例。尚未弃用的 JobClient 仍然只支持采用 JobConf 参数的方法。

谁能指出一个 Java 代码示例,该示例仅使用 Configuration 类(不是 JobConf)提交 Hadoop map/reduce 作业,并使用 mapreduce.lib.input 包而不是 mapred.input?

最佳答案

希望对你有帮助

import java.io.File;

import org.apache.commons.io.FileUtils;
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.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
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;

public class MapReduceExample extends Configured implements Tool {

static class MyMapper extends Mapper<LongWritable, Text, LongWritable, Text> {
public MyMapper(){

}

protected void map(
LongWritable key,
Text value,
org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, LongWritable, Text>.Context context)
throws java.io.IOException, InterruptedException {
context.getCounter("mygroup", "jeff").increment(1);
context.write(key, value);
};
}

@Override
public int run(String[] args) throws Exception {
Job job = new Job();
job.setMapperClass(MyMapper.class);
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));

job.waitForCompletion(true);
return 0;
}

public static void main(String[] args) throws Exception {
FileUtils.deleteDirectory(new File("data/output"));
args = new String[] { "data/input", "data/output" };
ToolRunner.run(new MapReduceExample(), args);
}
}

关于java - 不使用 JobConf 运行 Hadoop 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2115292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com