spark.streaming

DStream

abstract class DStream[T] extends Serializable with 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 spark.RDD for more details on RDDs). DStreams can either be created from live data (such as, data from HDFS, Kafka or Flume) or it can be generated by transformation 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 the right type (e.g., DStream[(Int, Int)] through implicit conversions when spark.streaming.StreamingContext._ is imported.

DStreams internally is characterized by a few basic properties:

Linear Supertypes
Logging, Serializable, Serializable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. DStream
  2. Logging
  3. Serializable
  4. Serializable
  5. AnyRef
  6. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new DStream(ssc: StreamingContext)(implicit arg0: ClassManifest[T])

Abstract Value Members

  1. abstract def compute(validTime: Time): Option[RDD[T]]

    Method that generates a RDD for the given time

  2. abstract def dependencies: List[spark.streaming.DStream[_]]

    List of parent DStreams on which this DStream depends on

  3. abstract def slideDuration: Duration

    Time interval after which the DStream generates a RDD

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def addMetadata(metadata: Any): Unit

    Attributes
    protected[streaming]
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def cache(): DStream[T]

    Persist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)

  9. def checkpoint(interval: Duration): DStream[T]

    Enable periodic checkpointing of RDDs of this DStream

    Enable periodic checkpointing of RDDs of this DStream

    interval

    Time interval after which generated RDD will be checkpointed

  10. val checkpointData: DStreamCheckpointData[T]

    Attributes
    protected[streaming]
  11. var checkpointDuration: Duration

    Attributes
    protected[streaming]
  12. def clearOldMetadata(time: Time): Unit

    Clear metadata that are older than rememberDuration of this DStream.

    Clear metadata that are older than rememberDuration of this DStream. This is an internal method that should not be called directly. This default implementation clears the old generated RDDs. Subclasses of DStream may override this to clear their own metadata along with the generated RDDs.

    Attributes
    protected[streaming]
  13. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  14. def context: StreamingContext

    Return the StreamingContext associated with this DStream

  15. def count(): DStream[Long]

    Return a new DStream in which each RDD has a single element generated by counting each RDD of this DStream.

  16. def countByValue(numPartitions: Int = ssc.sc.defaultParallelism): DStream[(T, Long)]

    Return a new DStream in which each RDD contains the counts of each distinct value in each RDD of this DStream.

    Return 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 with numPartitions partitions (Spark's default number of partitions if numPartitions not specified).

  17. def countByValueAndWindow(windowDuration: Duration, slideDuration: Duration, numPartitions: Int = ssc.sc.defaultParallelism): DStream[(T, Long)]

    Return a new DStream in which each RDD contains the count of distinct elements in RDDs in a sliding window over this DStream.

    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 with numPartitions partitions (Spark's default number of partitions if numPartitions not specified).

    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.

  18. def countByWindow(windowDuration: Duration, slideDuration: Duration): DStream[Long]

    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.

    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. Hash partitioning is used to generate the RDDs with Spark's default number of partitions.

    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

  19. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  21. def filter(filterFunc: (T) ⇒ Boolean): DStream[T]

    Return a new DStream containing only the elements that satisfy a predicate.

  22. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. def flatMap[U](flatMapFunc: (T) ⇒ Traversable[U])(implicit arg0: ClassManifest[U]): DStream[U]

    Return a new DStream by applying a function to all elements of this DStream, and then flattening the results

  24. def foreach(foreachFunc: (RDD[T], Time) ⇒ Unit): Unit

    Apply a function to each RDD in this DStream.

    Apply 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.

  25. def foreach(foreachFunc: (RDD[T]) ⇒ Unit): Unit

    Apply a function to each RDD in this DStream.

    Apply 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.

  26. def generateJob(time: Time): Option[Job]

    Generate a SparkStreaming job for the given time.

    Generate a SparkStreaming job for the given time. This is an internal method that should not be called directly. This default implementation creates a job that materializes the corresponding RDD. Subclasses of DStream may override this to generate their own jobs.

    Attributes
    protected[streaming]
  27. var generatedRDDs: HashMap[Time, RDD[T]]

    Attributes
    protected[streaming]
  28. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  29. def getOrCompute(time: Time): Option[RDD[T]]

    Retrieve a precomputed RDD of this DStream, or computes the RDD.

    Retrieve a precomputed RDD of this DStream, or computes the RDD. This is an internal method that should not be called directly.

    Attributes
    protected[streaming]
  30. def glom(): DStream[Array[T]]

    Return a new DStream in which each RDD is generated by applying glom() to each RDD of this DStream.

    Return 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.

  31. var graph: DStreamGraph

    Attributes
    protected[streaming]
  32. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  33. def initLogging(): Unit

    Attributes
    protected
    Definition Classes
    Logging
  34. def initialize(time: Time): Unit

    Initialize the DStream by setting the "zero" time, based on which the validity of future times is calculated.

    Initialize the DStream by setting the "zero" time, based on which the validity of future times is calculated. This method also recursively initializes its parent DStreams.

    Attributes
    protected[streaming]
  35. def isInitialized: Boolean

    Attributes
    protected[streaming]
  36. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  37. def isTimeValid(time: Time): Boolean

    Checks whether the 'time' is valid wrt slideDuration for generating RDD

    Checks whether the 'time' is valid wrt slideDuration for generating RDD

    Attributes
    protected
  38. def log: Logger

    Attributes
    protected
    Definition Classes
    Logging
  39. def logDebug(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  40. def logDebug(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  41. def logError(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  42. def logError(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  43. def logInfo(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  44. def logInfo(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  45. def logTrace(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  46. def logTrace(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  47. def logWarning(msg: ⇒ String, throwable: Throwable): Unit

    Attributes
    protected
    Definition Classes
    Logging
  48. def logWarning(msg: ⇒ String): Unit

    Attributes
    protected
    Definition Classes
    Logging
  49. def map[U](mapFunc: (T) ⇒ U)(implicit arg0: ClassManifest[U]): DStream[U]

    Return a new DStream by applying a function to all elements of this DStream.

  50. def mapPartitions[U](mapPartFunc: (Iterator[T]) ⇒ Iterator[U], preservePartitioning: Boolean)(implicit arg0: ClassManifest[U]): DStream[U]

    Return a new DStream in which each RDD is generated by applying mapPartitions() to each RDDs of this DStream.

    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.

  51. val mustCheckpoint: Boolean

    Attributes
    protected[streaming]
  52. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  53. final def notify(): Unit

    Definition Classes
    AnyRef
  54. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  55. def parentRememberDuration: Duration

    Attributes
    protected[streaming]
  56. def persist(): DStream[T]

    Persist RDDs of this DStream with the default storage level (MEMORY_ONLY_SER)

  57. def persist(level: StorageLevel): DStream[T]

    Persist the RDDs of this DStream with the given storage level

  58. def print(): Unit

    Print the first ten elements of each RDD generated in this DStream.

    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.

  59. def reduce(reduceFunc: (T, T) ⇒ T): DStream[T]

    Return a new DStream in which each RDD has a single element generated by reducing each RDD of this DStream.

  60. def reduceByWindow(reduceFunc: (T, T) ⇒ T, invReduceFunc: (T, T) ⇒ T, windowDuration: Duration, slideDuration: Duration): DStream[T]

    Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over 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. 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".
    reduceFunc

    associative reduce function

    invReduceFunc

    inverse 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

  61. def reduceByWindow(reduceFunc: (T, T) ⇒ T, windowDuration: Duration, slideDuration: Duration): DStream[T]

    Return a new DStream in which each RDD has a single element generated by reducing all elements in a sliding window over 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.

    reduceFunc

    associative 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

  62. def register(): Unit

  63. def remember(duration: Duration): Unit

    Attributes
    protected[streaming]
  64. var rememberDuration: Duration

    Attributes
    protected[streaming]
  65. def restoreCheckpointData(): Unit

    Restore the RDDs in generatedRDDs from the checkpointData.

    Restore the RDDs in generatedRDDs from the checkpointData. This is an internal method that should not be called directly. This is a default implementation that recreates RDDs from the checkpoint file names stored in checkpointData. Subclasses of DStream that override the updateCheckpointData() method would also need to override this method.

    Attributes
    protected[streaming]
  66. def saveAsObjectFiles(prefix: String, suffix: String = ""): Unit

    Save each RDD in this DStream as a Sequence file of serialized objects.

    Save each RDD in this DStream as a Sequence file of serialized objects. The file name at each batch interval is generated based on prefix and suffix: "prefix-TIME_IN_MS.suffix".

  67. def saveAsTextFiles(prefix: String, suffix: String = ""): Unit

    Save each RDD in this DStream as at text file, using string representation of elements.

    Save each RDD in this DStream as at text file, using string representation of elements. The file name at each batch interval is generated based on prefix and suffix: "prefix-TIME_IN_MS.suffix".

  68. def setContext(s: StreamingContext): Unit

    Attributes
    protected[streaming]
  69. def setGraph(g: DStreamGraph): Unit

    Attributes
    protected[streaming]
  70. def slice(fromTime: Time, toTime: Time): Seq[RDD[T]]

    Return all the RDDs between 'fromTime' to 'toTime' (both included)

  71. def slice(interval: Interval): Seq[RDD[T]]

    Return all the RDDs defined by the Interval object (both end times included)

    Return all the RDDs defined by the Interval object (both end times included)

    Attributes
    protected[streaming]
  72. var ssc: StreamingContext

    Attributes
    protected[streaming]
  73. var storageLevel: StorageLevel

    Attributes
    protected[streaming]
  74. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  75. def toString(): String

    Definition Classes
    AnyRef → Any
  76. def transform[U](transformFunc: (RDD[T], Time) ⇒ RDD[U])(implicit arg0: ClassManifest[U]): DStream[U]

    Return a new DStream in which each RDD is generated by applying a function on each RDD of this DStream.

  77. def transform[U](transformFunc: (RDD[T]) ⇒ RDD[U])(implicit arg0: ClassManifest[U]): DStream[U]

    Return a new DStream in which each RDD is generated by applying a function on each RDD of this DStream.

  78. def union(that: DStream[T]): DStream[T]

    Return a new DStream by unifying data of another DStream with this DStream.

    Return a new DStream by unifying data of another DStream with this DStream.

    that

    Another DStream having the same slideDuration as this DStream.

  79. def updateCheckpointData(currentTime: Time): Unit

    Refresh the list of checkpointed RDDs that will be saved along with checkpoint of this stream.

    Refresh the list of checkpointed RDDs that will be saved along with checkpoint of this stream. This is an internal method that should not be called directly. This is a default implementation that saves only the file names of the checkpointed RDDs to checkpointData. Subclasses of DStream (especially those of InputDStream) may override this method to save custom checkpoint data.

    Attributes
    protected[streaming]
  80. def validate(): Unit

    Attributes
    protected[streaming]
  81. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  82. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  83. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  84. def window(windowDuration: Duration, slideDuration: Duration): DStream[T]

    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.

    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

  85. def window(windowDuration: Duration): DStream[T]

    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. The new DStream generates RDDs with the same interval as this DStream.

    windowDuration

    width of the window; must be a multiple of this DStream's interval.

  86. var zeroTime: Time

    Attributes
    protected[streaming]

Inherited from Logging

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any