Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-418

Support approximate COUNT DISTINCT

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • None
    • 4.12.0
    • None
    • 287

    Description

      Support an "approximation" of count distinct to prevent having to hold on to all distinct values (since this will not scale well when the number of distinct values is huge). The Apache Drill folks have had some interesting discussions on this [here](http://mail-archives.apache.org/mod_mbox/incubator-drill-dev/201306.mbox/%3CJIRA.12650169.1369931282407.88049.1370645900553%40arcas%3E). They recommend using [Welford's method](http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance_Online_algorithm). I'm open to having a config option that uses exact versus approximate. I don't have experience implementing an approximate implementation, so I'm not sure how much state is required to keep on the server and return to the client (other than realizing it'd be much less that returning all distinct values and their counts).

      Update:
      Syntax of using approximate count distinct as:
      select APPROX_COUNT_DISTINCT(name) from person
      select APPROX_COUNT_DISTINCT(address||name) from person

      It is equivalent of Select COUNT(DISTINCT ID) from person. Implemented using hyperloglog, see discuss below.

      Source code patch link below, co-authorred with Swapna Kasula
      https://git-wip-us.apache.org/repos/asf?p=phoenix.git;a=commitdiff;h=d6381afc3af976ccdbb874d4458ea17b1e8a1d32

      Attachments

        1. PHOENIX-418-v6-pom.patch
          2 kB
          Ethan Wang
        2. PHOENIX-418-v6.patch
          19 kB
          Ethan Wang
        3. PHOENIX-418-v5.patch
          19 kB
          Ethan Wang
        4. PHOENIX-418-v4.patch
          20 kB
          Ethan Wang
        5. PHOENIX-418-v3.patch
          22 kB
          Ethan Wang
        6. PHOENIX-418-v2.patch
          37 kB
          Ethan Wang
        7. PHOENIX-418-v1.patch
          206 kB
          Ethan Wang

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            aertoria Ethan Wang
            jamestaylor James R. Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment