Class Source<T>
- java.lang.Object
-
- org.apache.beam.sdk.io.Source<T>
-
- Type Parameters:
T
- Type of elements read by the source.
- All Implemented Interfaces:
java.io.Serializable
,HasDisplayData
- Direct Known Subclasses:
BoundedSource
,UnboundedSource
@Experimental(SOURCE_SINK) public abstract class Source<T> extends java.lang.Object implements java.io.Serializable, HasDisplayData
Base class for defining input formats and creating aSource
for reading the input.This class is not intended to be subclassed directly. Instead, to define a bounded source (a source which produces a finite amount of input), subclass
BoundedSource
; to define an unbounded source, subclassUnboundedSource
.A
Source
passed to aRead
transform must beSerializable
. This allows theSource
instance created in this "main program" to be sent (in serialized form) to remote worker machines and reconstituted for each batch of elements of the inputPCollection
being processed or for each source splitting operation. ASource
can have instance variable state, and non-transient instance variable state will be serialized in the main program and then deserialized on remote worker machines.Source
classes MUST be effectively immutable. The only acceptable use of mutable fields is to cache the results of expensive operations, and such fields MUST be markedtransient
.Source
objects should overrideObject.toString()
, as it will be used in important error and debugging messages.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Source.Reader<T>
The interface that readers of custom input sources must implement.
-
Constructor Summary
Constructors Constructor Description Source()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Coder<T>
getDefaultOutputCoder()
Deprecated.OverridegetOutputCoder()
instead.Coder<T>
getOutputCoder()
Returns theCoder
to use for the data read from this source.void
populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.void
validate()
Checks that this source is valid, before it can be used in a pipeline.
-
-
-
Method Detail
-
validate
public void validate()
Checks that this source is valid, before it can be used in a pipeline.It is recommended to use
Preconditions
for implementing this method.
-
getDefaultOutputCoder
@Deprecated public Coder<T> getDefaultOutputCoder()
Deprecated.OverridegetOutputCoder()
instead.
-
getOutputCoder
public Coder<T> getOutputCoder()
Returns theCoder
to use for the data read from this source.
-
populateDisplayData
public void populateDisplayData(DisplayData.Builder builder)
Register display data for the given transform or component.populateDisplayData(DisplayData.Builder)
is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData)
. Implementations may callsuper.populateDisplayData(builder)
in order to register display data in the current namespace, but should otherwise usesubcomponent.populateDisplayData(builder)
to use the namespace of the subcomponent.By default, does not register any display data. Implementors may override this method to provide their own display data.
- Specified by:
populateDisplayData
in interfaceHasDisplayData
- Parameters:
builder
- The builder to populate with display data.- See Also:
HasDisplayData
-
-