【问题标题】:MapReduce-Cassandra wordcount compilation error: ConfigHelper not foundMapReduce-Cassandra wordcount 编译错误:找不到 ConfigHelper
【发布时间】:2014-02-27 16:28:35
【问题描述】:

我正在尝试运行 WordCount MapReduce 程序来读取和计算存储在 Cassandra 表(列族)中的数据,但是,当我编译我的程序时,我重复出现相同的错误。下面是我的源代码和我得到的错误。谁能帮我解决这个问题?提前致谢。

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import org.apache.cassandra.db.IColumn;
import org.apache.cassandra.hadoop.*;
import org.apache.cassandra.hadoop.ColumnFamilyInputFormat;
import org.apache.cassandra.hadoop.ConfigHelper;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.utils.ByteBufferUtil;

/**
 * This sums the word count stored in the input_words_count ColumnFamily for the key "key-if-verse1".
 *
 * Output is written to a text file.
 */
public class WordCountCounters extends Configured implements Tool
{
   private static final Logger logger = LoggerFactory.getLogger(WordCountCounters.class);

     static final String COUNTER_COLUMN_FAMILY = "input_words";
     private static final String OUTPUT_PATH_PREFIX = "/Users/Deepu/Documents/dse-3.2.4/dse-data/word_count_counters";


     public static void main(String[] args) throws Exception
    {
     // Let ToolRunner handle generic command-line options
     ToolRunner.run(new Configuration(), new WordCountCounters(), args);
     System.exit(0);
    }

public static class SumMapper extends Mapper<ByteBuffer, SortedMap<ByteBuffer, IColumn>, Text, LongWritable>
{
    public void map(ByteBuffer key, SortedMap<ByteBuffer, IColumn> columns, Context context) throws IOException, InterruptedException
    {
        long sum = 0;
        for (IColumn column : columns.values())
        {
            logger.debug("read " + key + ":" + column.name() + " from " + context.getInputSplit());
            sum += ByteBufferUtil.toLong(column.value());
        }
        context.write(new Text(ByteBufferUtil.string(key)), new LongWritable(sum));
    }
}

public int run(String[] args) throws Exception
{
    Job job = new Job(getConf(), "wordcountcounters");
    job.setJarByClass(WordCountCounters.class);
    job.setMapperClass(SumMapper.class);

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(LongWritable.class);
    FileOutputFormat.setOutputPath(job, new Path(OUTPUT_PATH_PREFIX));


    job.setInputFormatClass(ColumnFamilyInputFormat.class);


    ConfigHelper.setRpcPort(job.getConfiguration(), "9160");
    ConfigHelper.setInitialAddress(job.getConfiguration(), "localhost");
    ConfigHelper.setPartitioner(job.getConfiguration(), "org.apache.cassandra.dht.RandomPartitioner");
    ConfigHelper.setInputColumnFamily(job.getConfiguration(), WordCount.KEYSPACE, WordCountCounters.COUNTER_COLUMN_FAMILY);
    SlicePredicate predicate = new SlicePredicate().setSlice_range(
                                                                    new SliceRange().
                                                                    setStart(ByteBufferUtil.EMPTY_BYTE_BUFFER).
                                                                    setFinish(ByteBufferUtil.EMPTY_BYTE_BUFFER).
                                                                    setCount(100));
    ConfigHelper.setInputSlicePredicate(job.getConfiguration(), predicate);

    job.waitForCompletion(true);
    return 0;
 }
}

编译错误是:

【问题讨论】:

    标签: java hadoop mapreduce cassandra datastax-enterprise


    【解决方案1】:

    因为你可能注释掉了这两行:

    //import org.apache.cassandra.hadoop.ColumnFamilyInputFormat; //import org.apache.cassandra.hadoop.ConfigHelper;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多