public class CsvOutputFormat extends FileOutputFormat
Records to text. The output is
structured by record delimiters and field delimiters as common in CSV files.
Record delimiter separate records from each other ('\n' is common). Field
delimiters separate fields within a record. Record and field delimiters can
be configured using the CsvOutputFormat Configuration.
The number of fields to serialize must be configured as well. For each field
the type of the Value must be specified using the
FIELD_TYPE_PARAMETER_PREFIX config key and an index
running from 0 to the number of fields.
The position within the Record can be configured for each field using
the RECORD_POSITION_PARAMETER_PREFIX config key.
Either all Record positions must be configured or none. If none is
configured, the index of the config key is used.Value,
Configuration,
Record,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected static class |
CsvOutputFormat.AbstractConfigBuilder<T>
Abstract builder used to set parameters to the input format's
configuration in a fluent way.
|
static class |
CsvOutputFormat.ConfigBuilder
A builder used to set parameters to the input format's configuration in a
fluent way.
|
FileOutputFormat.OutputDirectoryMode| Modifier and Type | Field and Description |
|---|---|
static String |
FIELD_DELIMITER_PARAMETER |
static String |
FIELD_TYPE_PARAMETER_PREFIX |
static String |
LENIENT_PARSING |
static String |
NUM_FIELDS_PARAMETER |
static String |
RECORD_DELIMITER_PARAMETER |
static String |
RECORD_POSITION_PARAMETER_PREFIX |
FILE_PARAMETER_KEY, outputFilePath, stream| Constructor and Description |
|---|
CsvOutputFormat() |
CsvOutputFormat(Class<? extends Value>... types)
Creates an instance of CsvOutputFormat.
|
CsvOutputFormat(String fieldDelimiter,
Class<? extends Value>... types)
Creates an instance of CsvOutputFormat.
|
CsvOutputFormat(String recordDelimiter,
String fieldDelimiter,
Class<? extends Value>... types)
Creates an instance of CsvOutputFormat.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
configure(Configuration parameters) |
static CsvOutputFormat.ConfigBuilder |
configureRecordFormat(FileDataSink target)
Creates a configuration builder that can be used to set the input
format's parameters to the config in a fluent fashion.
|
void |
open(int taskNumber,
int numTasks) |
void |
setLenient(boolean lenient) |
void |
setTypes(Class<? extends Value>... types) |
void |
writeRecord(Record record) |
configureFileFormat, getDirectoryFileName, getOutputDirectoryMode, getOutputFilePath, getWriteMode, initializeGlobal, setOutputDirectoryMode, setOutputFilePath, setWriteMode, tryCleanupOnErrorpublic static final String RECORD_DELIMITER_PARAMETER
public static final String FIELD_DELIMITER_PARAMETER
public static final String NUM_FIELDS_PARAMETER
public static final String FIELD_TYPE_PARAMETER_PREFIX
public static final String RECORD_POSITION_PARAMETER_PREFIX
public static final String LENIENT_PARSING
public CsvOutputFormat()
public CsvOutputFormat(Class<? extends Value>... types)
types - The types of the fields that are in the record.public CsvOutputFormat(String fieldDelimiter, Class<? extends Value>... types)
fieldDelimiter - The delimiter that is used to separate the different fields in
the record.types - The types of the fields that are in the record.public CsvOutputFormat(String recordDelimiter, String fieldDelimiter, Class<? extends Value>... types)
recordDelimiter - The delimiter that is used to separate the different records.fieldDelimiter - The delimiter that is used to separate the different fields in
the record.types - The types of the fields that are in the record.public void setLenient(boolean lenient)
public void configure(Configuration parameters)
configure in interface OutputFormat<Record>configure in class FileOutputFormat<Record>public void open(int taskNumber,
int numTasks)
throws IOException
open in interface OutputFormat<Record>open in class FileOutputFormat<Record>IOExceptionpublic void close()
throws IOException
close in interface OutputFormat<Record>close in class FileOutputFormat<Record>IOExceptionpublic void writeRecord(Record record) throws IOException
IOExceptionpublic static CsvOutputFormat.ConfigBuilder configureRecordFormat(FileDataSink target)
Copyright © 2015 The Apache Software Foundation. All rights reserved.