Hadoop mapreduceの使用私は、異なる長さの部分文字列を取得するコードを書いています。長さ3( "ZYX"、 "YXC"、 "XCB"、 "CBA")、長さ4( "ZYXC"、 "YXCB")の可能なすべての文字列を返す必要があります。 、 "XCBA")最後に長さ5( "ZYXCB"、 "YXCBA")。ClassNotFoundException in Hadoop
キーは=サブストリングの長さは、私が
値= "ZYXCBA" たい:mapフェーズで
は、私は次のようでした。
のでマッパー出力は
3,"ZYXCBA"
4,"ZYXCBA"
5,"ZYXCBA"
では、私は長さ3の全ての部分文字列が同じ取得するには、文字列(「ZYXCBA」)とキー3を取る軽減される4,5のために発生します。結果はArrayListに集められます。
私は、コマンドに続く使用して私のコードを実行しています:以下に示すように
[email protected]:~/Documents$ hadoop jar Saishingles.jar hadoopshingles.Saishingles Behara/Shingles/input Behara/Shingles/output
私のコードがある::
package hadoopshingles;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class Saishingles{
public static class shinglesmapper extends Mapper<Object, Text, IntWritable, Text>{
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
String str = new String(value.toString());
String[] list = str.split(" ");
int index = Integer.parseInt(list[0]);
String val = list[1];
int length = val.length();
for(int i = index; i <= length; i++)
{
context.write(new IntWritable(index),new Text(val));
}
}
}
public static class shinglesreducer extends Reducer<IntWritable,Text,IntWritable,ArrayList<String>> {
private ArrayList<String> result = new ArrayList<String>();
public void reduce(IntWritable key, Text value, Context context
) throws IOException, InterruptedException {
String str = new String(value.toString());
int newkey = key.get();
int Tz = str.length() - newkey + 1;
int position = 0;
while (position <= Tz)
{
result.add(str.substring(position,position + newkey -1));
position = position + 1;
}
context.write(new IntWritable(newkey),result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "Saishingles");
job.setJarByClass(hadoopshingles.Saishingles.class);
job.setMapperClass(shinglesmapper.class);
job.setCombinerClass(shinglesreducer.class);
job.setReducerClass(shinglesreducer.class);
job.setMapOutputKeyClass(IntWritable.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(ArrayList.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
それは、次のエラーを与えている:
Exception in thread "main" java.lang.ClassNotFoundException: hadoopshingles.Saishingles
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
を助けてください私と事前に感謝:)
ありがとうございましたが、うまくいきませんでした –
あなたは今でも同じ例外または異なるものを取得していますか?また、適切なディレクトリ構造を持つクラスがJarファイルに含まれているかどうかを確認しましたか? – Amit
同じ例外が発生しています –