phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maryann Xue (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (PHOENIX-1580) Support UNION ALL
Date Sat, 04 Apr 2015 02:27:34 GMT

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

Maryann Xue commented on PHOENIX-1580:
--------------------------------------

This is what I put in ParseNodeFactory.select(), very simple straight-forward steps:
{code}
+    public SelectStatement select(List<SelectStatement> statements, List<OrderByNode>
orderBy, LimitNode limit, int bindCount) {
+        if (statements.size() == 1)
+            return statements.get(0);
+        
+        return select(null, HintNode.EMPTY_HINT_NODE, false, Lists.newArrayList(aliasedNode(null,
wildcard())), 
+                null, null, null, null, limit, bindCount, false, false, statements);
+    }
+
{code}

And this is what compiler does for ORDER-BY and LIMIT push down:
{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++ ) {
+            SelectStatement subSelect = unionAllSelects.get(i);
+            // Push down order-by and limit into sub-selects.
+            if (!select.getOrderBy().isEmpty() || select.getLimit() != null) {
+                subSelect = NODE_FACTORY.select(subSelect, select.getOrderBy(), select.getLimit());
+            }
+            QueryPlan subPlan = compileSubquery(subSelect);
+            TupleProjector projector = new TupleProjector(subPlan.getProjector());
+            subPlan = new TupleProjectionPlan(subPlan, projector, null);
+            plans.add(subPlan);
+        }
+        UnionCompiler.checkProjectionNumAndTypes(plans);
+
+        TableRef tableRef = UnionCompiler.contructSchemaTable(statement, plans.get(0));
+        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.getOrderBy(), GroupBy.EMPTY_GROUP_BY, plans, null); 
+        return plan;
+    }
{code}

> Support UNION ALL
> -----------------
>
>                 Key: PHOENIX-1580
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1580
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: Alicia Ying Shu
>            Assignee: Alicia Ying Shu
>         Attachments: PHOENIX-1580-grammar.patch, Phoenix-1580-v1.patch, Phoenix-1580-v2.patch,
Phoenix-1580-v3.patch, Phoenix-1580-v4.patch, Phoenix-1580-v5.patch, Phoenix-1580-v6.patch,
Phoenix-1580-v7.patch, Phoenix-1580-v8.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)

Mime
View raw message