org.apache.accumulo.hadoopImpl.mapreduce.FileOutputFormatBuilderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of accumulo-hadoop-mapreduce Show documentation
Show all versions of accumulo-hadoop-mapreduce Show documentation
Apache Accumulo MapReduce bindings.
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.hadoopImpl.mapreduce;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
import org.apache.accumulo.core.client.summary.SummarizerConfiguration;
import org.apache.accumulo.hadoop.mapreduce.FileOutputFormatBuilder;
import org.apache.accumulo.hadoopImpl.mapreduce.lib.FileOutputConfigurator;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapreduce.Job;
public class FileOutputFormatBuilderImpl implements FileOutputFormatBuilder,
FileOutputFormatBuilder.PathParams, FileOutputFormatBuilder.OutputOptions {
Class> callingClass;
Path outputPath;
Optional comp = Optional.empty();
Optional dataBlockSize = Optional.empty();
Optional fileBlockSize = Optional.empty();
Optional indexBlockSize = Optional.empty();
Optional replication = Optional.empty();
Optional sampler = Optional.empty();
Collection summarizers = Collections.emptySet();
public FileOutputFormatBuilderImpl(Class> callingClass) {
this.callingClass = callingClass;
}
@Override
public OutputOptions outputPath(Path path) {
this.outputPath = Objects.requireNonNull(path);
return this;
}
@Override
public OutputOptions compression(String compressionType) {
this.comp = Optional.of(compressionType);
return this;
}
@Override
public OutputOptions dataBlockSize(long dataBlockSize) {
this.dataBlockSize = Optional.of(dataBlockSize);
return this;
}
@Override
public OutputOptions fileBlockSize(long fileBlockSize) {
this.fileBlockSize = Optional.of(fileBlockSize);
return this;
}
@Override
public OutputOptions indexBlockSize(long indexBlockSize) {
this.indexBlockSize = Optional.of(indexBlockSize);
return this;
}
@Override
public OutputOptions replication(int replication) {
this.replication = Optional.of(replication);
return this;
}
@Override
public OutputOptions sampler(SamplerConfiguration samplerConfig) {
this.sampler = Optional.of(samplerConfig);
return this;
}
@Override
public OutputOptions summarizers(SummarizerConfiguration... summarizerConfigs) {
this.summarizers = Arrays.asList(Objects.requireNonNull(summarizerConfigs));
return this;
}
@Override
public void store(T j) {
if (j instanceof Job) {
store((Job) j);
} else if (j instanceof JobConf) {
store((JobConf) j);
} else {
throw new IllegalArgumentException("Unexpected type " + j.getClass().getName());
}
}
private void store(Job job) {
org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.setOutputPath(job, outputPath);
_store(job.getConfiguration());
}
private void _store(Configuration conf) {
if (comp.isPresent()) {
FileOutputConfigurator.setCompressionType(callingClass, conf, comp.orElseThrow());
}
if (dataBlockSize.isPresent()) {
FileOutputConfigurator.setDataBlockSize(callingClass, conf, dataBlockSize.orElseThrow());
}
if (fileBlockSize.isPresent()) {
FileOutputConfigurator.setFileBlockSize(callingClass, conf, fileBlockSize.orElseThrow());
}
if (indexBlockSize.isPresent()) {
FileOutputConfigurator.setIndexBlockSize(callingClass, conf, indexBlockSize.orElseThrow());
}
if (replication.isPresent()) {
FileOutputConfigurator.setReplication(callingClass, conf, replication.orElseThrow());
}
if (sampler.isPresent()) {
FileOutputConfigurator.setSampler(callingClass, conf, sampler.orElseThrow());
}
if (!summarizers.isEmpty()) {
FileOutputConfigurator.setSummarizers(callingClass, conf,
summarizers.toArray(new SummarizerConfiguration[0]));
}
}
private void store(JobConf job) {
org.apache.hadoop.mapred.FileOutputFormat.setOutputPath(job, outputPath);
_store(job);
}
}