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

James Taylor commented on PHOENIX-1264:
---------------------------------------

[~ramkrishna] - as an alternative like we talked about offline, you can 
piggyback on the UngroupedAggregateRegionObserver coprocessor instead of 
creating your own. Instead of having an endpoint coprocessor to re-analyze the 
stats, set a special attribute on the scan and then run a count(*) query like 
this example from MetaDataUtil. Might as well return how many rows were 
analyzed (instead of always 1 in the MutationState), since you'll be 
calculating this value:
{code}
    private MutationState buildIndex(PTable index, TableRef dataTableRef) 
throws SQLException {
        ...
               String query = "SELECT count(*) FROM " + tableName;
                QueryPlan plan = statement.compileQuery(query);
                Scan scan = plan.getContext().getScan();
                scan.setAttribute(BaseScannerRegionObserver.MySpecialAttribute, 
PDataType.TRUE_BYTES);
                // Executes the QueryPlan by getting the iterator and calling 
next
                Cell kv = plan.iterator().next().getValue(0);
                ImmutableBytesWritable tmpPtr = new 
ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), 
kv.getValueLength());
                // A single Cell will be returned with the count(*) - we decode 
that here
                long rowCount = PDataType.LONG.getCodec().decodeLong(tmpPtr, 
SortOrder.getDefault());
                state = new MutationState(0, connection, rowCount);
{code}

> Add StatisticsCollector to existing tables on first connection to cluster
> -------------------------------------------------------------------------
>
>                 Key: PHOENIX-1264
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1264
>             Project: Phoenix
>          Issue Type: Sub-task
>            Reporter: James Taylor
>
> We'll need to add the StatisticsCollector to existing tables so that stats 
> are kept for these tables. We typically do that on first connection to the 
> cluster in ensureTableCreated when our system table is created by walking 
> through the existing Phoenix tables. We only need to do it if the system 
> table already exists (otherwise, it's a new installation).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to