[
https://issues.apache.org/jira/browse/PHOENIX-1580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14363687#comment-14363687
]
James Taylor commented on PHOENIX-1580:
---------------------------------------
Thanks for the patch, [~ayingshu]. Would be good if [~maryannxue] reviewed, but
here's some initial high-level comments and questions:
- No need to use the => syntax for your grammar change. Also, the
isUnionAll=false state isn't necessary. This works fine:
{code}
// Parses a single SQL statement (expects an EOF after the select statement).
oneStatement returns [BindableStatement ret]
: ((SELECT s=hinted_select_node (UNION SELECT s2=hinted_select_node)?)
{$ret=s;}
| ns=non_select_node {$ret=ns;}
)
;
{code}
- Can you make sure you're not using tabs, as I'm seeing diffs that shouldn't
be there (which makes it harder to review):
{code}
public QueryCompiler(PhoenixStatement statement, SelectStatement select,
ColumnResolver resolver, List<? extends PDatum> targetColumns,
ParallelIteratorFactory parallelIteratorFactory, SequenceManager
sequenceManager, boolean projectTuples) throws SQLException {
- this.statement = statement;
- this.select = select;
- this.resolver = resolver;
- this.scan = new Scan();
- this.targetColumns = targetColumns;
- this.parallelIteratorFactory = parallelIteratorFactory;
- this.sequenceManager = sequenceManager;
- this.projectTuples = projectTuples;
- this.useSortMergeJoin =
select.getHint().hasHint(Hint.USE_SORT_MERGE_JOIN);
- this.noChildParentJoinOptimization =
select.getHint().hasHint(Hint.NO_CHILD_PARENT_JOIN_OPTIMIZATION);
- if
(statement.getConnection().getQueryServices().getLowestClusterHBaseVersion() >=
PhoenixDatabaseMetaData.ESSENTIAL_FAMILY_VERSION_THRESHOLD) {
- this.scan.setAttribute(LOAD_COLUMN_FAMILIES_ON_DEMAND_ATTR,
QueryConstants.TRUE);
- }
- if (select.getHint().hasHint(Hint.NO_CACHE)) {
- scan.setCacheBlocks(false);
- }
+ this.statement = statement;
+ this.select = select;
+ this.resolver = resolver;
+ this.scan = new Scan();
+ this.targetColumns = targetColumns;
+ this.parallelIteratorFactory = parallelIteratorFactory;
+ this.sequenceManager = sequenceManager;
+ this.projectTuples = projectTuples;
+ this.useSortMergeJoin =
select.getHint().hasHint(Hint.USE_SORT_MERGE_JOIN);
+ this.noChildParentJoinOptimization =
select.getHint().hasHint(Hint.NO_CHILD_PARENT_JOIN_OPTIMIZATION);
+ if
(statement.getConnection().getQueryServices().getLowestClusterHBaseVersion() >=
PhoenixDatabaseMetaData.ESSENTIAL_FAMILY_VERSION_THRESHOLD) {
+ this.scan.setAttribute(LOAD_COLUMN_FAMILIES_ON_DEMAND_ATTR,
QueryConstants.TRUE);
+ }
+ if (select.getHint().hasHint(Hint.NO_CACHE)) {
+ scan.setCacheBlocks(false);
+ }
+
+ scan.setCaching(statement.getFetchSize());
+ this.originalScan = ScanUtil.newScan(scan);
+ if (!select.getSelects().isEmpty() && !select.isUnion()) {
+ this.isUnionAll = true;
+ } else {
+ this.isUnionAll = false;
+ }
+ }
{code}
- Parse nodes need to stay immutable, so this is a no-no:
{code}
diff --git
a/phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java
b/phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java
index 71cabd6..52df3a8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java
@@ -17,6 +17,7 @@
*/
package org.apache.phoenix.parse;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -88,12 +89,14 @@ public class SelectStatement implements FilterableStatement
{
private final ParseNode where;
private final List<ParseNode> groupBy;
private final ParseNode having;
- private final List<OrderByNode> orderBy;
+ private List<OrderByNode> orderBy;
{code}
- We shouldn't need to expose UNION ALL up to PhoenixStatement. There still
should be only a single SELECT statement that may contain a list of other
SELECT statements in the case of UNION ALL.
{code}
@SuppressWarnings("unchecked")
@Override
public QueryPlan compilePlan(PhoenixStatement stmt, Sequence.ValueOp
seqAction) throws SQLException {
- SelectStatement select = SubselectRewriter.flatten(this,
stmt.getConnection());
- ColumnResolver resolver = FromCompiler.getResolverForQuery(select,
stmt.getConnection());
- select = StatementNormalizer.normalize(select, resolver);
- SelectStatement transformedSelect =
SubqueryRewriter.transform(select, resolver, stmt.getConnection());
- if (transformedSelect != select) {
- resolver = FromCompiler.getResolverForQuery(transformedSelect,
stmt.getConnection());
- select = StatementNormalizer.normalize(transformedSelect,
resolver);
- }
- QueryPlan plan = new QueryCompiler(stmt, select,
resolver).compile();
-
plan.getContext().getSequenceManager().validateSequences(seqAction);
- return plan;
+ List<SelectStatement> selects = new ArrayList<>();
+ if (this.getSelects() != null && !this.getSelects().isEmpty()) {
+ selects.addAll(this.getSelects());
+ }
+ SelectStatement select = SubselectRewriter.flatten(this,
stmt.getConnection());
+ ColumnResolver resolver =
FromCompiler.getResolverForQuery(select, stmt.getConnection());
+ select = StatementNormalizer.normalize(select, resolver);
+ SelectStatement transformedSelect =
SubqueryRewriter.transform(select, resolver, stmt.getConnection());
+ if (transformedSelect != select) {
+ resolver =
FromCompiler.getResolverForQuery(transformedSelect, stmt.getConnection());
+ select =
StatementNormalizer.normalize(transformedSelect, resolver);
+ }
+ if (!selects.isEmpty() && select.getSelects().isEmpty()) {
+ select.getSelects().addAll(selects);
+ }
+ QueryPlan plan = new QueryCompiler(stmt, select,
resolver).compile();
+
plan.getContext().getSequenceManager().validateSequences(seqAction);
+ return plan;
{code}
- Any test where you union together queries that are doing joins?
- How are you handling select statements with ORDER BY and LIMIT clauses? There
appears to be some logic that I can't seem to quite follow. It looks like union
should have higher precedence that order by and limit, and we should allow only
an order by and limit at the end (see Julian's comment above). It'd be good if
you confirmed this through the SQL spec. We'll likely need to make changes to
the grammar to reflect this.
> 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.patch, unionall-wipe.patch
>
>
> Select * from T1
> UNION ALL
> Select * from T2
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)