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.
nodeClass=DistinctCountHyperLogLogAggregateParseNode.class, args= {@Argument()} 
+public class DistinctCountHyperLogLogAggregateFunction extends 
DelegateConstantToCountAggregateFunction {
+    public static final String NAME = "APPROX_COUNT_DISTINCT";
+    public DistinctCountHyperLogLogAggregateFunction() {
+    }
+    public DistinctCountHyperLogLogAggregateFunction(List<Expression> 
+        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 
+ * @since 4.11

> Support approximate COUNT DISTINCT
> ----------------------------------
>                 Key: PHOENIX-418
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-418
>             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](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).

This message was sent by Atlassian JIRA

Reply via email to