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

Alicia Ying Shu commented on PHOENIX-1580:
------------------------------------------

I met an issue when I implemented Union All for aggregate functions. Your 
insight is appreciated. For example:

Select count(*) from t1 union all Select count(*) from t2;

In PhonenixStatement.java  

protected PhoenixResultSet executeQuery(final CompilableStatement stmt) throws 
SQLException:

 return CallRunner.run(
                new CallRunner.CallableThrowable<PhoenixResultSet, 
SQLException>() {
                @Override
                    public PhoenixResultSet call() throws SQLException {
                    try {
                        boolean chainUnionRes = false;
                        QueryPlan plan = 
stmt.compilePlan(PhoenixStatement.this, Sequence.ValueOp.RESERVE_SEQUENCE);
                        plan = 
connection.getQueryServices().getOptimizer().optimize(
                            PhoenixStatement.this, plan); 
                         // this will create its own trace internally, so we 
don't wrap this
                         // whole thing in tracing
                        ResultIterator resultIterator = plan.iterator();
                        if (logger.isDebugEnabled()) {
                            String explainPlan = 
QueryUtil.getExplainPlan(resultIterator);
                            logger.debug(LogUtil.addCustomAnnotations("Explain 
plan: " + explainPlan, connection));
                        }
                        PhoenixResultSet rs = newResultSet(resultIterator, 
plan.getProjector());
                        resultSets.add(rs);
                        setLastQueryPlan(plan);
                        setLastResultSet(rs);
                        setLastUpdateCount(NO_UPDATE);
                        setLastUpdateOperation(stmt.getOperation());            
   
                        return rs;
                    } catch (RuntimeException e) {

We need to get ONE RowProject and I used the rowProjector of one of the 
selects. When evaluating the result, the “aggregator” we get is the aggregator 
for that one select which gives wrong result for other selects since the 
aggregate value is cached for that Aggregator.

My workaround is to submit the query at the PhoenixStatement level and create 
PhoenixResultSet for each individual Aggregate select and chain the result 
sets. But it did not work for Union All with ORDER BY which needs all the 
result sets together.

I have thought about the following, please give comments:
1. Associate each ResultIterator with its RowProjector for Union All so as to 
evaluate result set with right RowProjector?
2. Any other better suggestions?
Thanks!

> Support UNION ALL
> -----------------
>
>                 Key: PHOENIX-1580
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1580
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Alicia Ying Shu
>            Assignee: Alicia Ying Shu
>         Attachments: unionall-wipe.patch
>
>
> Select * from T1
> UNION ALL
> Select * from T2



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

Reply via email to