gpt4 book ai didi

java - 读取HDFS并存储HBase时为"java.io.IOException: Pass a Delete or a Put"

转载 作者:行者123 更新时间:2023-12-01 13:23:58 25 4
gpt4 key购买 nike

一周内我已经被这个错误搞疯了。有一个帖子有同样的问题Pass a Delete or a Put error in hbase mapreduce 。但这个决议对我来说并不真正有效。

我的司机:

 Configuration conf = HBaseConfiguration.create();
Job job;
try {
job = new Job(conf, "Training");
job.setJarByClass(TrainingDriver.class);
job.setMapperClass(TrainingMapper.class);
job.setMapOutputKeyClass(LongWritable.class);
job.setMapOutputValueClass(Text.class);
FileInputFormat.setInputPaths(job, new Path("my/path"));
Scan scan = new Scan();
scan.setCaching(500); // 1 is the default in Scan, which will be bad for MapReduce jobs
scan.setCacheBlocks(false); // don't set to true for MR jobs
// set other scan attrs
TableMapReduceUtil.initTableReducerJob(Constants.PREFIX_TABLE,
TrainingReducer.class, job);
job.setReducerClass(TrainingReducer.class);
//job.setNumReduceTasks(1); // at least one, adjust as required
try {
job.waitForCompletion(true);
} catch (ClassNotFoundException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

我的映射器:

public class TrainingMapper extends
Mapper<LongWritable, Text, LongWritable, Text> {

public void map(LongWritable key, Text value,
Context context)
throws IOException {
context.write(key, new Text(generateNewText());
}

我的 reducer

public class TrainingReducer extends TableReducer<LongWritable,Text,ImmutableBytesWritable>{

public void reduce(LongWritable key, Iterator<Text> values,Context context)
throws IOException {
while (values.hasNext()) {
try {
Put put = new Put(Bytes.toBytes(key.toString()));
put.add("cf1".getBytes(), "c1".getBytes(), values.next().getBytes());
context.write(null, put);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

您有这方面的经验吗?请告诉我如何修复它。

最佳答案

我自己找到了解决方案。

在我的reduce函数之前插入注释@Override并更改reduce函数的第二个参数,如下所示:@覆盖public void reduce(LongWritable key, Iterable value,Context context)

关于java - 读取HDFS并存储HBase时为"java.io.IOException: Pass a Delete or a Put",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887050/

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