public class CsvOutputFormat<T extends Tuple> extends FileOutputFormat<T> implements InputTypeConfigurable
Tuple
s 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.FileOutputFormat.AbstractConfigBuilder<T>, FileOutputFormat.ConfigBuilder, FileOutputFormat.OutputDirectoryMode
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_FIELD_DELIMITER |
static String |
DEFAULT_LINE_DELIMITER |
FILE_PARAMETER_KEY, outputFilePath, stream
Constructor and Description |
---|
CsvOutputFormat(Path outputPath)
Creates an instance of CsvOutputFormat.
|
CsvOutputFormat(Path outputPath,
String fieldDelimiter)
Creates an instance of CsvOutputFormat.
|
CsvOutputFormat(Path outputPath,
String recordDelimiter,
String fieldDelimiter)
Creates an instance of CsvOutputFormat.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
open(int taskNumber,
int numTasks) |
void |
setAllowNullValues(boolean allowNulls)
Configures the format to either allow null values (writing an empty field),
or to throw an exception when encountering a null field.
|
void |
setCharsetName(String charsetName)
Sets the charset with which the CSV strings are written to the file.
|
void |
setInputType(TypeInformation<?> type)
The purpose of this method is solely to check whether the data type to be processed
is in fact a tuple type.
|
void |
setQuoteStrings(boolean quoteStrings)
Configures whether the output format should quote string values.
|
String |
toString() |
void |
writeRecord(T element) |
configure, configureFileFormat, getOutputDirectoryMode, getOutputFilePath, getWriteMode, initializeGlobal, setOutputDirectoryMode, setOutputFilePath, setWriteMode, tryCleanupOnError
public static final String DEFAULT_LINE_DELIMITER
public static final String DEFAULT_FIELD_DELIMITER
public CsvOutputFormat(Path outputPath)
outputPath
- The path where the CSV file is written.public CsvOutputFormat(Path outputPath, String fieldDelimiter)
outputPath
- The path where the CSV file is written.fieldDelimiter
- The delimiter that is used to separate fields in a tuple.public CsvOutputFormat(Path outputPath, String recordDelimiter, String fieldDelimiter)
outputPath
- The path where the CSV file is written.recordDelimiter
- The delimiter that is used to separate the tuples.fieldDelimiter
- The delimiter that is used to separate fields in a tuple.public void setAllowNullValues(boolean allowNulls)
by default, null values are allowed.
allowNulls
- Flag to indicate whether the output format should accept null values.public void setCharsetName(String charsetName)
charsetName
- The name of charset to use for encoding the output.public void setQuoteStrings(boolean quoteStrings)
String
and StringValue
, as well as
all subclasses of the latter.
By default, strings are not quoted.
quoteStrings
- Flag indicating whether string fields should be quoted.public void open(int taskNumber, int numTasks) throws IOException
open
in interface OutputFormat<T extends Tuple>
open
in class FileOutputFormat<T extends Tuple>
IOException
public void close() throws IOException
close
in interface OutputFormat<T extends Tuple>
close
in class FileOutputFormat<T extends Tuple>
IOException
public void writeRecord(T element) throws IOException
writeRecord
in interface OutputFormat<T extends Tuple>
IOException
public void setInputType(TypeInformation<?> type)
setInputType
in interface InputTypeConfigurable
type
- The data type of the input.Copyright © 2015 The Apache Software Foundation. All rights reserved.