phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Taylor (JIRA)" <>
Subject [jira] [Commented] (PHOENIX-418) Support approximate COUNT DISTINCT
Date Sat, 05 Aug 2017 21:02:00 GMT


James Taylor commented on PHOENIX-418:

Thanks for the patch, [~aertoria]. The transitive dependencies of licenses look fine. Here's
some feedback:
- You should be able to derive DistinctCountHyperLogLogAggregateFunction from DistinctCountAggregateFunction
and simply override the getName, newClientAggregator and newServerAggregator methods. The
behavior for things like COUNT(DISTINCT 123)) should be the same as APPROXIMATE_COUNT_DISTINCT(123),
returning either 0 or 1. The getDataType and evaluate method will be the same as DistinctCountAggregateFunction:
the return type should always be of type PLong and the evaluate method will have the same
special cases when a constant is used as the argument.
+@BuiltInFunction(name=DistinctCountHyperLogLogAggregateFunction.NAME, nodeClass=DistinctCountHyperLogLogAggregateParseNode.class,
args= {@Argument()} )
+public class DistinctCountHyperLogLogAggregateFunction extends DelegateConstantToCountAggregateFunction
+    public static final String NAME = "APPROX_COUNT_DISTINCT";
+    public DistinctCountHyperLogLogAggregateFunction() {
+    }
+    public DistinctCountHyperLogLogAggregateFunction(List<Expression> childExpressions){
+        super(childExpressions, null);
+    }
+    public DistinctCountHyperLogLogAggregateFunction(List<Expression> childExpressions,
CountAggregateFunction delegate){
+        super(childExpressions, delegate);
+    }
+    private Aggregator newAggregatorServer(final PDataType type, SortOrder sortOrder, ImmutableBytesWritable
ptr) {
+    	return new HyperLogLogServerAggregator(sortOrder, ptr) {
+            @Override
+            protected PDataType getInputDataType() {
+              return type;
+            }
+          };
+    }
- Minor nit, but if you include an @since tag, make the release the *next* release (i.e. the
release this function will appear in), not the current release:
+ * @since 4.11

> Support approximate COUNT DISTINCT
> ----------------------------------
>                 Key: PHOENIX-418
>                 URL:
>             Project: Phoenix
>          Issue Type: Task
>            Reporter: James Taylor
>            Assignee: Ethan Wang
>              Labels: gsoc2016
>         Attachments: PHOENIX-418-v1.patch, PHOENIX-418-v2.patch, PHOENIX-418-v3.patch
> 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](
They recommend using  [Welford's method](
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).

This message was sent by Atlassian JIRA

View raw message