Spark RDD Countapproxdistinct

Source: Internet
Author: User
Tags spark rdd

 PackageCom.latrobe.sparkImportOrg.apache.spark. {sparkconf, Sparkcontext}/*** Created by Spark on 15-1-18.* Countapproxdistinct:rdda method that is useful forRDDThe collection content is de-re-counted.  * The statistic is an approximate statistic, the parametersrelativesdcontrol the accuracy of statistics.  * RELATIVESDthe smaller the result, the more accurate */Objectcountapproxdistinct {defMain(args:array[String]) {Valconf =NewSparkconf (). Setappname ("Spark-demo"). Setmaster ("Local")Valsc =NewSparkcontext (CONF)/**     * build a collection that is divided into -aPartition     */    ValA = Sc.parallelize (1To10000,  -)//rdd aContent Replication5times, which had50000an element    Valb = A++a++a++a++a//The result is9760, does not pass parameters, the default is0.05    println(B.countapproxdistinct ())//The result is9760    println(B.countapproxdistinct (0.05))//8224    println(B.countapproxdistinct (0.1))//10000    println(B.countapproxdistinct (0.001))  }}

Spark RDD Countapproxdistinct

Related Article

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.