Github user ayingshu commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/39#discussion_r25928427
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java ---
@@ -147,21 +169,146 @@ public QueryCompiler(PhoenixStatement statement,
SelectStatement select, ColumnR
*/
public QueryPlan compile() throws SQLException{
SelectStatement select = this.select;
- List<Object> binds = statement.getParameters();
+ QueryPlan plan;
+ if (isUnionAll()) {
+ plan = compileUnionAll(select);
+ } else {
+ plan = compileSelect(select);
+ }
+ return plan;
+ }
+
+ public QueryPlan compileSelect(SelectStatement select) throws
SQLException{
+ // SelectStatement select = this.select;
+ List<Object> binds = statement.getParameters();
+ StatementContext context = new StatementContext(statement,
resolver, scan, sequenceManager);
+ ColumnResolver resolver;
+ if (isUnionAll()) {
+ resolver = FromCompiler.getResolverForQuery(select,
statement.getConnection());
+ context = new StatementContext(statement, resolver, new
Scan(), sequenceManager);
+ }
+ if (select.isJoin()) {
+ if (isUnionAll()) {
+ resolver =
FromCompiler.getResolverForQuery(select, statement.getConnection());
+ select = JoinCompiler.optimize(statement,
select, resolver);
+ }
+ else {
+ select = JoinCompiler.optimize(statement, select,
this.resolver);
+ }
+ if (this.select != select) {
+ ColumnResolver resolver1 =
FromCompiler.getResolverForQuery(select, statement.getConnection());
+ context = new StatementContext(statement,
resolver1, scan, sequenceManager);
+ }
+ JoinTable joinTable = JoinCompiler.compile(statement,
select, context.getResolver());
+ return compileJoinQuery(context, binds, joinTable,
false, false, null);
+ } else {
+ return compileSingleQuery(context, select, binds, false,
true);
+ }
+ }
+
+ private void checkForOrderByLimitInUnionAllSelect(SelectStatement
select) throws SQLException {
+ if (select.getOrderBy() != null && !select.getOrderBy().isEmpty())
{
+ throw new
SQLExceptionInfo.Builder(SQLExceptionCode.ORDER_BY_IN_UNIONALL_SELECT_NOT_SUPPORTED).setMessage(".").build().buildException();
+ }
+ if (select.getLimit() != null) {
+ throw new
SQLExceptionInfo.Builder(SQLExceptionCode.LIMIT_IN_UNIONALL_SELECT_NOT_SUPPORTED).setMessage(".").build().buildException();
+ }
+ }
+
+ private PTable createTempTableForUnionAllResultResolver(QueryPlan
plan) throws SQLException {
+ List<PColumn> projectedColumns = new ArrayList<PColumn>();
+ Long scn = statement.getConnection().getSCN();
+ List<PColumnFamily> families =
Collections.<PColumnFamily>emptyList(); // new ArrayList<PColumnFamily>();
+ PTable theTable = new
PTableImpl(statement.getConnection().getTenantId(), "unionAllSchema",
"unionAllTable", scn == null ? HConstants.LATEST_TIMESTAMP : scn, families);
+ PTable table = plan.getTableRef().getTable();
+ for (int i=0; i< plan.getProjector().getColumnCount(); i++) {
+ ColumnProjector colProj =
plan.getProjector().getColumnProjector(i);
+ Expression sourceExpression = colProj.getExpression();
+ PColumnImpl projectedColumn = new
PColumnImpl(PNameFactory.newName(colProj.getName().getBytes()),
table.getDefaultFamilyName(),
+ sourceExpression.getDataType(),
sourceExpression.getMaxLength(), sourceExpression.getScale(),
sourceExpression.isNullable(),
+ i, sourceExpression.getSortOrder(), 50, new byte[0],
true, sourceExpression.toString());
+ projectedColumns.add(projectedColumn);
+ }
+ PTable t = PTableImpl.makePTable(theTable, projectedColumns);
+ return t;
+ }
+
+ private QueryPlan buildTupleProjectPlan(QueryPlan plan) throws
SQLException {
--- End diff --
See above comments about buildTupleProjectPlan(QueryPlan plan).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---