Mahout:缺少创建序列文件的类

时间:2015-03-11 14:06:11

标签: java hadoop mahout mahout-recommender sequencefile

我按照the mahout site的说明将现有文件转换为序列文件:

VectorWriter vectorWriter = SequenceFile.createWriter(filesystem,
                                                  configuration,
                                                  outfile,
                                                  LongWritable.class,
                                                  SparseVector.class);

long numDocs = vectorWriter.write(new VectorIterable(), Long.MAX_VALUE);

我在maven项目中加入了mahout jar:

    <dependency>
        <groupId>org.apache.mahout</groupId>
        <artifactId>mahout-core</artifactId>
        <version>0.9</version>
    </dependency>

但它不会写文件。

我收到此错误:

Caused by: java.lang.NullPointerException
at org.apache.hadoop.io.serializer.SerializationFactory.getSerializer(SerializationFactory.java:73)
at org.apache.hadoop.io.SequenceFile$Writer.init(SequenceFile.java:963)
at org.apache.hadoop.io.SequenceFile$RecordCompressWriter.<init>(SequenceFile.java:1136)
at org.apache.hadoop.io.SequenceFile.createWriter(SequenceFile.java:397)
at org.apache.hadoop.io.SequenceFile.createWriter(SequenceFile.java:284)
at org.apache.hadoop.io.SequenceFile.createWriter(SequenceFile.java:265)

经过进一步调查后,由以下原因引起:

Serilization class not found: java.lang.ClassNotFoundException: org.apache.hadoop.io.serializer.WritableSerialization

这告诉我,我错过了一个罐子 - 有谁知道哪一个?

1 个答案:

答案 0 :(得分:0)

问题是我在Lenskit中使用它,Configuration类试图使用Thread.currentThread().getContextClassLoader()(无论出于何种原因)没有mahout或hadoop包。完整的代码是:

final Configuration configuration = new Configuration();
configuration.setClassLoader(Configuration.class.getClassLoader());

final Path path = new Path(POINTS_PATH + "/pointsFile");

LocalFileSystem fs = new LocalFileSystem();
fs.initialize(URI.create(POINTS_PATH + "/pointsFile"), configuration);

final SequenceFile.Writer writer =
        SequenceFile.createWriter(
                fs,
                configuration,
                path,
                Text.class,
                VectorWritable.class);