[
https://issues.apache.org/jira/browse/PHOENIX-1580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14387882#comment-14387882
]
Maryann Xue commented on PHOENIX-1580:
--------------------------------------
[~ayingshu] Here's more feedback:
1. Why do we need to handle differently here for isUnionAll()?
{code}
@@ -446,6 +505,9 @@ public class QueryCompiler {
protected QueryPlan compileSingleQuery(StatementContext context,
SelectStatement select, List<Object> binds, boolean asSubquery, boolean
allowPageFilter) throws SQLException{
SelectStatement innerSelect = select.getInnerSelectStatement();
if (innerSelect == null) {
+ if (isUnionAll()) {
+ return compileSingleFlatQuery(context, select, binds,
asSubquery, allowPageFilter, null, null, false);
+ }
return compileSingleFlatQuery(context, select, binds, asSubquery,
allowPageFilter, null, null, true);
}
{code}
2. And why do we need to re-resolve the columns for union all here? Has the
select statement been changed somewhere?
{code}
+ ColumnResolver resolver;
+ if (isUnionAll()) {
+ resolver = FromCompiler.getResolverForQuery(select,
statement.getConnection());
+ context = new StatementContext(statement, resolver, new Scan(),
sequenceManager);
+ }
{code}
3. In ParseNodeFactory.select(List<SelectStatement> statements,
List<OrderByNode> orderBy, LimitNode limit, int bindCount, boolean
isAggregate), I don't think pulling out the first sub-select as the outmost
select is a very good idea, instead you should compose a new select by
yourself, with a wildcard projection, a null where, an empty groupby, an order
by and a limit as specified. Plus, there is no need for the flag "isAggregate",
as it will be and only needs to be set correctly for the sub-selects; while for
your outmost query, it is always false.
4. Based on the previous adjustment, think the method compileUnionAll() should
be something like:
{code}
+
+ public QueryPlan compileUnionAll(SelectStatement select) throws
SQLException {
+ List<SelectStatement> unionAllSelects = select.getSelects();
+ List<QueryPlan> plans = new ArrayList<QueryPlan>();
+
+ int numSelects = unionAllSelects.size();
+ for (int i=0; i < numSelects; i++ ) {
+ plan = compileSubquery(unionAllSelects.get(i));
+ projector = new TupleProjector(plan.getProjector());
+ plan = new TupleProjectionPlan(plan, projector, null);
+ plans.add(plan);
+ }
+ UnionCompiler.checkProjectionNumAndTypes(plans);
+
+ TableRef tableRef = UnionCompiler.contructSchemaTable(statement, plan);
+ ColumnResolver resolver = FromCompiler.getResolver(tableRef);
+ StatementContext context = new StatementContext(statement, resolver,
scan, sequenceManager);
+
+ QueryPlan plan = compileSingleFlatQuery(context, select, binds, false,
false, null, null, false);
+ plan = new UnionPlan(context, select, tableRef, plan.getProjector(),
plan.getLimit(), plan.getOrderBy(), parallelIteratorFactory,
GroupBy.EMPTY_GROUP_BY, plans, null);
+ return plan;
+ }
{code}
One more adjustment to make along with this: you need to replace your dummy
column names in your temporary schema with real column names from one of the
sub-selects.
The above code should get the projection, ORDER BY expression and LIMIT working
altogether. It uses "compileSingleFlatQuery()" to compile the outmost query
with the right context, exactly the same way we handle the outer query of
derived tables in "compileSingleQuery()".
And I think you can now remove UnionCompiler.constructSelect(), as I see it
only returns an identical copy of your input select statement. But you may need
something else for pushing down ORDER BY or LIMIT to sub-selects.
> 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: PHOENIX-1580-grammar.patch, Phoenix-1580-v1.patch,
> phoenix-1580-v1-wipe.patch, phoenix-1580.patch, unionall-wipe.patch
>
>
> Select * from T1
> UNION ALL
> Select * from T2
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)