blob: 66ab94574d93d67589d7ceac8215d7a121c28944 (
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
61
62
63
64
65
66
67
68
69
70
|
// 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.Objects;
import java.util.Properties;
import java.util.logging.Logger;
import static com.yahoo.vespa.http.client.config.FeedParams.DataFormat.XML_UTF8;
/**
* An output specification for writing to Vespa instances in a Map-Reduce job.
* Mainly returns an instance of a {@link LegacyVespaRecordWriter} 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);
Boolean useLegacyClient = configuration.useLegacyClient().orElse(null);
if (Objects.equals(useLegacyClient, Boolean.TRUE) || configuration.dataFormat() == XML_UTF8) {
log.warning("Feeding with legacy client or XML will no longer be supported on Vespa 8. " +
"See https://docs.vespa.ai/en/vespa8-release-notes.html");
return new LegacyVespaRecordWriter(configuration, counters);
} else {
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 {
}
}
|