在spring数据hadoop上运行作业时出现的问题

hlswsv35  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(413)

我用mahout创建了以下Map器和还原器

package mypackage.ItemSimilarity;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.mahout.math.VarLongWritable;

public class ItemPrefMapper extends
        Mapper<LongWritable, Text, VarLongWritable, VarLongWritable> {

    private static final Pattern NUMBERS = Pattern.compile("(\\d+)");

    @Override
    public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String line = value.toString();
        Matcher m = NUMBERS.matcher(line);
        m.find();
        VarLongWritable userID = new VarLongWritable(Long.parseLong(m.group()));
        VarLongWritable itemID = new VarLongWritable();
        while (m.find()) {
            itemID.set(Long.parseLong(m.group()));
            context.write(userID, itemID);
        }
    }
}

降低等级

package mypackage.ItemSimilarity;

import java.io.IOException;

import org.apache.hadoop.mapreduce.Reducer;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.VarLongWritable;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;

public class UserVectorReducer
        extends
        Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable> {
    @Override
    public void reduce(VarLongWritable userID,
            Iterable<VarLongWritable> itemPrefs, Context context)
            throws IOException, InterruptedException {
        Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
        for (VarLongWritable itemPref : itemPrefs) {
            userVector.set((int) itemPref.get(), 1.0f);
        }
        context.write(userID, new VectorWritable(userVector));
    }

}

运行此命令的spring配置

<job id="mahoutJob" input-path="/home/ubuntu/input/data.txt" output-path="/home/ubuntu/output"
mapper="mypackage.ItemSimilarity.ItemPrefMapper" 
reducer="mypackage.ItemSimilarity.UserVectorReducer" 
jar-by-class="mypackage.ItemSimilarity.ItemPrefMapper"/>

<job-runner id="myjob-runner" pre-action="setupScript"  job-ref="mahoutJob" 
run-at-startup="true"/>

当我运行这个时,我得到了以下错误。我已经扩展了hadoopMap器类,但是spring说它不是一个Map器类。
java.lang.runtimeexception:class mypackage.itemsimilarity.itemprefmapper not org.apache.hadoop.mapreduce.mapper at org.apache.hadoop.conf.configuration.setclass(配置)。java:931)在org.apache.hadoop.mapreduce.job.setmapperclass(作业。java:175)在org.springframework.data.hadoop.mapreduce.jobfactorybean.afterpropertiesset(jobfactorybean。java:153)位于org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory)。java:1571)在org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory)。java:1509)位于org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory)。java:521)在org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory)。java:458)

von4xj4u

von4xj4u1#

你确定你的jar-by-class元素吗?因为它应该指向类似main方法的东西,在这里您可以示例化applicationcontext示例。
另外,你确定你的包裹名称吗?
com.threepillar.labs.itemsimilarity.itemprefmapper
以及
mypackage.itemsimilarity.itemprefmapper

相关问题