本文整理汇总了Java中org.apache.avro.file.CodecFactory.deflateCodec方法的典型用法代码示例。如果您正苦于以下问题:Java CodecFactory.deflateCodec方法的具体用法?Java CodecFactory.deflateCodec怎么用?Java CodecFactory.deflateCodec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.file.CodecFactory
的用法示例。
在下文中一共展示了CodecFactory.deflateCodec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompressionCodec
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
private CodecFactory getCompressionCodec(Map<String, String> conf) {
if (getBoolean(conf, CONF_COMPRESS, false)) {
int deflateLevel = getInt(conf, CONF_DEFLATE_LEVEL, CodecFactory.DEFAULT_DEFLATE_LEVEL);
int xzLevel = getInt(conf, CONF_XZ_LEVEL, CodecFactory.DEFAULT_XZ_LEVEL);
String outputCodec = conf.get(CONF_COMPRESS_CODEC);
if (DataFileConstants.DEFLATE_CODEC.equals(outputCodec)) {
return CodecFactory.deflateCodec(deflateLevel);
} else if (DataFileConstants.XZ_CODEC.equals(outputCodec)) {
return CodecFactory.xzCodec(xzLevel);
} else {
return CodecFactory.fromString(outputCodec);
}
}
return CodecFactory.nullCodec();
}
示例2: getCompressionCodec
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
private CodecFactory getCompressionCodec(Map<String,String> conf) {
if (getBoolean(conf, CONF_COMPRESS, false)) {
int deflateLevel = getInt(conf, CONF_DEFLATE_LEVEL, CodecFactory.DEFAULT_DEFLATE_LEVEL);
int xzLevel = getInt(conf, CONF_XZ_LEVEL, CodecFactory.DEFAULT_XZ_LEVEL);
String outputCodec = conf.get(CONF_COMPRESS_CODEC);
if (DataFileConstants.DEFLATE_CODEC.equals(outputCodec)) {
return CodecFactory.deflateCodec(deflateLevel);
} else if (DataFileConstants.XZ_CODEC.equals(outputCodec)) {
return CodecFactory.xzCodec(xzLevel);
} else {
return CodecFactory.fromString(outputCodec);
}
}
return CodecFactory.nullCodec();
}
示例3: configureDataFileWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
static void configureDataFileWriter(DataFileWriter<GenericData.Record> writer,
JobConf job) throws UnsupportedEncodingException {
if (FileOutputFormat.getCompressOutput(job)) {
int level = job.getInt(DEFLATE_LEVEL_KEY,
DEFAULT_DEFLATE_LEVEL);
String codecName = job.get(AvroJob.OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory = codecName.equals(DEFLATE_CODEC)
? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
writer.setCodec(factory);
}
writer.setSyncInterval(job.getInt(SYNC_INTERVAL_KEY,
DEFAULT_SYNC_INTERVAL));
// copy metadata from job
for (Map.Entry<String,String> e : job) {
if (e.getKey().startsWith(AvroJob.TEXT_PREFIX))
writer.setMeta(e.getKey().substring(AvroJob.TEXT_PREFIX.length()),
e.getValue());
if (e.getKey().startsWith(AvroJob.BINARY_PREFIX))
writer.setMeta(e.getKey().substring(AvroJob.BINARY_PREFIX.length()),
URLDecoder.decode(e.getValue(), "ISO-8859-1")
.getBytes("ISO-8859-1"));
}
}
示例4: getRecordWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Override
public RecordWriter<NullWritable, Object> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
if (schema == null)
throw new IOException("Must provide a schema");
Configuration conf = context.getConfiguration();
DataFileWriter<Object> writer = new DataFileWriter<Object>(new PigAvroDatumWriter(schema));
if (FileOutputFormat.getCompressOutput(context)) {
int level = conf.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
String codecName = conf.get(OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory = codecName.equals(DEFLATE_CODEC)
? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
writer.setCodec(factory);
}
Path path = getDefaultWorkFile(context, EXT);
writer.create(schema, path.getFileSystem(conf).create(path));
return new PigAvroRecordWriter(writer);
}
示例5: configureDataFileWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
static <K> void configureDataFileWriter(DataFileWriter<K> writer,
JobConf job) throws UnsupportedEncodingException {
if (FileOutputFormat.getCompressOutput(job)) {
int level = job.getInt(org.apache.avro.mapred.AvroOutputFormat.DEFLATE_LEVEL_KEY,
org.apache.avro.mapred.AvroOutputFormat.DEFAULT_DEFLATE_LEVEL);
String codecName = job.get(AvroJob.OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory = codecName.equals(DEFLATE_CODEC) ?
CodecFactory.deflateCodec(level) : CodecFactory.fromString(codecName);
writer.setCodec(factory);
}
writer.setSyncInterval(job.getInt(org.apache.avro.mapred.AvroOutputFormat.SYNC_INTERVAL_KEY,
DEFAULT_SYNC_INTERVAL));
// copy metadata from job
for (Map.Entry<String,String> e : job) {
if (e.getKey().startsWith(AvroJob.TEXT_PREFIX))
writer.setMeta(e.getKey().substring(AvroJob.TEXT_PREFIX.length()),e.getValue());
if (e.getKey().startsWith(AvroJob.BINARY_PREFIX))
writer.setMeta(e.getKey().substring(AvroJob.BINARY_PREFIX.length()),
URLDecoder.decode(e.getValue(), "ISO-8859-1")
.getBytes("ISO-8859-1"));
}
}
示例6: configureDataFileWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
static <T> void configureDataFileWriter(DataFileWriter<T> writer,
TaskAttemptContext context) throws UnsupportedEncodingException {
if (FileOutputFormat.getCompressOutput(context)) {
int level = context.getConfiguration()
.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
String codecName = context.getConfiguration()
.get(org.apache.avro.mapred.AvroJob.OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory =
codecName.equals(DEFLATE_CODEC) ? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
writer.setCodec(factory);
}
writer.setSyncInterval(context.getConfiguration()
.getInt(SYNC_INTERVAL_KEY, DEFAULT_SYNC_INTERVAL));
// copy metadata from job
for (Map.Entry<String, String> e : context.getConfiguration()) {
if (e.getKey().startsWith(org.apache.avro.mapred.AvroJob.TEXT_PREFIX)) {
writer.setMeta(e.getKey()
.substring(org.apache.avro.mapred.AvroJob.TEXT_PREFIX.length()),
e.getValue());
}
if (e.getKey().startsWith(org.apache.avro.mapred.AvroJob.BINARY_PREFIX)) {
writer.setMeta(e.getKey()
.substring(org.apache.avro.mapred.AvroJob.BINARY_PREFIX.length()),
URLDecoder.decode(e.getValue(), "ISO-8859-1").getBytes("ISO-8859-1"));
}
}
}
示例7: readExternal
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
final String codecStr = in.readUTF();
switch (codecStr) {
case NULL_CODEC:
case SNAPPY_CODEC:
case BZIP2_CODEC:
codecFactory = CodecFactory.fromString(codecStr);
return;
}
Matcher deflateMatcher = deflatePattern.matcher(codecStr);
if (deflateMatcher.find()) {
codecFactory = CodecFactory.deflateCodec(
Integer.parseInt(deflateMatcher.group("level")));
return;
}
Matcher xzMatcher = xzPattern.matcher(codecStr);
if (xzMatcher.find()) {
codecFactory = CodecFactory.xzCodec(
Integer.parseInt(xzMatcher.group("level")));
return;
}
throw new IllegalStateException(codecStr + " is not supported");
}
示例8: testDeflateCodecSerDeWithLevels
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Test
public void testDeflateCodecSerDeWithLevels() throws Exception {
for (int i = 0; i < 10; ++i) {
SerializableAvroCodecFactory codecFactory = new SerializableAvroCodecFactory(
CodecFactory.deflateCodec(i));
SerializableAvroCodecFactory serdeC = SerializableUtils.clone(codecFactory);
assertEquals(CodecFactory.deflateCodec(i).toString(), serdeC.getCodec().toString());
}
}
示例9: getCodecFactory
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
/**
* Creates a {@link CodecFactory} based on the specified codec name and deflate level. If codecName is absent, then
* a {@link CodecFactory#deflateCodec(int)} is returned. Otherwise the codecName is converted into a
* {@link CodecFactory} via the {@link CodecFactory#fromString(String)} method.
*
* @param codecName the name of the codec to use (e.g. deflate, snappy, xz, etc.).
* @param deflateLevel must be an integer from [0-9], and is only applicable if the codecName is "deflate".
* @return a {@link CodecFactory}.
*/
public static CodecFactory getCodecFactory(Optional<String> codecName, Optional<String> deflateLevel) {
if (!codecName.isPresent()) {
return CodecFactory.deflateCodec(ConfigurationKeys.DEFAULT_DEFLATE_LEVEL);
} else if (codecName.get().equalsIgnoreCase(DataFileConstants.DEFLATE_CODEC)) {
if (!deflateLevel.isPresent()) {
return CodecFactory.deflateCodec(ConfigurationKeys.DEFAULT_DEFLATE_LEVEL);
} else {
return CodecFactory.deflateCodec(Integer.parseInt(deflateLevel.get()));
}
} else {
return CodecFactory.fromString(codecName.get());
}
}
示例10: getCodec
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
protected CodecFactory getCodec() {
if (CODEC_DEFLATE.equalsIgnoreCase(codec)) {
return CodecFactory.deflateCodec(codecLevel);
} else if (CODEC_SNAPPY.equalsIgnoreCase(codec)) {
return CodecFactory.snappyCodec();
} else if (CODEC_BZIP2.equalsIgnoreCase(codec)) {
return CodecFactory.bzip2Codec();
} else if (CODEC_XY.equalsIgnoreCase(codec)) {
return CodecFactory.xzCodec(codecLevel);
} else {
return CodecFactory.nullCodec();
}
}
示例11: getRecordWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Override
public RecordWriter<Text, Text> getRecordWriter(FileSystem ignored, JobConf job, String name,
Progressable progress) throws IOException {
if (schema == null) {
SchemaLoader loader = new SchemaLoader(job);
this.schema = loader.load(
job.get(SCHEMA_LITERAL), job.get(SCHEMA_URL), job.get(SCHEMA_TYPE_NAME));
this.converter = new JsonConverter(schema);
this.readKey = job.getBoolean(READ_KEY, true);
}
DataFileWriter<GenericRecord> writer = new DataFileWriter<GenericRecord>(
new GenericDatumWriter<GenericRecord>(schema));
if (getCompressOutput(job)) {
int level = job.getInt(AvroOutputFormat.DEFLATE_LEVEL_KEY, AvroOutputFormat.DEFAULT_DEFLATE_LEVEL);
String codecName = job.get(AvroJob.CONF_OUTPUT_CODEC,
org.apache.avro.file.DataFileConstants.DEFLATE_CODEC);
CodecFactory codec = codecName.equals(DataFileConstants.DEFLATE_CODEC)
? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
writer.setCodec(codec);
}
writer.setSyncInterval(job.getInt(AvroOutputFormat.SYNC_INTERVAL_KEY,
DataFileConstants.DEFAULT_SYNC_INTERVAL));
Path path = FileOutputFormat.getTaskOutputPath(job, name + AvroOutputFormat.EXT);
writer.create(schema, path.getFileSystem(job).create(path));
return new AvroAsJSONRecordWriter(writer, converter, readKey);
}
示例12: createDataFileWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
private DataFileWriter<GenericRecord> createDataFileWriter(DataFileReader<GenericRecord> dataFileReader) throws IllegalArgumentException,
IOException
{
Schema schema = dataFileReader.getSchema();
DatumWriter<GenericRecord> datumWriter =
new GenericDatumWriter<GenericRecord>(schema);
DataFileWriter<GenericRecord> writer =
new DataFileWriter<GenericRecord>(datumWriter);
// Get the codec of the reader
String codecStr = dataFileReader.getMetaString(DataFileConstants.CODEC);
int level = conf.getInt("avro.mapred.deflate.level", 1);
String codecName = conf.get("avro.output.codec", codecStr);
CodecFactory factory =
codecName.equals("deflate") ? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
// Set the codec of the writer
writer.setCodec(factory);
writer.setSyncInterval(conf.getInt("avro.mapred.sync.interval",
Math.max(conf.getInt("io.file.buffer.size",
16000), 16000)));
writer.create(schema,
new Path(tempFileName).getFileSystem(conf)
.create(new Path(tempFileName)));
return writer;
}
示例13: getRecordWriter
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Override
public RecordWriter<NullWritable, Object> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
if (schema == null)
throw new IOException("Must provide a schema");
Configuration conf = context.getConfiguration();
DataFileWriter<Object> writer = new DataFileWriter<Object>(new PigAvroDatumWriter(schema));
if (FileOutputFormat.getCompressOutput(context)) {
int level = conf.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
String codecName = conf.get(OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory = codecName.equals(DEFLATE_CODEC)
? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
writer.setCodec(factory);
}
// Do max as core-default.xml has io.file.buffer.size as 4K
writer.setSyncInterval(conf.getInt(SYNC_INTERVAL_KEY, Math.max(
conf.getInt("io.file.buffer.size", DEFAULT_SYNC_INTERVAL), DEFAULT_SYNC_INTERVAL)));
Path path = getDefaultWorkFile(context, EXT);
writer.create(schema, path.getFileSystem(conf).create(path));
return new PigAvroRecordWriter(writer);
}
示例14: open
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
@Override
public void open(Configuration conf,
JsonNode json,
BlockSchema schema,
Path root,
String filename) throws IOException
{
Path teePath = new Path(root, filename + ".avro");
FileSystem fs = FileSystem.get(conf);
Schema avroSchema = AvroUtils.convertFromBlockSchema("record", schema);
GenericDatumWriter<Object> datumWriter =
new PigAvroDatumWriter(avroSchema);
dataFileWriter = new DataFileWriter<Object>(datumWriter);
// if compression is requested, set the proper compression codec
if (PhaseContext.getConf().getBoolean("mapred.output.compress", false))
{
int level = conf.getInt(DEFLATE_LEVEL_KEY, DEFAULT_DEFLATE_LEVEL);
String codecName = conf.get(OUTPUT_CODEC, DEFLATE_CODEC);
CodecFactory factory =
codecName.equals(DEFLATE_CODEC) ? CodecFactory.deflateCodec(level)
: CodecFactory.fromString(codecName);
dataFileWriter.setCodec(factory);
}
dataFileWriter.create(avroSchema, fs.create(teePath));
}
示例15: getCodecFactory
import org.apache.avro.file.CodecFactory; //导入方法依赖的package包/类
/**
* Creates a {@link CodecFactory} based on the specified codec name and deflate level. If codecName is absent, then
* a {@link CodecFactory#deflateCodec(int)} is returned. Otherwise the codecName is converted into a
* {@link CodecFactory} via the {@link CodecFactory#fromString(String)} method.
*
* @param codecName the name of the codec to use (e.g. deflate, snappy, xz, etc.).
* @param deflateLevel must be an integer from [0-9], and is only applicable if the codecName is "deflate".
* @return a {@link CodecFactory}.
*/
public static CodecFactory getCodecFactory(Optional<String> codecName, Optional<String> deflateLevel) {
if (!codecName.isPresent()) {
return CodecFactory.deflateCodec(ConfigurationKeys.DEFAULT_DEFLATE_LEVEL);
} else if (codecName.get().equalsIgnoreCase(DataFileConstants.DEFLATE_CODEC)) {
if (!deflateLevel.isPresent()) {
return CodecFactory.deflateCodec(ConfigurationKeys.DEFAULT_DEFLATE_LEVEL);
}
return CodecFactory.deflateCodec(Integer.parseInt(deflateLevel.get()));
} else {
return CodecFactory.fromString(codecName.get().toLowerCase());
}
}