本文整理汇总了Java中org.apache.avro.file.DataFileWriter.setSyncInterval方法的典型用法代码示例。如果您正苦于以下问题:Java DataFileWriter.setSyncInterval方法的具体用法?Java DataFileWriter.setSyncInterval怎么用?Java DataFileWriter.setSyncInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.file.DataFileWriter
的用法示例。
在下文中一共展示了DataFileWriter.setSyncInterval方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeToStream
import org.apache.avro.file.DataFileWriter; //导入方法依赖的package包/类
/**
* Writes the given {@link DataEvent}s from the eventStream into the
* {@link OutputStream} using avro's object container format (see
* {@link DataFileWriter}). Please note: As this method is creating the
* {@link OutputStream} via the {@link Supplier}, the {@link OutputStream}
* is as well closed by this method.
*
*
* @param eventStream
* a stream of valid and normalized {@link DataEvent}.
* @param out
* a {@link Supplier} of an output stream
* @throws IOException
*/
public static void writeToStream(Stream<DataEvent> eventStream, Supplier<OutputStream> outSupplier) throws IOException {
final OutputStream out = outSupplier.get();
@Cleanup
final DataFileWriter<DataEvent> writer = new DataFileWriter<>(DataEventSerializer.getWRITER());
writer.setSyncInterval(1024 * 1024);
writer.setCodec(CodecFactory.deflateCodec(9));
writer.setMeta("created_at", new Date().getTime());
writer.create(DataEvent.SCHEMA$, out);
eventStream.forEach(event -> {
try {
writer.append(event);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
示例2: configureDataFileWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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"));
}
}
示例3: configureDataFileWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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"));
}
}
示例4: configureDataFileWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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"));
}
}
}
示例5: testIncorrectOffset
import org.apache.avro.file.DataFileWriter; //导入方法依赖的package包/类
@Test
public void testIncorrectOffset() throws Exception {
File avroDataFile = SdcAvroTestUtil.createAvroDataFile();
avroDataFile.delete();
Schema schema = new Schema.Parser().parse(AVRO_SCHEMA);
DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema);
DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter);
dataFileWriter.create(schema, avroDataFile);
for (int i = 0; i < 5; i++) {
GenericRecord r = new GenericData.Record(schema);
r.put("name", NAMES[i % NAMES.length]);
r.put("id", i);
dataFileWriter.setSyncInterval(1073741824);
dataFileWriter.append(r);
dataFileWriter.sync();
}
dataFileWriter.flush();
dataFileWriter.close();
DataParserFactoryBuilder dataParserFactoryBuilder = new DataParserFactoryBuilder(getContext(),
DataParserFormat.AVRO);
DataParserFactory factory = dataParserFactoryBuilder
.setMaxDataLen(1024 * 1024)
.setOverRunLimit(1000 * 1000)
.setConfig(SCHEMA_SOURCE_KEY, SOURCE)
.build();
DataParser dataParser = factory.getParser(avroDataFile, null);
Map<String, Record> records = new HashMap<>();
Record record;
while((record = dataParser.parse()) != null) {
records.put(dataParser.getOffset(), record);
}
Assert.assertEquals(String.valueOf(records), 5, records.size());
Assert.assertEquals(0, records.get("141::1").get("/id").getValueAsInteger());
Assert.assertEquals(1, records.get("166::1").get("/id").getValueAsInteger());
Assert.assertEquals(2, records.get("190::1").get("/id").getValueAsInteger());
Assert.assertEquals(3, records.get("215::1").get("/id").getValueAsInteger());
Assert.assertEquals(4, records.get("239::1").get("/id").getValueAsInteger());
}
示例6: getRecordWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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);
}
示例7: createDataFileWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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;
}
示例8: getRecordWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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);
}
示例9: configureDataFileWriter
import org.apache.avro.file.DataFileWriter; //导入方法依赖的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);
}
// Do max as core-default.xml has io.file.buffer.size as 4K
writer.setSyncInterval(job.getInt(SYNC_INTERVAL_KEY, Math.max(
job.getInt("io.file.buffer.size", DEFAULT_SYNC_INTERVAL), 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"));
}
}