summaryrefslogtreecommitdiffstats
path: root/vespa-hadoop/src/main/java/com/yahoo/vespa/hadoop/mapreduce/VespaOutputFormat.java
blob: e49a5e179700e45afb57342b345b4a63ff8ba24e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hadoop.mapreduce;

import com.yahoo.vespa.hadoop.mapreduce.util.VespaConfiguration;
import com.yahoo.vespa.hadoop.mapreduce.util.VespaCounters;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.OutputCommitter;
import org.apache.hadoop.mapreduce.OutputFormat;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Logger;

/**
 * An output specification for writing to Vespa instances in a Map-Reduce job.
 * Mainly returns an instance of a {@link VespaRecordWriter} that does the
 * actual feeding to Vespa.
 *
 * @author lesters
 */
@SuppressWarnings("rawtypes")
public class VespaOutputFormat extends OutputFormat {

    private static final Logger log = Logger.getLogger(VespaOutputFormat.class.getName());

    final Properties configOverride;

    public VespaOutputFormat() {
        super();
        this.configOverride = null;
    }

    public VespaOutputFormat(Properties configOverride) {
        super();
        this.configOverride = configOverride;
    }


    @Override
    @SuppressWarnings("deprecation")
    public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException {
        VespaCounters counters = VespaCounters.get(context);
        VespaConfiguration configuration = VespaConfiguration.get(context.getConfiguration(), configOverride);
        return new VespaRecordWriter(configuration, counters);
    }


    @Override
    public OutputCommitter getOutputCommitter(TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException {
        return new VespaOutputCommitter();
    }


    @Override
    public void checkOutputSpecs(JobContext jobContext) throws IOException, InterruptedException {
    }

}