i have 2 databases on text files: USERS(firstName, lastName, tel, zipCode, city) CALLS(fromNumber, toNumber, duration) i would like to translate this SQL request to MapReduce using Java
SELECT firstName, lastName
FROM users U, calls C
WHERE U.tel=C.toNumber AND U.City='Le Mans';
when i try to run my program on Hadoop cluster I get java.lang.NoSuchMethodException
, Help me please, this is my full code:
class UsersCallsJoin is the Program name UsrTokenizerMapper is the Mapper of USERS file CallsTokenizerMapper is the Mapper of CALLS file UsersCallsReducer is the reducer
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.MultipleInputs;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class UsersCallsJoin {
public static class UsrTokenizerMapper extends Mapper <Object, Text, Text, Text> {
public void map (Object key, Text value, Context context) throws IOException, InterruptedException {
String record = value.toString();
String[] parts = record.split(",");
if (parts[4] == "LE MANS")
context.write(new Text(parts[2]),new Text("usr\t" + parts[0]+":"+parts[1]));
}
}
public static class CallsTokenizerMapper extends Mapper <Object, Text, Text, Text> {
public void map (Object key, Text value, Context context) throws IOException, InterruptedException {
String record = value.toString();
String[] parts = record.split(",");
context.write(new Text(parts[1]), new Text("calls"));
}
}
public static class UsersCallsReducer extends Reducer <Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
String name = "";
boolean callOK = false;
boolean UsrOK = false;
for (Text t : values) {
//String parts[] = t.toString().split("\t");
if (t.toString().startsWith("usr")){
UsrOK = true;
parts = t.toString().split("\t");
name = parts[1];
}
else if (t.toString().startsWith("calls"))
callOK = true;
}
if (UsrOK && callOK) {
context.write(new Text(name), new Text(""));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "user call");
job.setJarByClass(UsersCallsJoin.class);
job.setReducerClass(UsersCallsReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
MultipleInputs.addInputPath(job, new Path(args[0]),TextInputFormat.class, UsrTokenizerMapper.class);
MultipleInputs.addInputPath(job, new Path(args[1]),TextInputFormat.class, CallsTokenizerMapper.class);
Path outputPath = new Path(args[2]);
FileOutputFormat.setOutputPath(job, outputPath);
outputPath.getFileSystem(conf).delete(outputPath);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
when I try to excuete it /home/hadoop/hadoop/bin/hadoop jar usercalljoin.jar UsersCallsJoin /path/to/users2.txt /path/to/calls2.txt output
This is the error that i am getting
Exception in thread "main" java.lang.NoSuchMethodException: UsersCallsJoin.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1786)
at org.apache.hadoop.util.RunJar.run(RunJar.java:228)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148)