public class AvroKeyValueSinkWriter<K,V> extends StreamWriterBase<org.apache.flink.api.java.tuple.Tuple2<K,V>> implements Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>, org.apache.flink.api.java.typeutils.InputTypeConfigurable
Usage:
BucketingSink<Tuple2<Long, Long>> sink = new BucketingSink<Tuple2<Long, Long>>("/tmp/path");
sink.setBucketer(new DateTimeBucketer<Tuple2<Long, Long>>("yyyy-MM-dd/HH/mm/"));
sink.setPendingSuffix(".avro");
Map<String, String> properties = new HashMap<>();
Schema longSchema = Schema.create(Type.LONG);
String keySchema = longSchema.toString();
String valueSchema = longSchema.toString();
properties.put(AvroKeyValueSinkWriter.CONF_OUTPUT_KEY_SCHEMA, keySchema);
properties.put(AvroKeyValueSinkWriter.CONF_OUTPUT_VALUE_SCHEMA, valueSchema);
properties.put(AvroKeyValueSinkWriter.CONF_COMPRESS, Boolean.toString(true));
properties.put(AvroKeyValueSinkWriter.CONF_COMPRESS_CODEC, DataFileConstants.SNAPPY_CODEC);
sink.setWriter(new AvroSinkWriter<Long, Long>(properties));
sink.setBatchSize(1024 * 1024 * 64); // this is 64 MB,
| 限定符和类型 | 类和说明 |
|---|---|
static class |
AvroKeyValueSinkWriter.AvroKeyValue<K,V>
A reusable Avro generic record for writing key/value pairs to the
file.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
CONF_COMPRESS |
static String |
CONF_COMPRESS_CODEC |
static String |
CONF_DEFLATE_LEVEL |
static String |
CONF_OUTPUT_KEY_SCHEMA |
static String |
CONF_OUTPUT_VALUE_SCHEMA |
static String |
CONF_XZ_LEVEL |
| 限定符 | 构造器和说明 |
|---|---|
protected |
AvroKeyValueSinkWriter(AvroKeyValueSinkWriter<K,V> other) |
|
AvroKeyValueSinkWriter(Map<String,String> properties)
C'tor for the writer.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
Closes the
Writer. |
AvroKeyValueSinkWriter<K,V> |
duplicate()
Duplicates the
Writer. |
long |
flush()
Flushes out any internally held data, and returns the offset that the file
must be truncated to at recovery.
|
void |
open(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
Initializes the
Writer for a newly opened bucket file. |
void |
setInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type,
org.apache.flink.api.common.ExecutionConfig executionConfig) |
void |
write(org.apache.flink.api.java.tuple.Tuple2<K,V> element)
Writes one element to the bucket file.
|
getPos, getStream, isSyncOnFlush, setSyncOnFlushpublic AvroKeyValueSinkWriter(Map<String,String> properties)
You can provide different properties that will be used to configure avro key-value writer as simple properties map(see example above)
properties - protected AvroKeyValueSinkWriter(AvroKeyValueSinkWriter<K,V> other)
public void open(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path path)
throws IOException
WriterWriter for a newly opened bucket file.
Any internal per-bucket initialization should be performed here.open 在接口中 Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>open 在类中 StreamWriterBase<org.apache.flink.api.java.tuple.Tuple2<K,V>>fs - The FileSystem containing the newly opened file.path - The Path of the newly opened file.IOExceptionpublic void close()
throws IOException
WriterWriter. If the writer is already closed, no action will be
taken. The call should close all state related to the current output file,
including the output stream opened in open.close 在接口中 Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>close 在类中 StreamWriterBase<org.apache.flink.api.java.tuple.Tuple2<K,V>>IOExceptionpublic long flush()
throws IOException
Writerflush 在接口中 Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>flush 在类中 StreamWriterBase<org.apache.flink.api.java.tuple.Tuple2<K,V>>IOExceptionpublic void write(org.apache.flink.api.java.tuple.Tuple2<K,V> element) throws IOException
Writerwrite 在接口中 Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>IOExceptionpublic void setInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type,
org.apache.flink.api.common.ExecutionConfig executionConfig)
setInputType 在接口中 org.apache.flink.api.java.typeutils.InputTypeConfigurableCopyright © 2014–2019 The Apache Software Foundation. All rights reserved.