我尝试使用“RandomSampler”对映射器结果进行分区。这是相关代码:

JobConf conf = new JobConf(SortExample.class);
conf.setJobName("sortexample");
...
conf.setPartitionerClass(TotalOrderPartitioner.class);
InputSampler.Sampler<IntWritable, Text> sampler =
    new InputSampler.RandomSampler<IntWritable, Text>(0.1, 100);
InputSampler.writePartitionFile(conf, sampler);
conf.setNumReduceTasks(2);

以我的理解,采样器将默认写入_patition.lst文件,该文件描述作业将自动用来确定将哪些键/值对发送给哪个reducer的分区。
但是运行后,出现以下错误:
ava.lang.RuntimeException: Error in configuring object
        at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:93)
        at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:64)
        at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:117)
        at org.apache.hadoop.mapred.MapTask$OldOutputCollector.<init>(MapTask.java:574)
        at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:436)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)
        at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:396)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1083)
        at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
        ... 10 more
Caused by: java.lang.IllegalArgumentException: Can't read partitions file
        at org.apache.hadoop.mapred.lib.TotalOrderPartitioner.configure(TotalOrderPartitioner.java:91)
        ... 15 more
Caused by: java.io.FileNotFoundException: File _partition.lst does not exist.

而且我不知道文件“_partition.lst”在哪里?这里一定会有一些误会,感谢您的帮助〜

最佳答案

我认为您需要在InputSample内部类之一上调用getSample()。这就是通过InputFormat读取文件并实际上弄清楚应该将哪些拆分放入_partition.lst文件中的内容。

关于hadoop - '_partition.lst'不存在错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13027180/

10-13 04:21