gpt4 book ai didi

java - hadoop:预期 org.apache.hadoop.io.LongWritable,收到 org.apache.hadoop.io.Text

转载 作者:可可西里 更新时间:2023-11-01 16:22:40 27 4
gpt4 key购买 nike

我是 hadoop 的新手,正在尝试运行书中的示例程序。我正面临错误

java.io.IOException:映射中的键类型不匹配:预期 org.apache.hadoop.io.LongWritable,收到 org.apache.hadoop.io.Text

请帮我解决这个错误。下面是代码

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.KeyValueTextInputFormat;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class HadoopJob extends Configured implements Tool {



public static class MapperClass extends MapReduceBase implements Mapper<Text, Text, Text, Text> {

@Override
public void map(Text key, Text value, OutputCollector<Text, Text> output,
Reporter reporter) throws IOException {
output.collect(value, key);
}

}

public static class ReducerClass extends MapReduceBase implements Reducer<Text, Text, Text, Text> {

@Override
public void reduce(Text key, Iterator<Text> values,
OutputCollector<Text, Text> output, Reporter reporter) throws IOException {

String csv = "";
while (values.hasNext()) {
if (csv.length() > 0) {
csv += ",";
}

csv += values.next().toString();
}

output.collect(key, new Text(csv));
}

}

public static void main(String[] args) throws Exception{
int res = ToolRunner.run(new Configuration(), new HadoopJob(), args);
System.exit(res);
}

@Override
public int run(String[] arg0) throws Exception {

Configuration conf = getConf();
JobConf job = new JobConf(conf, HadoopJob.class);

Path in = new Path("/home/sumit/Documents/samples/WordCount/input");
Path out = new Path("/home/sumit/Documents/samples/WordCount/output");

FileSystem fs = FileSystem.get(new Configuration());
if (fs.exists(out)) {
fs.delete(out, true);
}

FileInputFormat.setInputPaths(job, in);
FileOutputFormat.setOutputPath(job, out);

job.setJobName("Hadoop Job");
job.setMapperClass(MapperClass.class);
job.setReducerClass(ReducerClass.class);

job.setInputFormat(KeyValueTextInputFormat.class);
job.setOutputFormat(TextOutputFormat.class);
job.setOutputValueClass(Text.class);
job.set("key.value.separator.in.input.line", ",");

JobClient.runJob(job);

return 0;
}

}

也请看下面的痕迹

13/05/18 21:04:54 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
13/05/18 21:04:54 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
13/05/18 21:04:54 WARN snappy.LoadSnappy: Snappy native library not loaded
13/05/18 21:04:54 INFO mapred.FileInputFormat: Total input paths to process : 1
13/05/18 21:04:55 INFO mapred.JobClient: Running job: job_local_0001
13/05/18 21:04:55 INFO util.ProcessTree: setsid exited with exit code 0
13/05/18 21:04:55 INFO mapred.Task: Using ResourceCalculatorPlugin : org.apache.hadoop.util.LinuxResourceCalculatorPlugin@5090d8ea
13/05/18 21:04:55 INFO mapred.MapTask: numReduceTasks: 1
13/05/18 21:04:55 INFO mapred.MapTask: io.sort.mb = 100
13/05/18 21:04:55 INFO mapred.MapTask: data buffer = 79691776/99614720
13/05/18 21:04:55 INFO mapred.MapTask: record buffer = 262144/327680
13/05/18 21:04:55 WARN mapred.LocalJobRunner: job_local_0001
java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.LongWritable, recieved org.apache.hadoop.io.Text
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1014)
at org.apache.hadoop.mapred.MapTask$OldOutputCollector.collect(MapTask.java:592)
at com.sis.hadoop.wordcount.HadoopJob$MapperClass.map(HadoopJob.java:32)
at com.sis.hadoop.wordcount.HadoopJob$MapperClass.map(HadoopJob.java:1)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:436)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)
13/05/18 21:04:56 INFO mapred.JobClient: map 0% reduce 0%
13/05/18 21:04:56 INFO mapred.JobClient: Job complete: job_local_0001
13/05/18 21:04:56 INFO mapred.JobClient: Counters: 0
13/05/18 21:04:56 INFO mapred.JobClient: Job Failed: NA
Exception in thread "main" java.io.IOException: Job failed!
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:1265)
at com.sis.hadoop.wordcount.HadoopJob.run(HadoopJob.java:88)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at com.sis.hadoop.wordcount.HadoopJob.main(HadoopJob.java:58)

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