gpt4 book ai didi

java - 从 map 获取 key 中的类型不匹配:预期的org.apache.hadoop.io.Text,收到org.apache.hadoop.io.LongWritable错误

转载 作者:行者123 更新时间:2023-12-02 21:20:16 24 4
gpt4 key购买 nike

我正在尝试使用Eclipse在Java中运行 map /缩小器。以下是我的代码

驱动程序代码:

package com.hadoop.training.criccount;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import javax.lang.model.SourceVersion;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import com.hadoop.training.hadooputility.HadoopUtility;
public class CricClickDriver extends Configured implements Tool{
public int run (String args[]) throws Exception
{
Configuration config =HadoopUtility.INSTANCE.pseudomode();


Job job = new Job(config, "No of clicks by location");
job.setJarByClass(CricClickDriver.class);

job.setInputFormatClass(TextInputFormat.class);

job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);

job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);

job.setMapperClass(CricClickMapper.class);
job.setReducerClass(CricClickReducer.class);

FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));

int exitcode = job.waitForCompletion(true)? 0:1;
return exitcode;
}
}

映射器代码:
package com.hadoop.training.criccount;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
@SuppressWarnings("unused")
public class CricClickMapper extends Mapper<LongWritable, Text,Text, LongWritable>{

public void CricketClick(LongWritable key, Text value, Context output) throws IOException, InterruptedException
{

String Line= value.toString();
String part[]=Line.split(" ");

if(part[0].contains("BAN"))
{
output.write(new Text(part[1]),new LongWritable(Long.parseLong(part[2])));
}

}
}

reducer 代码:
package com.hadoop.training.criccount;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class CricClickReducer extends Reducer<Text, LongWritable, Text, LongWritable>{
public void reduce(Text key, Iterable<LongWritable> value, Context output) throws IOException, InterruptedException
{
int sum=0;
for(LongWritable val:value){

sum +=val.get();
}
output.write(key, new LongWritable(sum));
}
}

我收到以下错误:
map 中键的类型不匹配

我尝试调试,但找不到根本原因。需要帮助。

最佳答案

您的Mapper类定义看起来不像documentation中提到的那样。
public class Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
还是在您在此处发布的代码中看不到它?

关于java - 从 map 获取 key 中的类型不匹配:预期的org.apache.hadoop.io.Text,收到org.apache.hadoop.io.LongWritable错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37597596/

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