GitHub user saucam opened a pull request:

    https://github.com/apache/spark/pull/4764

    SPARK-6006: Optimize count distinct for high cardinality columns

    Currently the plan for count distinct looks like this : 
    
    Aggregate false, [snAppProtocol#448], [CombineAndCount(partialSets#513) AS 
_c0#437L]
       Exchange SinglePartition
        Aggregate true, [snAppProtocol#448], 
[snAppProtocol#448,AddToHashSet(snAppProtocol#448) AS partialSets#513]
         !OutputFaker [snAppProtocol#448]
          ParquetTableScan [snAppProtocol#587], (ParquetRelation 
hdfs://192.168.160.57:9000/data/collector/13/11/14, Some(Configuration: 
core-default.xml, core-site.xml, mapred-default.xml, mapred-site.xml, 
yarn-default.xml, yarn-site.xml, hdfs-default.xml, hdfs-site.xml), 
org.apache.spark.sql.hive.HiveContext@6b1ed434, [ptime#443], ptime=2014-11-13 
00%3A55%3A00), []
    
    
    This can be slow if there are too many distinct values in a column. This PR 
changes the above plan to : 
    
    
    Aggregate false, [], [SUM(_c0#437L) AS totalCount#514L]
     Exchange SinglePartition
      Aggregate false, [snAppProtocol#448], [CombineAndCount(partialSets#513) 
AS _c0#437L]
       Exchange (HashPartitioning [snAppProtocol#448], 200)
        Aggregate true, [snAppProtocol#448], 
[snAppProtocol#448,AddToHashSet(snAppProtocol#448) AS partialSets#513]
         !OutputFaker [snAppProtocol#448]
          ParquetTableScan [snAppProtocol#587], (ParquetRelation 
hdfs://192.168.160.57:9000/data/collector/13/11/14, Some(Configuration: 
core-default.xml, core-site.xml, mapred-default.xml, mapred-site.xml, 
yarn-default.xml, yarn-site.xml, hdfs-default.xml, hdfs-site.xml), 
org.apache.spark.sql.hive.HiveContext@6b1ed434, [ptime#443], ptime=2014-11-13 
00%3A55%3A00), []
    
    This way even if there are too many distinct values; we insert them into 
partial maps and computation remains distributed and thus faster.
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/saucam/spark optcountdis

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/4764.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #4764
    
----
commit 3e6d227184451026dbfda9866ae1e114bde002b1
Author: Yash Datta <[email protected]>
Date:   2015-02-25T12:09:01Z

    SPARK-6006: Optimize count distinct for high cardinality columns

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to