- java.lang.Object
- 
- com.pervasive.datarush.operators.AbstractLogicalOperator
- 
- com.pervasive.datarush.operators.CompositeOperator
- 
- com.pervasive.datarush.operators.io.AbstractWriter
 
 
 
- 
- All Implemented Interfaces:
- LogicalOperator,- RecordSinkOperator,- SinkOperator<RecordPort>
 - Direct Known Subclasses:
- AbstractTextWriter,- BinaryWriter,- WriteAvro,- WriteORC,- WriteStagingDataset
 
 public abstract class AbstractWriter extends CompositeOperator implements RecordSinkOperator A generic writer of byte data representing a stream of records. The writer encompasses the basic attributes any such reader should have:- 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
 AbstractWriterwraps aWriteSinkoperator. 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 onlyDataFormatused differing between implementations.
- 
- 
Field SummaryFields Modifier and Type Field Description protected RecordPortinputThe input port of the read operatorprotected FormattingOptionsoptionsContainer for options related to formatting
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedAbstractWriter()Writes 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 SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcompose(CompositionContext ctx)Composes a writer for the target, using configured options and a derived format.protected abstract DataFormatcomputeFormat(CompositionContext ctx)Determines the data format for the target.FormattingOptionsgetFormatOptions()Gets the formatting options used by the writer.RecordPortgetInput()Gets the record port providing the records to write to the target sink.WriteModegetMode()Gets how existing files should be handled by the writer.booleangetSaveMetadata()If set to true, the writer will attempt to save the metadata with the data if the implementation supports it.ByteSinkgetTarget()Gets the data sink for the writer.intgetWriteBuffer()Gets the size of the I/O buffer, in bytes, to use for writes.booleangetWriteOnClient()Indicates whether the writer should write a file on the client.booleangetWriteSingleSink()Indicates whether the writer produces a single output file.booleanisIgnoreSortOrder()If 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.voidsetMode(WriteMode mode)Sets 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.voidsetTarget(Path path)Sets the data sink for the writer.voidsetTarget(ByteSink sink)Sets the data sink for the writer.voidsetTarget(String path)Sets 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.AbstractLogicalOperatordisableParallelism, getInputPorts, getOutputPorts, newInput, newInput, newOutput, newRecordInput, newRecordInput, newRecordOutput, notifyError
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface com.pervasive.datarush.operators.LogicalOperatordisableParallelism, getInputPorts, getOutputPorts
 
- 
 
- 
- 
- 
Field Detail- 
inputprotected final RecordPort input The input port of the read operator
 - 
optionsprotected final FormattingOptions options Container for options related to formatting
 
- 
 - 
Constructor Detail- 
AbstractWriterprotected AbstractWriter() Writes an empty target with default settings. The target must be set before execution or an error will be raised.- See Also:
- setTarget(ByteSink)
 
 - 
AbstractWriterprotected 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:
- setTarget(ByteSink)
 
 - 
AbstractWriterprotected AbstractWriter(String path, WriteMode mode) 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 write
- mode- how to handle existing files
 
 - 
AbstractWriterprotected AbstractWriter(Path path, WriteMode mode) 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 write
- mode- how to handle existing files
 
 - 
AbstractWriterprotected AbstractWriter(ByteSink target, WriteMode mode) 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 write
- mode- how to handle an existing sink
 
 
- 
 - 
Method Detail- 
getInputpublic RecordPort getInput() Gets the record port providing the records to write to the target sink.- Specified by:
- getInputin interface- RecordSinkOperator
- Specified by:
- getInputin interface- SinkOperator<RecordPort>
- Returns:
- the input port for records to write
 
 - 
getTargetpublic ByteSink getTarget() Gets the data sink for the writer.- Returns:
- the write sink
 
 - 
setTargetpublic void setTarget(String path) 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
 
 - 
setTargetpublic void setTarget(Path path) 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
 
 - 
setTargetpublic void setTarget(ByteSink sink) Sets the data sink for the writer.- Parameters:
- sink- the sink to which to write
 
 - 
getModepublic WriteMode getMode() Gets how existing files should be handled by the writer.- Returns:
- the configured behavior with respect to target files
 
 - 
setModepublic void setMode(WriteMode mode) Sets how the writer should handle an existing target.- Parameters:
- mode- the behavior to use for existing files
 
 - 
getFormatOptionspublic FormattingOptions getFormatOptions() Gets the formatting options used by the writer.- Returns:
- the format options
 
 - 
setFormatOptionspublic void setFormatOptions(FormattingOptions options) 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
 
 - 
getWriteBufferpublic int getWriteBuffer() Gets the size of the I/O buffer, in bytes, to use for writes.- Returns:
- the size of the write buffer
 
 - 
setWriteBufferpublic 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
 
 - 
getWriteSingleSinkpublic boolean getWriteSingleSink() Indicates whether the writer produces a single output file.- Returns:
- trueif the writer should write a single output,- falseotherwise.
 
 - 
setWriteSingleSinkpublic 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
 
 - 
getWriteOnClientpublic 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.
 
 - 
setWriteOnClientpublic 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.
 
 - 
isIgnoreSortOrderpublic 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.
 
 - 
setIgnoreSortOrderpublic 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.
 
 - 
getSaveMetadatapublic 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
 
 - 
setSaveMetadatapublic 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
 
 - 
computeFormatprotected abstract DataFormat computeFormat(CompositionContext ctx) 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 of- compose(CompositionContext)
- Returns:
- the target format to use
 
 - 
composeprotected final void compose(CompositionContext ctx) Composes a writer for the target, using configured options and a derived format.- Specified by:
- composein class- CompositeOperator
- Parameters:
- ctx- the context
 
 
- 
 
-