[ 
https://issues.apache.org/jira/browse/PHOENIX-418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16137402#comment-16137402
 ] 

James Taylor commented on PHOENIX-418:
--------------------------------------

Thanks for the revised patch, [~aertoria]. Looks very good. A couple of minor 
things:
- derive your test from ParallelStatsDisabledIT instead of 
BaseUniqueNamesOwnClusterIT and remove the setup method which you won't need. 
The advantage of ParallelStatsDisabledIT tests are that they don't need to each 
spin up a new mini cluster when they run so are overall test run time stays 
lower.
{code}
+public class CountDistinctApproximateHyperLogLogIT extends 
BaseUniqueNamesOwnClusterIT {
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        Map<String, String> props = Maps.newHashMapWithExpectedSize(3);
+        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    }
+
{code}
- I think it also makes sense to have another test derived from 
ParallelStatsEnabledIT. This base test class is configured to collect 
statistics. In this way, you can get more test coverage. You can likely run the 
exact same tests, but in this case you'll have guideposts in place (because 
stats will be collected). Make sure to call TestUtil.analyzeTable(connection, 
fullTableName) prior to running your TABLESAMPLE queries. You'll get more rows 
back, since you'll have guideposts in addition to region boundaries.
- minor nit, extra semicolon here:
{code}
+    
DistinctCountHyperLogLogAggregateFunction(DistinctCountHyperLogLogAggregateFunction.class);;
{code}
- Instead of always copying the underlying byte buffer, use 
ByteUtil.copyKeyBytesIfNecessary(ImmutableBytesWritable ptr) instead which only 
copies when necessary:
+       @Override
+       public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {      
+               try {
+                       valueByteArray.set(hll.getBytes(), 0, 
hll.getBytes().length);
+                       ptr.set(valueByteArray.copyBytes());
{code}

> 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, PHOENIX-418-v4.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
(v6.4.14#64029)

Reply via email to