Class DStream<T>
Object
org.apache.spark.streaming.dstream.DStream<T>
- All Implemented Interfaces:
- Serializable,- org.apache.spark.internal.Logging
- Direct Known Subclasses:
- InputDStream,- MapWithStateDStream
public abstract class DStream<T>
extends Object
implements Serializable, org.apache.spark.internal.Logging
A Discretized Stream (DStream), the basic abstraction in Spark Streaming, is a continuous
 sequence of RDDs (of the same type) representing a continuous stream of data (see
 org.apache.spark.rdd.RDD in the Spark core documentation for more details on RDDs).
 DStreams can either be created from live data (such as, data from TCP sockets, Kafka,
 etc.) using a 
StreamingContext or it can be generated by
 transforming existing DStreams using operations such as map,
 window and reduceByKeyAndWindow. While a Spark Streaming program is running, each DStream
 periodically generates a RDD, either from live data or by transforming the RDD generated by a
 parent DStream.
 
 This class contains the basic operations available on all DStreams, such as map, filter and
 window. In addition, PairDStreamFunctions contains
 operations available only on DStreams of key-value pairs, such as groupByKeyAndWindow and
 join. These operations are automatically available on any DStream of pairs
 (e.g., DStream[(Int, Int)] through implicit conversions.
 
A DStream internally is characterized by a few basic properties: - A list of other DStreams that the DStream depends on - A time interval at which the DStream generates an RDD - A function that is used to generate an RDD after each time interval
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.apache.spark.internal.Loggingorg.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptioncache()Persist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)checkpoint(Duration interval) Enable periodic checkpointing of RDDs of this DStreamMethod that generates an RDD for the given timecontext()Return the StreamingContext associated with this DStreamcount()Return a new DStream in which each RDD has a single element generated by counting each RDD of this DStream.countByValue(int numPartitions, scala.math.Ordering<T> ord) Return a new DStream in which each RDD contains the counts of each distinct value in each RDD of this DStream.countByValueAndWindow(Duration windowDuration, Duration slideDuration, int numPartitions, scala.math.Ordering<T> ord) Return a new DStream in which each RDD contains the count of distinct elements in RDDs in a sliding window over this DStream.countByWindow(Duration windowDuration, Duration slideDuration) Return a new DStream in which each RDD has a single element generated by counting the number of elements in a sliding window over this DStream.abstract scala.collection.immutable.List<DStream<?>>List of parent DStreams on which this DStream depends onReturn a new DStream containing only the elements that satisfy a predicate.<U> DStream<U>flatMap(scala.Function1<T, scala.collection.IterableOnce<U>> flatMapFunc, scala.reflect.ClassTag<U> evidence$3) Return a new DStream by applying a function to all elements of this DStream, and then flattening the resultsvoidforeachRDD(scala.Function1<RDD<T>, scala.runtime.BoxedUnit> foreachFunc) Apply a function to each RDD in this DStream.voidforeachRDD(scala.Function2<RDD<T>, Time, scala.runtime.BoxedUnit> foreachFunc) Apply a function to each RDD in this DStream.glom()Return a new DStream in which each RDD is generated by applying glom() to each RDD of this DStream.<U> DStream<U>Return a new DStream by applying a function to all elements of this DStream.<U> DStream<U>mapPartitions(scala.Function1<scala.collection.Iterator<T>, scala.collection.Iterator<U>> mapPartFunc, boolean preservePartitioning, scala.reflect.ClassTag<U> evidence$4) Return a new DStream in which each RDD is generated by applying mapPartitions() to each RDDs of this DStream.persist()Persist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)persist(StorageLevel level) Persist the RDDs of this DStream with the given storage levelvoidprint()Print the first ten elements of each RDD generated in this DStream.voidprint(int num) Print the first num elements of each RDD generated in this DStream.Return a new DStream in which each RDD has a single element generated by reducing each RDD of this DStream.Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over this DStream.reduceByWindow(scala.Function2<T, T, T> reduceFunc, scala.Function2<T, T, T> invReduceFunc, Duration windowDuration, Duration slideDuration) Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over this DStream.repartition(int numPartitions) Return a new DStream with an increased or decreased level of parallelism.voidsaveAsObjectFiles(String prefix, String suffix) Save each RDD in this DStream as a Sequence file of serialized objects.voidsaveAsTextFiles(String prefix, String suffix) Save each RDD in this DStream as at text file, using string representation of elements.slice(org.apache.spark.streaming.Interval interval) Return all the RDDs defined by the Interval object (both end times included)Return all the RDDs between 'fromTime' to 'toTime' (both included)abstract DurationTime interval after which the DStream generates an RDDstatic <K,V> PairDStreamFunctions<K, V> toPairDStreamFunctions(DStream<scala.Tuple2<K, V>> stream, scala.reflect.ClassTag<K> kt, scala.reflect.ClassTag<V> vt, scala.math.Ordering<K> ord) <U> DStream<U>Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream.<U> DStream<U>Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream.<U,V> DStream<V> transformWith(DStream<U> other, scala.Function2<RDD<T>, RDD<U>, RDD<V>> transformFunc, scala.reflect.ClassTag<U> evidence$7, scala.reflect.ClassTag<V> evidence$8) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream and 'other' DStream.<U,V> DStream<V> transformWith(DStream<U> other, scala.Function3<RDD<T>, RDD<U>, Time, RDD<V>> transformFunc, scala.reflect.ClassTag<U> evidence$9, scala.reflect.ClassTag<V> evidence$10) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream and 'other' DStream.Return a new DStream by unifying data of another DStream with this DStream.Return a new DStream in which each RDD contains all the elements in seen in a sliding window of time over this DStream.Return a new DStream in which each RDD contains all the elements in seen in a sliding window of time over this DStream.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.internal.LogginginitializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, MDC, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContext
- 
Constructor Details- 
DStream
 
- 
- 
Method Details- 
toPairDStreamFunctionspublic static <K,V> PairDStreamFunctions<K,V> toPairDStreamFunctions(DStream<scala.Tuple2<K, V>> stream, scala.reflect.ClassTag<K> kt, scala.reflect.ClassTag<V> vt, scala.math.Ordering<K> ord) 
- 
slideDurationTime interval after which the DStream generates an RDD
- 
dependenciesList of parent DStreams on which this DStream depends on
- 
computeMethod that generates an RDD for the given time
- 
contextReturn the StreamingContext associated with this DStream
- 
persistPersist the RDDs of this DStream with the given storage level
- 
persistPersist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)
- 
cachePersist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)
- 
checkpointEnable periodic checkpointing of RDDs of this DStream- Parameters:
- interval- Time interval after which generated RDD will be checkpointed
- Returns:
- (undocumented)
 
- 
mapReturn a new DStream by applying a function to all elements of this DStream.
- 
flatMappublic <U> DStream<U> flatMap(scala.Function1<T, scala.collection.IterableOnce<U>> flatMapFunc, scala.reflect.ClassTag<U> evidence$3) Return a new DStream by applying a function to all elements of this DStream, and then flattening the results- Parameters:
- flatMapFunc- (undocumented)
- evidence$3- (undocumented)
- Returns:
- (undocumented)
 
- 
filterReturn a new DStream containing only the elements that satisfy a predicate.
- 
glomReturn a new DStream in which each RDD is generated by applying glom() to each RDD of this DStream. Applying glom() to an RDD coalesces all elements within each partition into an array.- Returns:
- (undocumented)
 
- 
repartitionReturn a new DStream with an increased or decreased level of parallelism. Each RDD in the returned DStream has exactly numPartitions partitions.- Parameters:
- numPartitions- (undocumented)
- Returns:
- (undocumented)
 
- 
mapPartitionspublic <U> DStream<U> mapPartitions(scala.Function1<scala.collection.Iterator<T>, scala.collection.Iterator<U>> mapPartFunc, boolean preservePartitioning, scala.reflect.ClassTag<U> evidence$4) Return a new DStream in which each RDD is generated by applying mapPartitions() to each RDDs of this DStream. Applying mapPartitions() to an RDD applies a function to each partition of the RDD.- Parameters:
- mapPartFunc- (undocumented)
- preservePartitioning- (undocumented)
- evidence$4- (undocumented)
- Returns:
- (undocumented)
 
- 
reduceReturn a new DStream in which each RDD has a single element generated by reducing each RDD of this DStream.- Parameters:
- reduceFunc- (undocumented)
- Returns:
- (undocumented)
 
- 
countReturn a new DStream in which each RDD has a single element generated by counting each RDD of this DStream.- Returns:
- (undocumented)
 
- 
countByValueReturn a new DStream in which each RDD contains the counts of each distinct value in each RDD of this DStream. Hash partitioning is used to generate the RDDs withnumPartitionspartitions (Spark's default number of partitions ifnumPartitionsnot specified).- Parameters:
- numPartitions- (undocumented)
- ord- (undocumented)
- Returns:
- (undocumented)
 
- 
foreachRDDApply a function to each RDD in this DStream. This is an output operator, so 'this' DStream will be registered as an output stream and therefore materialized.- Parameters:
- foreachFunc- (undocumented)
 
- 
foreachRDDApply a function to each RDD in this DStream. This is an output operator, so 'this' DStream will be registered as an output stream and therefore materialized.- Parameters:
- foreachFunc- (undocumented)
 
- 
transformpublic <U> DStream<U> transform(scala.Function1<RDD<T>, RDD<U>> transformFunc, scala.reflect.ClassTag<U> evidence$5) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream.- Parameters:
- transformFunc- (undocumented)
- evidence$5- (undocumented)
- Returns:
- (undocumented)
 
- 
transformpublic <U> DStream<U> transform(scala.Function2<RDD<T>, Time, RDD<U>> transformFunc, scala.reflect.ClassTag<U> evidence$6) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream.- Parameters:
- transformFunc- (undocumented)
- evidence$6- (undocumented)
- Returns:
- (undocumented)
 
- 
transformWithpublic <U,V> DStream<V> transformWith(DStream<U> other, scala.Function2<RDD<T>, RDD<U>, RDD<V>> transformFunc, scala.reflect.ClassTag<U> evidence$7, scala.reflect.ClassTag<V> evidence$8) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream and 'other' DStream.- Parameters:
- other- (undocumented)
- transformFunc- (undocumented)
- evidence$7- (undocumented)
- evidence$8- (undocumented)
- Returns:
- (undocumented)
 
- 
transformWithpublic <U,V> DStream<V> transformWith(DStream<U> other, scala.Function3<RDD<T>, RDD<U>, Time, RDD<V>> transformFunc, scala.reflect.ClassTag<U> evidence$9, scala.reflect.ClassTag<V> evidence$10) Return a new DStream in which each RDD is generated by applying a function on each RDD of 'this' DStream and 'other' DStream.- Parameters:
- other- (undocumented)
- transformFunc- (undocumented)
- evidence$9- (undocumented)
- evidence$10- (undocumented)
- Returns:
- (undocumented)
 
- 
printpublic void print()Print the first ten elements of each RDD generated in this DStream. This is an output operator, so this DStream will be registered as an output stream and there materialized.
- 
printpublic void print(int num) Print the first num elements of each RDD generated in this DStream. This is an output operator, so this DStream will be registered as an output stream and there materialized.- Parameters:
- num- (undocumented)
 
- 
windowReturn a new DStream in which each RDD contains all the elements in seen in a sliding window of time over this DStream. The new DStream generates RDDs with the same interval as this DStream.- Parameters:
- windowDuration- width of the window; must be a multiple of this DStream's interval.
- Returns:
- (undocumented)
 
- 
windowReturn a new DStream in which each RDD contains all the elements in seen in a sliding window of time over this DStream.- Parameters:
- windowDuration- width of the window; must be a multiple of this DStream's batching interval
- slideDuration- sliding interval of the window (i.e., the interval after which the new DStream will generate RDDs); must be a multiple of this DStream's batching interval
- Returns:
- (undocumented)
 
- 
reduceByWindowpublic DStream<T> reduceByWindow(scala.Function2<T, T, T> reduceFunc, Duration windowDuration, Duration slideDuration) Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over this DStream.- Parameters:
- reduceFunc- associative and commutative reduce function
- windowDuration- width of the window; must be a multiple of this DStream's batching interval
- slideDuration- sliding interval of the window (i.e., the interval after which the new DStream will generate RDDs); must be a multiple of this DStream's batching interval
- Returns:
- (undocumented)
 
- 
reduceByWindowpublic DStream<T> reduceByWindow(scala.Function2<T, T, T> reduceFunc, scala.Function2<T, T, T> invReduceFunc, Duration windowDuration, Duration slideDuration) Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over this DStream. However, the reduction is done incrementally using the old window's reduced value : 1. reduce the new values that entered the window (e.g., adding new counts) 2. "inverse reduce" the old values that left the window (e.g., subtracting old counts) This is more efficient than reduceByWindow without "inverse reduce" function. However, it is applicable to only "invertible reduce functions".- Parameters:
- reduceFunc- associative and commutative reduce function
- invReduceFunc- inverse reduce function; such that for all y, invertible x:- invReduceFunc(reduceFunc(x, y), x) = y
- windowDuration- width of the window; must be a multiple of this DStream's batching interval
- slideDuration- sliding interval of the window (i.e., the interval after which the new DStream will generate RDDs); must be a multiple of this DStream's batching interval
- Returns:
- (undocumented)
 
- 
countByWindowReturn a new DStream in which each RDD has a single element generated by counting the number of elements in a sliding window over this DStream. Hash partitioning is used to generate the RDDs with Spark's default number of partitions.- Parameters:
- windowDuration- width of the window; must be a multiple of this DStream's batching interval
- slideDuration- sliding interval of the window (i.e., the interval after which the new DStream will generate RDDs); must be a multiple of this DStream's batching interval
- Returns:
- (undocumented)
 
- 
countByValueAndWindowpublic DStream<scala.Tuple2<T,Object>> countByValueAndWindow(Duration windowDuration, Duration slideDuration, int numPartitions, scala.math.Ordering<T> ord) Return a new DStream in which each RDD contains the count of distinct elements in RDDs in a sliding window over this DStream. Hash partitioning is used to generate the RDDs withnumPartitionspartitions (Spark's default number of partitions ifnumPartitionsnot specified).- Parameters:
- windowDuration- width of the window; must be a multiple of this DStream's batching interval
- slideDuration- sliding interval of the window (i.e., the interval after which the new DStream will generate RDDs); must be a multiple of this DStream's batching interval
- numPartitions- number of partitions of each RDD in the new DStream.
- ord- (undocumented)
- Returns:
- (undocumented)
 
- 
unionReturn a new DStream by unifying data of another DStream with this DStream.- Parameters:
- that- Another DStream having the same slideDuration as this DStream.
- Returns:
- (undocumented)
 
- 
sliceReturn all the RDDs defined by the Interval object (both end times included)- Parameters:
- interval- (undocumented)
- Returns:
- (undocumented)
 
- 
sliceReturn all the RDDs between 'fromTime' to 'toTime' (both included)- Parameters:
- fromTime- (undocumented)
- toTime- (undocumented)
- Returns:
- (undocumented)
 
- 
saveAsObjectFilesSave each RDD in this DStream as a Sequence file of serialized objects. The file name at each batch interval is generated based onprefixandsuffix: "prefix-TIME_IN_MS.suffix".- Parameters:
- prefix- (undocumented)
- suffix- (undocumented)
 
- 
saveAsTextFilesSave each RDD in this DStream as at text file, using string representation of elements. The file name at each batch interval is generated based onprefixandsuffix: "prefix-TIME_IN_MS.suffix".- Parameters:
- prefix- (undocumented)
- suffix- (undocumented)
 
 
-