gpt4 book ai didi

hadoop - 在 Hadoop 中找不到 "KeyValueInputFormat"

转载 作者:可可西里 更新时间:2023-11-01 16:34:26 24 4
gpt4 key购买 nike

我是 Hadoop 的新手,但已经阅读了关于它的 Yahoo 教程并且已经编写了一些 mapReduce 作业。我以前的所有作品都使用 TextInputFormat,但我现在需要将其更改为 KeyValueInputFormat。问题是hadoop 0.20.2找不到KeyValueInputFormat.class?

我在下面附上我的代码(这是仅更改输入格式的字数统计示例)

package org.myorg;

import java.io.IOException;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class WordCount {

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();

public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}

public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);

conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);

conf.setInputFormat(keyValueInputFormat.class); //The modified input format
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));

JobClient.runJob(conf);
}
}

最佳答案

org.apache.hadoop.mapreduce.lib.input中有KeyValueTextInputFormat。

一些旧教程基于旧版本的 Hadoop API。我建议您学习一些较新的教程。

这是我在 KeyValueTextInputFormat 上寻找源代码时得到的结果。

package org.apache.hadoop.mapreduce.lib.input;

import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

public class KeyValueTextInputFormat extends FileInputFormat<Text, Text> {

public KeyValueTextInputFormat() {
//compiled code
throw new RuntimeException("Compiled Code");
}

protected boolean isSplitable(JobContext context, Path file) {
//compiled code
throw new RuntimeException("Compiled Code");
}

public RecordReader<Text, Text> createRecordReader(InputSplit genericSplit, TaskAttemptContext context) throws IOException {
//compiled code
throw new RuntimeException("Compiled Code");
}
}

关于hadoop - 在 Hadoop 中找不到 "KeyValueInputFormat",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11443905/

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