Class WriteDelimitedText
- All Implemented Interfaces:
LogicalOperator,RecordSinkOperator,SinkOperator<RecordPort>
Delimited text supports up to three distinct user-defined sequences within a record, used to identify field boundaries:
- a field separator, found between individual fields; by default, this is a comma (the ',' character).
- a field start delimiter, marking the beginning of a field value; by default this is a double quote (the '"' character).
- a field end delimiter, marking the end of a field value; ; by default this is a double quote (the '"' character).
The writer accepts a RecordTextSchema to provide formatting information
for fields, as well as header row information, if requested. It is not required
to provide a schema however, as one can be generated from the input
data type, using default formatting based on datatype. The writer also
supports a pluggable discovery mechanism for creating a schema based on the input type,
should fine-grained dynamic control be required.
Any schema, supplied or discovered, must be compatible with the input to the reader.
To be compatible, a schema must contain a field definition with an assignable type
for each field named in the input. Fields present in the schema, but not the input are
permitted with the missing field assuming a null value.
Delimited text data may or may not have a header row. The header row is delimited as usual but contains the names of the fields in the data portion of the record. The writer will emit a header row if it should be present and the write is not appending to an existing file.
-
Field Summary
Fields inherited from class com.pervasive.datarush.operators.io.textfile.AbstractTextWriter
encodingPropsFields inherited from class com.pervasive.datarush.operators.io.AbstractWriter
input, options -
Constructor Summary
ConstructorsConstructorDescriptionWrites delimited text to an empty target with default settings.WriteDelimitedText(boolean provideDoneSignal) Writes delimited text to an empty target with default settings.WriteDelimitedText(Path path, WriteMode mode) Writes delimited text to the specified path in the given mode, using default settings.WriteDelimitedText(ByteSink target, WriteMode mode) Writes delimited text to the specified target sink in the given mode.WriteDelimitedText(String path, WriteMode mode) Writes delimited text to the specified path in the given mode, using default settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected DataFormatDetermines the data format for the target.Gets the field delimiter settings used by the writer.Gets the end of field delimiter.Returns the delimiter used to distinguish field boundaries.Returns the start of field delimiter.booleanIndicates whether a header row should be written in the target.Gets the character sequence indicating a line comment.Gets the text value used to represent null values by default in generated schemas.Gets the value used as a record separator.Gets the record schema for delimited text source.Gets the schema discoverer to use on for the delimited text.voidsetDelimiters(FieldDelimiterSettings settings) Sets the field delimiter settings for the writer.voidsetFieldDelimiter(String delimiter) Sets the delimiter used to denote the boundaries of a data field.voidsetFieldEndDelimiter(String delimiter) Sets the delimiter used to denote the end of a data field.voidsetFieldSeparator(String separator) Sets the delimiter used to define the boundary between data fields.voidsetFieldStartDelimiter(String delimiter) Sets the delimiter used to denote the beginning of a data field.voidsetHeader(boolean header) Configures whether to write a header row in the target.voidsetLineComment(String lineComment) Sets the character sequence indicating a line comment.voidsetNullIndicator(String value) Sets the text value used to represent null values by default in generated schemas.voidsetRecordSeparator(String separator) Sets the value to use as a record separator.voidsetSchema(RecordTextSchema<?> schema) Sets the record schema for the delimited text source.voidsetSchemaDiscovery(TextRecordDiscoverer discoverer) Sets the schema discoverer to use for the delimited text.Methods inherited from class com.pervasive.datarush.operators.io.textfile.AbstractTextWriter
getCharset, getCharsetName, getEncodeBuffer, getEncoding, getErrorAction, getReplacement, setCharset, setCharsetName, setEncodeBuffer, setEncoding, setErrorAction, setReplacementMethods inherited from class com.pervasive.datarush.operators.io.AbstractWriter
compose, getFormatOptions, getInput, getMode, getSaveMetadata, getTarget, getWriteBuffer, getWriteOnClient, getWriteSingleSink, isIgnoreSortOrder, setFormatOptions, setIgnoreSortOrder, setMode, setSaveMetadata, setTarget, setTarget, setTarget, setWriteBuffer, setWriteOnClient, setWriteSingleSinkMethods 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
-
Constructor Details
-
WriteDelimitedText
public WriteDelimitedText()Writes delimited text to an empty target with default settings. The target must be set before execution or an error will be raised.A default schema will be generated based on the input type, unless otherwise configured via
setSchema(RecordTextSchema)orsetSchemaDiscovery(TextRecordDiscoverer).- See Also:
-
WriteDelimitedText
public WriteDelimitedText(boolean provideDoneSignal) Writes delimited text to an empty target with default settings. The target must be set before execution or an error will be raised.A default schema will be generated based on the input type, unless otherwise configured via
setSchema(RecordTextSchema)orsetSchemaDiscovery(TextRecordDiscoverer).- Parameters:
provideDoneSignal- indicates whether a done signal port should be created- See Also:
-
WriteDelimitedText
Writes delimited text to the specified path in the given mode, using default settings.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.
A default schema will be generated based on the input type, unless otherwise configured via
setSchema(RecordTextSchema)orsetSchemaDiscovery(TextRecordDiscoverer).- Parameters:
path- the path to which to writemode- how to handle existing files
-
WriteDelimitedText
Writes delimited text to the specified path in the given mode, using default settings.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.
A default schema will be generated based on the input type, unless otherwise configured via
setSchema(RecordTextSchema)orsetSchemaDiscovery(TextRecordDiscoverer).- Parameters:
path- the path to which to writemode- how to handle existing files
-
WriteDelimitedText
Writes delimited text 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.
A default schema will be generated based on the input type, unless otherwise configured via
setSchema(RecordTextSchema)orsetSchemaDiscovery(TextRecordDiscoverer).- Parameters:
target- the sink to which to writemode- how to handle an existing sink
-
-
Method Details
-
getSchema
Gets the record schema for delimited text source. If schema discovery is enabled, this will returnnull.- Returns:
- the record schema for the target
-
setSchema
Sets the record schema for the delimited text source. The output text will follow the formatting and ordering of fields in the schema.Setting a schema overrides any previously configured schema discovery.
- Parameters:
schema- the desired record schema for the target- See Also:
-
getSchemaDiscovery
Gets the schema discoverer to use on for the delimited text. If schema discovery is disabled, this will returnnull.- Returns:
- the configured schema discoverer
-
setSchemaDiscovery
Sets the schema discoverer to use for the delimited text. Just prior to graph execution the type of the input records will be used to determine the schema to use for formatting and ordering fields in the output text.By default, the schema will be discovered automatically. This schema preserves field order from the input and uses default formatting appropriate for the field's datatype. If a header row is written, it will use the field names from the input.
Setting schema discovery overrides any previously configured schema.
- Parameters:
discoverer- the schema discoverer to use.- See Also:
-
getNullIndicator
Gets the text value used to represent null values by default in generated schemas.- Returns:
- the string indicating a null value
-
setNullIndicator
Sets the text value used to represent null values by default in generated schemas. By default, this is the empty string. If schema is provided, this setting is ignored.- Parameters:
value- the string indicating a null value
-
getHeader
public boolean getHeader()Indicates whether a header row should be written in the target.- Returns:
- whether a header row should be written
-
setHeader
public void setHeader(boolean header) Configures whether to write a header row in the target. A header will not be written if appending to a target file.- Parameters:
header- indicates whether to write a header row
-
getLineComment
Gets the character sequence indicating a line comment.- Returns:
- the sequence marking a line comment
-
setLineComment
Sets the character sequence indicating a line comment. This sequence is used immediately following a record to indicate everything up to the next record separator is to be ignored.- Parameters:
lineComment- the character sequence marking the start of a line comment
-
getDelimiters
Gets the field delimiter settings used by the writer.- Returns:
- the field delimiter settings
-
setDelimiters
Sets the field delimiter settings for the writer. This sets all field delimiter settings at once.- Parameters:
settings- the field delimiter settings to use
-
getRecordSeparator
Gets the value used as a record separator.- Returns:
- the text value of the record separator
-
setRecordSeparator
Sets the value to use as a record separator. The separator is used to delimit records in the output text.By default the record separator is set to the default record separator for the installed operating system of the execution environment.
- Parameters:
separator- the value to use as a record separator- Throws:
com.pervasive.datarush.graphs.physical.InvalidPropertyValueException- if the separator isnullor the empty string
-
getFieldSeparator
Returns the delimiter used to distinguish field boundaries.- Returns:
- the string used to separate fields
-
setFieldSeparator
Sets the delimiter used to define the boundary between data fields.- Parameters:
separator- string used to separate fields- Throws:
com.pervasive.datarush.graphs.physical.InvalidPropertyValueException- if the delimiter isnullor the empty string
-
setFieldDelimiter
Sets the delimiter used to denote the boundaries of a data field.This method is generally equivalent to calling
setFieldStartDelimiter()andsetFieldEndDelimiter()with the same parameter values. However, those methods do not allow the empty string as a parameter.- Parameters:
delimiter- string used to optionally mark the start and end of a field value. An empty string indicates field values are not delimited.- Throws:
com.pervasive.datarush.graphs.physical.InvalidPropertyValueException- if the delimiter isnull
-
getFieldStartDelimiter
Returns the start of field delimiter.- Returns:
- the string used to mark the beginning of a field value
-
getFieldEndDelimiter
Gets the end of field delimiter.- Returns:
- the string used to mark the end of a field value
-
setFieldStartDelimiter
Sets the delimiter used to denote the beginning of a data field. It not permitted to set the start delimiter to the empty string; usesetFieldDelimiter(String)instead to indicate no delimiters.- Parameters:
delimiter- string used to mark the start of a field value- Throws:
com.pervasive.datarush.graphs.physical.InvalidPropertyValueException- if the delimiter isnullor the empty string
-
setFieldEndDelimiter
Sets the delimiter used to denote the end of a data field. It not permitted to set the end delimiter to the empty string; usesetFieldDelimiter(String)instead to indicate no delimiters.- Parameters:
delimiter- string used to mark the start of a field value- Throws:
com.pervasive.datarush.graphs.physical.InvalidPropertyValueException- if the delimiter isnullor the empty string
-
computeFormat
Description copied from class:AbstractWriterDetermines 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.- Specified by:
computeFormatin classAbstractWriter- Parameters:
ctx- the composition context for the current invocation ofAbstractWriter.compose(CompositionContext)- Returns:
- the target format to use
-