0

我有 2 个关于文本文件的数据库:USERS(firstName, lastName, tel, zipCode, city) CALLS(fromNumber, toNumber, duration) 我想使用 Java 将此 SQL 请求转换为 MapReduce

SELECT firstName, lastName
FROM users U, calls C
WHERE U.tel=C.toNumber AND U.City='Le Mans';

当我尝试在 Hadoop 集群上运行我的程序时java.lang.NoSuchMethodException,请帮帮我,这是我的完整代码:

class UsersCallsJoin 是程序名 UsrTokenizerMapper 是 USERS 文件的 Mapper CallsTokenizerMapper 是 CALLS 文件的 Mapper UsersCallsReducer 是 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);
            }
        } 

当我尝试执行它时 /home/hadoop/hadoop/bin/hadoop jar usercalljoin.jar UsersCallsJoin /path/to/users2.txt /path/to/calls2.txt 输出

这是我得到的错误

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)
4

0 回答 0