public class TextLine extends Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]> implements FileFormat
Scheme
for plain text files. Files are broken into
lines. Either line-feed or carriage-return are used to signal end of line.
By default, this scheme returns a Tuple
with two fields, "offset" and "line".
Many of the constructors take both "sourceFields" and "sinkFields". sourceFields denote the field names
to be used instead of the names "offset" and "line". sinkFields is a selector and is by default Fields.ALL
.
Any available field names can be given if only a subset of the incoming fields should be used.
If a Fields
instance is passed on the constructor as sourceFields having only one field, the return tuples
will simply be the "line" value using the given field name.
Note that TextLine will concatenate all the Tuple values for the selected fields with a TAB delimiter before writing out the line.
Note sink compression is TextLine.Compress.DISABLE
by default. If null
is passed to the constructor
for the compression value, it will remain disabled.
If any of the input files end with ".zip", an error will be thrown. *
By default, all text is encoded/decoded as UTF-8. This can be changed via the charsetName
constructor
argument.
Modifier and Type | Class and Description |
---|---|
static class |
TextLine.Compress |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CHARSET |
static Fields |
DEFAULT_SOURCE_FIELDS
Field DEFAULT_SOURCE_FIELDS
|
Constructor and Description |
---|
TextLine()
Creates a new TextLine instance that sources "offset" and "line" fields, and sinks all incoming fields, where
"offset" is the byte offset in the input file.
|
TextLine(Fields sourceFields)
Creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields)
Creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
int numSinkParts)
Creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
java.lang.String charsetName)
Creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
TextLine.Compress sinkCompression)
Constructor TextLine creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
TextLine.Compress sinkCompression,
int numSinkParts)
Constructor TextLine creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
TextLine.Compress sinkCompression,
int numSinkParts,
java.lang.String charsetName)
Constructor TextLine creates a new TextLine instance.
|
TextLine(Fields sourceFields,
Fields sinkFields,
TextLine.Compress sinkCompression,
java.lang.String charsetName)
Constructor TextLine creates a new TextLine instance.
|
TextLine(Fields sourceFields,
int numSinkParts)
Creates a new TextLine instance.
|
TextLine(Fields sourceFields,
java.lang.String charsetName)
Creates a new TextLine instance.
|
TextLine(int numSinkParts)
Creates a new TextLine instance that sources "offset" and "line" fields, and sinks all incoming fields, where
"offset" is the byte offset in the input file.
|
TextLine(TextLine.Compress sinkCompression)
Creates a new TextLine instance that sources "offset" and "line" fields, and sinks all incoming fields, where
"offset" is the byte offset in the input file.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getCharsetName() |
java.lang.String |
getExtension() |
TextLine.Compress |
getSinkCompression()
Method getSinkCompression returns the sinkCompression of this TextLine object.
|
protected java.lang.String |
makeEncodedString(java.lang.Object[] context) |
void |
presentSinkFields(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
Tap tap,
Fields fields)
Method presentSinkFields is called after the planner is invoked and all fields are resolved.
|
void |
presentSourceFields(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
Tap tap,
Fields fields)
Method presentSourceFields is called after the planner is invoked and all fields are resolved.
|
protected void |
setCharsetName(java.lang.String charsetName) |
void |
setSinkCompression(TextLine.Compress sinkCompression)
Method setSinkCompression sets the sinkCompression of this TextLine object.
|
void |
sink(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
SinkCall<java.lang.Object[],org.apache.hadoop.mapred.OutputCollector> sinkCall)
Method sink writes out the given
Tuple found on SinkCall.getOutgoingEntry() to
the SinkCall.getOutput() . |
void |
sinkConfInit(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
Tap<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector> tap,
org.apache.hadoop.conf.Configuration conf)
Method sinkInit initializes this instance as a sink.
|
void |
sinkPrepare(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
SinkCall<java.lang.Object[],org.apache.hadoop.mapred.OutputCollector> sinkCall)
Method sinkPrepare is used to initialize resources needed during each call of
Scheme.sink(cascading.flow.FlowProcess, SinkCall) . |
boolean |
source(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall)
Method source will read a new "record" or value from
SourceCall.getInput() and populate
the available Tuple via SourceCall.getIncomingEntry() and return true
on success or false if no more values available. |
void |
sourceCleanup(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall)
Method sourceCleanup is used to destroy resources created by
Scheme.sourcePrepare(cascading.flow.FlowProcess, SourceCall) . |
void |
sourceConfInit(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
Tap<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector> tap,
org.apache.hadoop.conf.Configuration conf)
Method sourceInit initializes this instance as a source.
|
protected void |
sourceHandleInput(SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall) |
void |
sourcePrepare(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess,
SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall)
Method sourcePrepare is used to initialize resources needed during each call of
Scheme.source(cascading.flow.FlowProcess, SourceCall) . |
protected void |
verify(Fields sourceFields) |
equals, getNumSinkParts, getSinkFields, getSourceFields, getTrace, hashCode, isSink, isSource, isSymmetrical, presentSinkFieldsInternal, presentSourceFieldsInternal, retrieveSinkFields, retrieveSourceFields, setNumSinkParts, setSinkFields, setSourceFields, sinkCleanup, sinkWrap, sourceRePrepare, sourceWrap, toString
public static final java.lang.String DEFAULT_CHARSET
public static final Fields DEFAULT_SOURCE_FIELDS
public TextLine()
@ConstructorProperties(value="numSinkParts") public TextLine(int numSinkParts)
numSinkParts
- of type int@ConstructorProperties(value="sinkCompression") public TextLine(TextLine.Compress sinkCompression)
sinkCompression
- of type Compress@ConstructorProperties(value={"sourceFields","sinkFields"}) public TextLine(Fields sourceFields, Fields sinkFields)
sourceFields
- the source fields for this schemesinkFields
- the sink fields for this scheme@ConstructorProperties(value={"sourceFields","sinkFields","charsetName"}) public TextLine(Fields sourceFields, Fields sinkFields, java.lang.String charsetName)
sourceFields
- the source fields for this schemesinkFields
- the sink fields for this schemecharsetName
- of type String@ConstructorProperties(value={"sourceFields","sinkFields","numSinkParts"}) public TextLine(Fields sourceFields, Fields sinkFields, int numSinkParts)
sourceFields
- the source fields for this schemesinkFields
- the sink fields for this schemenumSinkParts
- of type int@ConstructorProperties(value={"sourceFields","sinkFields","sinkCompression"}) public TextLine(Fields sourceFields, Fields sinkFields, TextLine.Compress sinkCompression)
sourceFields
- of type FieldssinkFields
- of type FieldssinkCompression
- of type Compress@ConstructorProperties(value={"sourceFields","sinkFields","sinkCompression","charsetName"}) public TextLine(Fields sourceFields, Fields sinkFields, TextLine.Compress sinkCompression, java.lang.String charsetName)
sourceFields
- of type FieldssinkFields
- of type FieldssinkCompression
- of type CompresscharsetName
- of type String@ConstructorProperties(value={"sourceFields","sinkFields","sinkCompression","numSinkParts"}) public TextLine(Fields sourceFields, Fields sinkFields, TextLine.Compress sinkCompression, int numSinkParts)
sourceFields
- of type FieldssinkFields
- of type FieldssinkCompression
- of type CompressnumSinkParts
- of type int@ConstructorProperties(value={"sourceFields","sinkFields","sinkCompression","numSinkParts","charsetName"}) public TextLine(Fields sourceFields, Fields sinkFields, TextLine.Compress sinkCompression, int numSinkParts, java.lang.String charsetName)
sourceFields
- of type FieldssinkFields
- of type FieldssinkCompression
- of type CompressnumSinkParts
- of type intcharsetName
- of type String@ConstructorProperties(value="sourceFields") public TextLine(Fields sourceFields)
sourceFields
- the source fields for this scheme@ConstructorProperties(value={"sourceFields","charsetName"}) public TextLine(Fields sourceFields, java.lang.String charsetName)
sourceFields
- the source fields for this schemecharsetName
- of type String@ConstructorProperties(value={"sourceFields","numSinkParts"}) public TextLine(Fields sourceFields, int numSinkParts)
sourceFields
- the source fields for this schemenumSinkParts
- of type intprotected void setCharsetName(java.lang.String charsetName)
public java.lang.String getCharsetName()
public TextLine.Compress getSinkCompression()
public void setSinkCompression(TextLine.Compress sinkCompression)
sinkCompression
- the sinkCompression of this TextLine object.public void sourceConfInit(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, Tap<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector> tap, org.apache.hadoop.conf.Configuration conf)
Scheme
This method is executed client side as a means to provide necessary configuration parameters used by the underlying platform.
It is not intended to initialize resources that would be necessary during the execution of this class, like a "formatter" or "parser".
See Scheme.sourcePrepare(cascading.flow.FlowProcess, SourceCall)
if resources much be initialized
before use. And Scheme.sourceCleanup(cascading.flow.FlowProcess, SourceCall)
if resources must be
destroyed after use.
sourceConfInit
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesstap
- of type Tapconf
- of type Configpublic void presentSourceFields(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, Tap tap, Fields fields)
Scheme
This method is called after Scheme.retrieveSourceFields(cascading.flow.FlowProcess, cascading.tap.Tap)
.
presentSourceFields
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesstap
- of type Tapfields
- of type Fieldspublic void presentSinkFields(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, Tap tap, Fields fields)
Scheme
This method is called after Scheme.retrieveSinkFields(cascading.flow.FlowProcess, cascading.tap.Tap)
.
presentSinkFields
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesstap
- of type Tapfields
- of type Fieldspublic void sinkConfInit(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, Tap<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector> tap, org.apache.hadoop.conf.Configuration conf)
Scheme
This method is executed client side as a means to provide necessary configuration parameters used by the underlying platform.
It is not intended to initialize resources that would be necessary during the execution of this class, like a "formatter" or "parser".
See Scheme.sinkPrepare(cascading.flow.FlowProcess, SinkCall)
if resources much be initialized
before use. And Scheme.sinkCleanup(cascading.flow.FlowProcess, SinkCall)
if resources must be
destroyed after use.
sinkConfInit
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesstap
- of type Tapconf
- of type Configpublic void sourcePrepare(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall)
Scheme
Scheme.source(cascading.flow.FlowProcess, SourceCall)
.
This method is guaranteed to be called once before the first invocation of Scheme.source(FlowProcess, SourceCall)
.
Be sure to place any initialized objects in the SourceContext
so each instance
will remain thread-safe.
sourcePrepare
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesssourceCall
- of type SourceCallpublic boolean source(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall) throws java.io.IOException
Scheme
SourceCall.getInput()
and populate
the available Tuple
via SourceCall.getIncomingEntry()
and return true
on success or false
if no more values available.
It's ok to set a new Tuple instance on the incomingEntry
TupleEntry
, or
to simply re-use the existing instance.
Note this is only time it is safe to modify a Tuple instance handed over via a method call.
This method may optionally throw a TapException
if it cannot process a particular
instance of data. If the payload Tuple is set on the TapException, that Tuple will be written to
any applicable failure trap Tap.
source
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesssourceCall
- of SourceCalltrue
when a Tuple was successfully readjava.io.IOException
protected void sourceHandleInput(SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall) throws java.io.IOException
java.io.IOException
protected java.lang.String makeEncodedString(java.lang.Object[] context)
public void sourceCleanup(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, SourceCall<java.lang.Object[],org.apache.hadoop.mapred.RecordReader> sourceCall)
Scheme
Scheme.sourcePrepare(cascading.flow.FlowProcess, SourceCall)
.sourceCleanup
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of ProcesssourceCall
- of type SourceCallpublic void sinkPrepare(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, SinkCall<java.lang.Object[],org.apache.hadoop.mapred.OutputCollector> sinkCall) throws java.io.IOException
Scheme
Scheme.sink(cascading.flow.FlowProcess, SinkCall)
.
This method is guaranteed to be called once before the first invocation of Scheme.sink(FlowProcess, SinkCall)
.
Be sure to place any initialized objects in the SinkContext
so each instance
will remain threadsafe.
sinkPrepare
in class Scheme<org.apache.hadoop.conf.Configuration,org.apache.hadoop.mapred.RecordReader,org.apache.hadoop.mapred.OutputCollector,java.lang.Object[],java.lang.Object[]>
flowProcess
- of type FlowProcesssinkCall
- of type SinkCalljava.io.IOException
public void sink(FlowProcess<? extends org.apache.hadoop.conf.Configuration> flowProcess, SinkCall<java.lang.Object[],org.apache.hadoop.mapred.OutputCollector> sinkCall) throws java.io.IOException
Scheme
Tuple
found on SinkCall.getOutgoingEntry()
to
the SinkCall.getOutput()
.
This method may optionally throw a TapException
if it cannot process a particular
instance of data. If the payload Tuple is set on the TapException, that Tuple will be written to
any applicable failure trap Tap. If not set, the incoming Tuple will be written instead.
public java.lang.String getExtension()
getExtension
in interface FileFormat
Copyright © 2007-2017 Cascading Maintainers. All Rights Reserved.