Spark1.1.0 actions

Source: Internet
Author: User
Actions

The following table lists some of the common actions supported by spark. Refer to the rdd api doc (Scala, Java, Python) and pair RDD functions DOC (Scala, Java) for details.

Action Meaning
Reduce(Func) Aggregate the elements of the dataset using a functionFunc(Which takes two arguments and returns one). The function shocould be commutative and associative so that it can be computed correctly in parallel.
Collect() Return all the elements of the dataset as an array at the driver program. This is usually useful after a filter or other operation that returns a sufficiently small subset of the data.
Count() Return the number of elements in the dataset.
First() Return the first element of the dataset (similar to take (1 )).
Take(N) Return an array with the firstNElements of the dataset. Note that this is currently not executed in parallel. Instead, the driver program computes all the elements.
Takesample(Withreplacement,Num,[Seed]) Return an array with a random sampleNumElements of the dataset, with or without replacement, optionally pre-specifying a random number generator seed.
Takeordered(N,[Ordering]) Return the firstNElements of the RDD using either their natural order or a custom comparator.
Saveastextfile(Path) Write the elements of the dataset as a text file (or set of text files) in a given directory in the local filesystem, HDFS or any other hadoop-Supported file system. spark will call tostring on each element to convert it to a line of text in the file.
Saveassequencefile(Path)
(Java and Scala)
Write the elements of the dataset as a hadoop sequencefile in a given path in the local filesystem, HDFS or any other hadoop-Supported file system. this is available on RDDs of key-value pairs that either implement hadoop's writable interface. in Scala, it is also available on types that are implicitly convertible to writable (spark into des conversions for basic types like int, double, String, etc ).
Saveasobjectfile(Path)
(Java and Scala)
Write the elements of the dataset in a simple format using Java serialization, which can then be loaded usingSparkContext.objectFile().
Countbykey() Only available on RDDs of type (K, V). Returns a hashmap of (K, INT) pairs with the Count of each key.
Foreach(Func) Run a functionFuncOn each element of the dataset. This is usually done for side effects such as updating an accumulator variable (see below) or interacting with external storage systems.

Spark1.1.0 actions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.