- All Implemented Interfaces:
LogicalOperator,RecordSinkOperator,SinkOperator<RecordPort>
- Direct Known Subclasses:
AbstractTextWriter,BinaryWriter,WriteAvro,WriteORC,WriteStagingDataset
- a sink for bytes, as identified by a
ByteSink. This is most often a file, so convenience methods for specifying the target as a file are provided. - common I/O tunables, such as buffer sizes
AbstractWriter wraps a WriteSink operator.
Implementations provide an interface specific to
an appropriate class of files - delimited text files, as an
example - hiding the more complex model used to describe
data parsing in general. The composition structure is the
same for all readers with only DataFormat used
differing between implementations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RecordPortThe input port of the read operatorprotected final FormattingOptionsContainer for options related to formatting -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWrites an empty target with default settings.protectedAbstractWriter(boolean includeDoneSignal) Writes an empty target with default settings, optionally providing a port for signaling completion of the write.protectedAbstractWriter(Path path, WriteMode mode) Writes to the specified path in the given mode.protectedAbstractWriter(ByteSink target, WriteMode mode) Writes to the specified target sink in the given mode.protectedAbstractWriter(String path, WriteMode mode) Writes to the specified path in the given mode. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidComposes a writer for the target, using configured options and a derived format.protected abstract DataFormatDetermines the data format for the target.Gets the formatting options used by the writer.getInput()Gets the record port providing the records to write to the target sink.getMode()Gets how existing files should be handled by the writer.booleanIf set to true, the writer will attempt to save the metadata with the data if the implementation supports it.Gets the data sink for the writer.intGets the size of the I/O buffer, in bytes, to use for writes.booleanIndicates whether the writer should write a file on the client.booleanIndicates whether the writer produces a single output file.booleanIf set to true, the writer will write in any order.voidsetFormatOptions(FormattingOptions options) Sets the formatting options used by the reader.voidsetIgnoreSortOrder(boolean ignoreSortOrder) If set to true, the writer will write in any order.voidSets how the writer should handle an existing target.voidsetSaveMetadata(boolean saveMetadata) If set to true, the writer will attempt to save the metadata with the data if the implementation supports it.voidSets the data sink for the writer.voidSets the data sink for the writer.voidSets the data sink for the writer.voidsetWriteBuffer(int size) Sets the size of the I/O buffer, in bytes, to use for writes.voidsetWriteOnClient(boolean enabled) Set whether the writer should write a file on the client.voidsetWriteSingleSink(boolean enabled) Set whether the writer should produce a single output file or multiple ones.Methods inherited from class com.pervasive.datarush.operators.AbstractLogicalOperator
disableParallelism, getInputPorts, getOutputPorts, newInput, newInput, newOutput, newRecordInput, newRecordInput, newRecordOutput, notifyErrorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pervasive.datarush.operators.LogicalOperator
disableParallelism, getInputPorts, getOutputPorts
-
Field Details
-
input
The input port of the read operator -
options
Container for options related to formatting
-
-
Constructor Details
-
AbstractWriter
protected AbstractWriter()Writes an empty target with default settings. The target must be set before execution or an error will be raised.- See Also:
-
AbstractWriter
protected AbstractWriter(boolean includeDoneSignal) Writes an empty target with default settings, optionally providing a port for signaling completion of the write. The target must be set before execution or an error will be raised.- Parameters:
includeDoneSignal- indicates whether a done signal port should be created- See Also:
-
AbstractWriter
Writes to the specified path in the given mode.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
- Parameters:
path- the path to which to writemode- how to handle existing files
-
AbstractWriter
Writes to the specified path in the given mode.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
- Parameters:
path- the path to which to writemode- how to handle existing files
-
AbstractWriter
Writes to the specified target sink in the given mode.The writer can only be parallelized if the sink is fragmentable. In this case, each partition will be written as an independent sink. Otherwise, the writer will run non-parallel.
- Parameters:
target- the sink to which to writemode- how to handle an existing sink
-
-
Method Details
-
getInput
Gets the record port providing the records to write to the target sink.- Specified by:
getInputin interfaceRecordSinkOperator- Specified by:
getInputin interfaceSinkOperator<RecordPort>- Returns:
- the input port for records to write
-
getTarget
Gets the data sink for the writer.- Returns:
- the write sink
-
setTarget
Sets the data sink for the writer.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
- Parameters:
path- the path to which to write
-
setTarget
Sets the data sink for the writer.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
- Parameters:
path- the path to which to write
-
setTarget
Sets the data sink for the writer.- Parameters:
sink- the sink to which to write
-
getMode
Gets how existing files should be handled by the writer.- Returns:
- the configured behavior with respect to target files
-
setMode
Sets how the writer should handle an existing target.- Parameters:
mode- the behavior to use for existing files
-
getFormatOptions
Gets the formatting options used by the writer.- Returns:
- the format options
-
setFormatOptions
Sets the formatting options used by the reader. This sets all format options at once.- Parameters:
options- the format options to use- See Also:
-
DataFormatter
-
getWriteBuffer
public int getWriteBuffer()Gets the size of the I/O buffer, in bytes, to use for writes.- Returns:
- the size of the write buffer
-
setWriteBuffer
public void setWriteBuffer(int size) Sets the size of the I/O buffer, in bytes, to use for writes. The default size is 64K.- Parameters:
size- the size of the write buffer
-
getWriteSingleSink
public boolean getWriteSingleSink()Indicates whether the writer produces a single output file.- Returns:
trueif the writer should write a single output,falseotherwise.
-
setWriteSingleSink
public void setWriteSingleSink(boolean enabled) Set whether the writer should produce a single output file or multiple ones. By default, an output file will be produced for each partition, if the target sink supports this.- Parameters:
enabled- indicates whether a single output file should be written
-
getWriteOnClient
public boolean getWriteOnClient()Indicates whether the writer should write a file on the client. This also disables the parallelism on the sink.- Returns:
trueif the writer should a file on the client,falseotherwise.
-
setWriteOnClient
public void setWriteOnClient(boolean enabled) Set whether the writer should write a file on the client. This has the effect of disabling the parallelism on the sink.- Parameters:
enabled- indicates whether the writer should write a file on the client.
-
isIgnoreSortOrder
public boolean isIgnoreSortOrder()If set to true, the writer will write in any order. If false, the writer will preserve the current sorted state of the input.- Returns:
- whether to ignore sort order.
-
setIgnoreSortOrder
public void setIgnoreSortOrder(boolean ignoreSortOrder) If set to true, the writer will write in any order. If false, the writer will preserve the current sorted state of the input.- Parameters:
ignoreSortOrder- whether to ignore sort order.
-
getSaveMetadata
public boolean getSaveMetadata()If set to true, the writer will attempt to save the metadata with the data if the implementation supports it. Otherwise metadata will not be saved.- Returns:
- whether metadata is saved
-
setSaveMetadata
public void setSaveMetadata(boolean saveMetadata) If set to true, the writer will attempt to save the metadata with the data if the implementation supports it. Otherwise metadata will not be saved.- Parameters:
saveMetadata- whether metadata is saved
-
computeFormat
Determines the data format for the target. The returned format is used during composition to construct aWriteSinkoperator. If an implementation supports schema discovery, it must be performed in this method.- Parameters:
ctx- the composition context for the current invocation ofcompose(CompositionContext)- Returns:
- the target format to use
-
compose
Composes a writer for the target, using configured options and a derived format.- Specified by:
composein classCompositeOperator- Parameters:
ctx- the context
-