A Resilient Distributed Dataset (RDD), the basic abstraction in Spark. Represents an immutable,partitioned collection of elements that can be operated on in parallel. This class contains thebasic operations available on all RDDs, such asmap,filter, andpersist. In addition,PairRDDFunctions contains operations available only on RDDs of key-value pairs, suchasgroupByKey andjoin;DoubleRDDFunctions contains operations available only onRDDs of Doubles; andSequenceFileRDDFunctions contains operations available on RDDsthat can be saved as SequenceFiles. These operations are automatically available on any RDD ofthe right type (e.g. RDD[(Int, Int)] through implicit conversions when youimport spark.SparkContext._.
Internally, each RDD is characterized by five main properties:
All of the scheduling and execution in Spark is done based on these methods, allowing each RDDto implement its own way of computing itself. Indeed, users can implement custom RDDs (e.g. forreading data from a new storage system) by overriding these functions. Please refer to theSpark paper for more detailson RDD internals.
Return the union of this RDD and another one.
Return the union of this RDD and another one. Any identical elements will appear multipletimes (use.distinct() to eliminate them).
Aggregate the elements of each partition, and then the results for all the partitions, usinggiven combine functions and a neutral "zero value".
Aggregate the elements of each partition, and then the results for all the partitions, usinggiven combine functions and a neutral "zero value". This function can return a different resulttype, U, than the type of this RDD, T. Thus, we need one operation for merging a T into an Uand one operation for merging two U's, as in scala.TraversableOnce. Both of these functions areallowed to modify and return their first argument instead of creating a new U to avoid memoryallocation.
Persist this RDD with the default storage level (MEMORY_ONLY).
Return the Cartesian product of this RDD and another one, that is, the RDD of all pairs ofelements (a, b) where a is inthis and b is inother.
Return an array that contains all of the elements in this RDD.
TheSparkContext that this RDD was created on.
Return the number of elements in the RDD.
(Experimental) Approximate version of count() that returns a potentially incomplete resultwithin a timeout, even if not all tasks have finished.
Return the count of each unique value in this RDD as a map of (value, count) pairs.
Return the count of each unique value in this RDD as a map of (value, count) pairs. The finalcombine step happens locally on the master, equivalent to running a single reduce task.
(Experimental) Approximate version of countByValue().
Return a new RDD containing the distinct elements in this RDD.
Return a new RDD containing only the elements that satisfy a predicate.
Return the first element in this RDD.
Return a new RDD by first applying a function to all elements of this RDD, and then flattening the results.
Aggregate the elements of each partition, and then the results for all the partitions, using agiven associative function and a neutral "zero value".
Aggregate the elements of each partition, and then the results for all the partitions, using agiven associative function and a neutral "zero value". The function op(t1, t2) is allowed tomodify t1 and return it as its result value to avoid object allocation; however, it should notmodify t2.
Applies a function f to all elements of this RDD.
Get the RDD's current storage level, or StorageLevel.
Get the RDD's current storage level, or StorageLevel.NONE if none is set.
Return an RDD created by coalescing all elements within each partition into an array.
Return an RDD of grouped items.
Return an RDD of grouped elements.
Return an RDD of grouped elements. Each group consists of a key and a sequence of elementsmapping to that key.
A unique ID for this RDD (within its SparkContext).
Internal method to this RDD; will read from cache if applicable, or otherwise compute it.
Internal method to this RDD; will read from cache if applicable, or otherwise compute it.This shouldnot be called by users directly, but is available for implementors of customsubclasses of RDD.
Return a new RDD by applying a function to all elements of this RDD.
Return a new RDD by applying a function to each partition of this RDD.
Return a new RDD by applying a function to each partition of this RDD, while tracking the indexof the original partition.
Optionally overridden by subclasses to specify how they are partitioned.
Persist this RDD with the default storage level (MEMORY_ONLY).
Set this RDD's storage level to persist its values across operations after the first timeit is computed.
Set this RDD's storage level to persist its values across operations after the first timeit is computed. Can only be called once on each RDD.
Return an RDD created by piping elements to a forked external process.
Return an RDD created by piping elements to a forked external process.
Return an RDD created by piping elements to a forked external process.
Optionally overridden by subclasses to specify placement preferences.
Reduces the elements of this RDD using the specified associative binary operator.
Return a sampled subset of this RDD.
Save this RDD as a SequenceFile of serialized objects.
Save this RDD as a text file, using string representations of elements.
Take the first num elements of the RDD.
Take the first num elements of the RDD. This currently scans the partitions *one by one*, soit will be slow if a lot of partitions are required. In that case, use collect() to get thewhole RDD instead.
Return an array that contains all of the elements in this RDD.
Return the union of this RDD and another one.
Return the union of this RDD and another one. Any identical elements will appear multipletimes (use.distinct() to eliminate them).