【问题标题】:How to use hadoop.mapreduce.lib.output.MultipleOutputs to create directory structure using oozie workflow?如何使用 hadoop.mapreduce.lib.output.MultipleOutputs 使用 oozie 工作流创建目录结构?
【发布时间】:2014-10-26 17:35:45
【问题描述】:

我正在使用 workflow:0.5" 运行我的 MR 作业。我的用例是为输出创建基于键的目录结构。 这是我的配置文件:-

`           
        <configuration>
                <!-- These are important. -->
                <property>
                    <name>mapred.mapper.new-api</name>
                    <value>true</value>
                </property>
                <property>
                    <name>mapred.reducer.new-api</name>
                    <value>true</value>
                </property>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queue.name}
                    </value>
                </property>
                <property>
                    <name>mapreduce.map.class</name>
                    <value>com.a.b.c.Amapper</value>
                </property>
                <property>
                    <name>mapreduce.reduce.class</name>
                    <value>com.a.b.c.Areducer</value>
                </property>
                <property>
                    <name>mapred.output.key.class</name>
                    <value>org.apache.hadoop.io.Text</value>
                </property>
                <property>
                    <name>mapred.output.value.class</name>
                    <value>org.apache.hadoop.io.Text</value>
                </property>
                <property>
                    <name>mapreduce.outputformat.class</name>
                    <value>org.apache.hadoop.mapreduce.lib.output.MultipleOutputs
                    </value>
                </property>
                <property>
                    <name>mapred.input.dir</name>
                    <value>${inputDir}</value>
                </property>
                <property>
                    <name>mapred.output.dir</name>
                    <value>${outputDir}</value>
                </property>
            </configuration>`

在 reducer 中,我想使用此代码创建格式化目录结构-

`public class Areducer extends Reducer<Text, Text, Text, Text> {
    private Text aggregatorRecord = new Text();
    private MultipleOutputs<Text, Text> out;

    public void setup(Context context) {
        out = new MultipleOutputs<Text, Text>(context);
    }

    public void reduce(Text aggregatorRecordKey,
            Iterable<Text> values, Context context)
            throws IOException, InterruptedException {
        /** 
           some business logic to do aggregation to set aggregatorRecord.
        */
        String plist = "Surname|Forename";
        Text t = new Text(plist);
        out.write(aggregatorRecordKey, aggregatorRecord, generateFileName(t));
    }

    protected void cleanup(Context context) throws IOException,
            InterruptedException {
        out.close();
    }

    private String generateFileName(Text k) {
        String[] kStr = k.toString().split("\\|");

        String sName = kStr[0];
        String fName = kStr[1];

        // example for k = Smith|John
        // output written to /user/hadoop/path/to/output/Smith/John-r-00000
        // (etc)
        return sName + "/" + fName;
    }

`

oozie 工作流给出了这个异常

java.lang.NoSuchMethodException: org.apache.hadoop.mapreduce.lib.output.MultipleOutputs.()

有人可以建议使用 MultipleOutputs 使用 oozie 工作流创建目录结构的正确方法吗?

【问题讨论】:

    标签: java hadoop bigdata oozie oozie-coordinator


    【解决方案1】:

    您的问题是 MultipleOutputs 不是 OutputFormat ,因此您没有将其设置为工作的输出格式。我通常使用 java 类来配置和提交我的 MultipleOutputs 作业,但是查看您的代码,我认为您需要将输出格式类型设置为 TextOutputFormat 并将您对 reducer 变量的引用保持原样。

    【讨论】:

    • 非常感谢。有效。最初,我坚持定义 org.apache.hadoop.mapreduce.lib.output.MultipleOutputs,但将其更改为 org.apache.hadoop.mapreduce.lib.output。 TextOutputFormat,解决了我的问题。但是我在输出中得到这样的目录文件结构:- /outputDir/Surname /outputDir/Surname/Forename-r-00000 /outputDir/_SUCCESS /outputDir/part-r-00000,我想在'Surname'目录中获得_SUCCESS使用 Forename-r-00000(因为它需要标志来启动其他相关作业)。那么不写java类,是不是就不能搞定呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多