简体   繁体   中英

How to use hadoop.mapreduce.lib.output.MultipleOutputs to create directory structure using oozie workflow?

I am running my MR jobs using workflow:0.5". My use case to create key based directory structure for output. This is my configuration file:-

`           
        <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>`

In reducer, i want to create formatted directory structure using this code-

`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 workflow gives this exception

java.lang.NoSuchMethodException: org.apache.hadoop.mapreduce.lib.output.MultipleOutputs.<\\init>()

Can someone suggest the correct approach to use MultipleOutputs to create directory structure using oozie workflow?

Your problem is that MultipleOutputs is not an OutputFormat and so you don't set it as the output format for your job. I usually use a java class to configure and submit my MultipleOutputs jobs, but looking at your code I think what you need to to is set your output format type to TextOutputFormat and leave your references to reducer variable as they are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM