由于globStatus,MapReduce Job不生成输出

时间:2015-03-31 07:23:29

标签: java json hadoop gson

我不确定为什么我的Mapper和Reducer没有输出。我的代码背后的逻辑是,给定一个UUID文件(换行新行),我想使用globStatus显示UUID可能所在的所有潜在文件的所有路径。打开并读取文件。每个文件包含1-n行JSON。 UUID位于JSON中的event_header.event_id

现在MapReduce作业运行没有错误。然而,有些事情是错误的,因为我没有任何输出。我也不确定如何调试MapReduce作业。如果有人能为我提供一个非常棒的来源!该程序的预期输出应为

fee90c3f-e832-4267-aa9b-250f53kc06d3 1
914938ae-eed6-4dfa-81bf-71e67m42d93a 1
bbge6012-9c51-4ae1-9242-a4aaf08bfb36 1
e5a12493-gtrf-4ar4-9235-02fd3h580970 1
3b054300-09ba-4d59-a6ac-a0975ca74ed5 1
6fbb1c5g-15ce-4e6f-9236-55a9d9d6e2c6 1
ab4677a3-0f58-428c-8h58-5fe3dfe528dc 1
caaa011d-ahba-4ne7-9h05-3872f3k1854c 1

示例JSON:

{"event_header":{"version":"1.0","event_id":"fdk32k23-f7f6-412d-879d-f79b4c3b0d55","server_timestamp":1427734304673,"client_ip_address":"10.144.28.48","server_ip_address":"10.129.67.0"},"data_version":"1.0","application":{"properties":{}},"session":{"test":false,"user_id":"1121057496"},"event":{"timestamp":"1427734304577","event_category":"User","traffic":{"priority_code":"1728300000"},"event_id":"9ad26251-b940-408a-b6a9-0a825be1fd38","event_name":"Create"}}

在我的逻辑中,输出文件应该是UUID,它们旁边有1,因为在找到时,写入1,如果未找到,则写入0。它们应该全是1,因为我从源中提取了UUID。

我在for循环中添加了行context.write(new Text("None"), new Text("blank")),我发现没有任何内容写入输出。所以我想我可以安全地断定我错误地使用了globStatus() link

我的Reducer目前没有做任何事情,除了我只是想看看我是否可以使用一些简单的逻辑。我的代码中很可能存在错误,因为我不知道如何调试MapReduce作业。

驱动:

public class SearchUUID {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "UUID Search");
        job.getConfiguration().set("mapred.job.queue.name", "exp_dsa");
        job.setJarByClass(SearchUUID.class);
        job.setMapperClass(UUIDMapper.class);
        job.setReducerClass(UUIDReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

UUIDMapper:

public class UUIDMapper extends Mapper<Object, Text, Text, Text> {
    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

        try {
            Text one = new Text("1");
            Text zero = new Text("0");

            FileSystem fs = FileSystem.get(new Configuration());
            FileStatus[] paths = fs.globStatus(new Path("/data/path/to/file/d_20150330-1650"));
            for (FileStatus path : paths) {
                BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(path.getPath())));
                String json_string = br.readLine();
                while (json_string != null) {
                    JsonElement jelement = new JsonParser().parse(json_string);
                    JsonObject jsonObject = jelement.getAsJsonObject();
                    jsonObject = jsonObject.getAsJsonObject("event_header");
                    jsonObject = jsonObject.getAsJsonObject("event_id");

                    if (value.toString().equals(jsonObject.getAsString())) {
                        System.out.println(value.toString() + "slkdjfksajflkjsfdkljsadfk;ljasklfjklasjfklsadl;sjdf");
                        context.write(value, one);
                    } else {
                        context.write(value, zero);
                    }

                    json_string = br.readLine();
                }
            }
        } catch (IOException failed) {
        }
    }
}

减速机:

public class UUIDReducer extends Reducer<Text, Text, Text, Text>{

    public void reduce(Text key, Text value, Context context) throws IOException, InterruptedException{
        context.write(key, value);
    }
}

1 个答案:

答案 0 :(得分:1)

你检查了日志文件夹中的用户日志吗? 以下代码工作正常

jsonObject = jsonObject.getAsJsonObject(&#34; event_header&#34;);  jsonObject = jsonObject.getAsJsonObject(&#34; event_id&#34;);  这条线使用不正确  jsonObject.get(&#34; event_header&#34)。getAsJsonObject();  jsonObject.get(&#34; EVENT_ID&#34)。getAsJsonObject(); 问题出现在事件event_header,event_id JSONOBJECT。

public class UUIDMapper extends Mapper < Object, Text, Text, Text > {
    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        try {
            Text one = new Text("1");
            Text zero = new Text("0");
            String json_string[] = {
                "your data", "your data", "your data", "your data "
            };
            int i = 0;
            while (i < json_string.length) {
                if (value.toString().equals(json_string[i])) {
                    context.write(value, one);
                } else {
                    context.write(value, zero);
                }
            }
        } catch (Exception t) {
            t.printStackTrace();
        }
    }
}