Package org.apache.flink.api.common.io
Class FileOutputFormat<IT>
- java.lang.Object
-
- org.apache.flink.api.common.io.RichOutputFormat<IT>
-
- org.apache.flink.api.common.io.FileOutputFormat<IT>
-
- All Implemented Interfaces:
Serializable,CleanupWhenUnsuccessful,InitializeOnMaster,OutputFormat<IT>
- Direct Known Subclasses:
BinaryOutputFormat
@Public public abstract class FileOutputFormat<IT> extends RichOutputFormat<IT> implements InitializeOnMaster, CleanupWhenUnsuccessful
The abstract base class for all Rich output formats that are file based. Contains the logic to open/close the target file streams.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileOutputFormat.OutputDirectoryModeBehavior for creating output directories.-
Nested classes/interfaces inherited from interface org.apache.flink.api.common.io.OutputFormat
OutputFormat.InitializationContext
-
-
Field Summary
Fields Modifier and Type Field Description static StringFILE_PARAMETER_KEYDeprecated.protected PathoutputFilePathThe path of the file to be written.protected FSDataOutputStreamstreamThe stream to which the data is written;
-
Constructor Summary
Constructors Constructor Description FileOutputFormat()FileOutputFormat(Path outputPath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Method that marks the end of the life-cycle of parallel output instance.voidconfigure(Configuration parameters)Configures this output format.protected StringgetDirectoryFileName(int taskNumber)FileOutputFormat.OutputDirectoryModegetOutputDirectoryMode()PathgetOutputFilePath()FileSystem.WriteModegetWriteMode()static voidinitDefaultsFromConfiguration(Configuration configuration)Initialize defaults for output format.voidinitializeGlobal(int parallelism)Initialization of the distributed file system if it is used.voidopen(int taskNumber, int numTasks)Opens a parallel instance of the output format to store the result of its parallel instance.voidsetOutputDirectoryMode(FileOutputFormat.OutputDirectoryMode mode)voidsetOutputFilePath(Path path)voidsetWriteMode(FileSystem.WriteMode mode)voidtryCleanupOnError()Hook that is called upon an unsuccessful execution.-
Methods inherited from class org.apache.flink.api.common.io.RichOutputFormat
getRuntimeContext, setRuntimeContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.api.common.io.OutputFormat
open, writeRecord
-
-
-
-
Field Detail
-
FILE_PARAMETER_KEY
@Deprecated public static final String FILE_PARAMETER_KEY
Deprecated.The key under which the name of the target path is stored in the configuration.- See Also:
- Constant Field Values
-
outputFilePath
protected Path outputFilePath
The path of the file to be written.
-
stream
protected transient FSDataOutputStream stream
The stream to which the data is written;
-
-
Constructor Detail
-
FileOutputFormat
public FileOutputFormat()
-
FileOutputFormat
public FileOutputFormat(Path outputPath)
-
-
Method Detail
-
initDefaultsFromConfiguration
public static void initDefaultsFromConfiguration(Configuration configuration)
Initialize defaults for output format. Needs to be a static method because it is configured for local cluster execution.- Parameters:
configuration- The configuration to load defaults from
-
setOutputFilePath
public void setOutputFilePath(Path path)
-
getOutputFilePath
public Path getOutputFilePath()
-
setWriteMode
public void setWriteMode(FileSystem.WriteMode mode)
-
getWriteMode
public FileSystem.WriteMode getWriteMode()
-
setOutputDirectoryMode
public void setOutputDirectoryMode(FileOutputFormat.OutputDirectoryMode mode)
-
getOutputDirectoryMode
public FileOutputFormat.OutputDirectoryMode getOutputDirectoryMode()
-
configure
public void configure(Configuration parameters)
Description copied from interface:OutputFormatConfigures this output format. Since output formats are instantiated generically and hence parameterless, this method is the place where the output formats set their basic fields based on configuration values.This method is always called first on a newly instantiated output format.
- Specified by:
configurein interfaceOutputFormat<IT>- Parameters:
parameters- The configuration with all parameters.
-
open
public void open(int taskNumber, int numTasks) throws IOExceptionDescription copied from interface:OutputFormatOpens a parallel instance of the output format to store the result of its parallel instance.When this method is called, the output format it guaranteed to be configured.
- Specified by:
openin interfaceOutputFormat<IT>- Parameters:
taskNumber- The number of the parallel instance.numTasks- The number of parallel tasks.- Throws:
IOException- Thrown, if the output could not be opened due to an I/O problem.
-
getDirectoryFileName
protected String getDirectoryFileName(int taskNumber)
-
close
public void close() throws IOExceptionDescription copied from interface:OutputFormatMethod that marks the end of the life-cycle of parallel output instance. Should be used to close channels and streams and release resources. After this method returns without an error, the output is assumed to be correct.When this method is called, the output format it guaranteed to be opened.
- Specified by:
closein interfaceOutputFormat<IT>- Throws:
IOException- Thrown, if the input could not be closed properly.
-
initializeGlobal
public void initializeGlobal(int parallelism) throws IOExceptionInitialization of the distributed file system if it is used.- Specified by:
initializeGlobalin interfaceInitializeOnMaster- Parameters:
parallelism- The task parallelism.- Throws:
IOException- The initialization may throw exceptions, which may cause the job to abort.
-
tryCleanupOnError
public void tryCleanupOnError()
Description copied from interface:CleanupWhenUnsuccessfulHook that is called upon an unsuccessful execution.- Specified by:
tryCleanupOnErrorin interfaceCleanupWhenUnsuccessful
-
-