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:
RollingSink<Tuple2<Long , Long>> sink = new RollingSink<Tuple2<Long , Long>>("/tmp/path");
sink.setBucketer(new DateTimeBucketer("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,
| Modifier and Type | Class and Description |
|---|---|
static class |
AvroKeyValueSinkWriter.AvroKeyValue<K,V> |
| Modifier and Type | Field and Description |
|---|---|
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 |
| Constructor and Description |
|---|
AvroKeyValueSinkWriter(Map<String,String> properties)
C'tor for the writer
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the
Writer. |
Writer<org.apache.flink.api.java.tuple.Tuple2<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, hflushOrSyncpublic static final String CONF_OUTPUT_KEY_SCHEMA
public static final String CONF_OUTPUT_VALUE_SCHEMA
public static final String CONF_COMPRESS
public static final String CONF_COMPRESS_CODEC
public static final String CONF_DEFLATE_LEVEL
public static final String CONF_XZ_LEVEL
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 in interface Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>open in class 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 in interface Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>close in class StreamWriterBase<org.apache.flink.api.java.tuple.Tuple2<K,V>>IOExceptionpublic long flush()
throws IOException
Writerflush in interface Writer<org.apache.flink.api.java.tuple.Tuple2<K,V>>flush in class 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 in interface 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 in interface org.apache.flink.api.java.typeutils.InputTypeConfigurableCopyright © 2014–2016 The Apache Software Foundation. All rights reserved.