【问题标题】:java.lang.Exception: java.io.IOException: wrong value class while setting hadoop and hbasejava.lang.Exception:java.io.IOException:设置hadoop和hbase时值类错误
【发布时间】:2019-05-15 15:33:11
【问题描述】:

我对 Hadoop 和 Hbase 还很陌生,我正在努力让它们一起工作。我已经建立了一个.java 并获得了一个.jar 存档,没有任何错误。无论如何,在启动程序时出现此错误:

    java.lang.Exception: java.io.IOException: wrong value class: class org.apache.hadoop.hbase.client.Put is not class org.apache.hadoop.io.IntWritable
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
    Caused by: java.io.IOException: wrong value class: class org.apache.hadoop.hbase.client.Put is not class org.apache.hadoop.io.IntWritable
at org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:194)
at org.apache.hadoop.mapred.Task$CombineOutputCollector.collect(Task.java:1378)
at org.apache.hadoop.mapred.Task$NewCombinerRunner$OutputConverter.write(Task.java:1695)
at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:89)
at org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer$Context.write(WrappedReducer.java:105)
at TweetSentiment$ClassificationCounterReducer.reduce(TweetSentiment.java:131)
at TweetSentiment$ClassificationCounterReducer.reduce(TweetSentiment.java:114)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:171)
at org.apache.hadoop.mapred.Task$NewCombinerRunner.combine(Task.java:1716)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:1637)
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.flush(MapTask.java:1489)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.close(MapTask.java:723)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:844)

我不明白为什么。

我已经尝试了一些不同版本的 Hadoop 和 Hbase,但它似乎不起作用。这是我的代码:

public static class ClassificationCounterReducer extends TableReducer<IntWritable,IntWritable,IntWritable> {

        //private IntWritable result = new IntWritable();

        public void reduce(IntWritable classification, Iterable<IntWritable> values, Context context)
                throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {
                sum += val.get();
            }

            Put put = new Put(Bytes.toBytes(classification.toString()));

            put.addColumn( Bytes.toBytes("number"), Bytes.toBytes(""), Bytes.toBytes(sum) );
            context.write(classification, put);
        }
    }

    private static final String OUTPUT_TABLE = "sentiment";

    public int run(String[] args) throws Exception  {

        Job job = Job.getInstance(getConf(), "Sentiment Count");

        job.setJarByClass(TweetSentiment.class);
        job.setMapperClass(ClassificatorMapper.class);
        job.setCombinerClass(ClassificationCounterReducer.class);
        job.setReducerClass(ClassificationCounterReducer.class);

        TableMapReduceUtil.initTableReducerJob(
                OUTPUT_TABLE,
                TweetSentiment.ClassificationCounterReducer.class,
                job);

        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(IntWritable.class);

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

        System.exit(job.waitForCompletion(true) ? 0 : 1);

        return 0;
    }

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

该代码预计将对 Twitter 的推文进行情绪分析。 Mapper 应该从 HDFS 读取推文,对它们进行分类并将结果发送到组合器/归约器。 reducer 应该先计数,然后将它们存储在一个 hbase 表中,该表有两个条目,分别称为“Sentiment”和“Number”。

【问题讨论】:

    标签: java hadoop hbase


    【解决方案1】:

    您的类型不匹配 - 您正在输出 context.write(IntWritable, Put),但您的减速器类扩展了 TableReducer&lt;IntWritable,IntWritable,IntWritable&gt;

    将第一行改为:

    public static class ClassificationCounterReducer extends TableReducer<IntWritable,IntWritable,Put> {
    

    另外,取消组合器,它不会工作。

    【讨论】:

    • 我试着按照你说的取消组合器,而第一行保持不变。现在错误已经消失了,但程序仍然不会将任何结果保存到 hbase 表中。
    猜你喜欢
    • 2011-07-13
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 2012-02-08
    • 2016-07-14
    • 2012-12-04
    相关资源
    最近更新 更多