Search in sources :

Example 1 with UnionPlan

use of org.apache.phoenix.execute.UnionPlan in project phoenix by apache.

the class QueryCompiler method compileUnionAll.

public QueryPlan compileUnionAll(SelectStatement select) throws SQLException {
    List<SelectStatement> unionAllSelects = select.getSelects();
    List<QueryPlan> plans = new ArrayList<QueryPlan>();
    for (int i = 0; i < unionAllSelects.size(); i++) {
        SelectStatement subSelect = unionAllSelects.get(i);
        // Push down order-by and limit into sub-selects.
        if (!select.getOrderBy().isEmpty() || select.getLimit() != null) {
            if (select.getOffset() == null) {
                subSelect = NODE_FACTORY.select(subSelect, select.getOrderBy(), select.getLimit(), null);
            } else {
                subSelect = NODE_FACTORY.select(subSelect, select.getOrderBy(), null, null);
            }
        }
        QueryPlan subPlan = compileSubquery(subSelect, true);
        plans.add(subPlan);
    }
    TableRef tableRef = UnionCompiler.contructSchemaTable(statement, plans, select.hasWildcard() ? null : select.getSelect());
    ColumnResolver resolver = FromCompiler.getResolver(tableRef);
    StatementContext context = new StatementContext(statement, resolver, scan, sequenceManager);
    QueryPlan plan = compileSingleFlatQuery(context, select, statement.getParameters(), false, false, null, null, false);
    plan = new UnionPlan(context, select, tableRef, plan.getProjector(), plan.getLimit(), plan.getOffset(), plan.getOrderBy(), GroupBy.EMPTY_GROUP_BY, plans, context.getBindManager().getParameterMetaData());
    return plan;
}
Also used : SelectStatement(org.apache.phoenix.parse.SelectStatement) ArrayList(java.util.ArrayList) Hint(org.apache.phoenix.parse.HintNode.Hint) TableRef(org.apache.phoenix.schema.TableRef) UnionPlan(org.apache.phoenix.execute.UnionPlan)

Aggregations

ArrayList (java.util.ArrayList)1 UnionPlan (org.apache.phoenix.execute.UnionPlan)1 Hint (org.apache.phoenix.parse.HintNode.Hint)1 SelectStatement (org.apache.phoenix.parse.SelectStatement)1 TableRef (org.apache.phoenix.schema.TableRef)1