ScanProjector.serializeProjectorIntoScan(context.getScan(), JoinCompiler.getScanProjector(initialProjectedTable));
context.setCurrentTable(join.getMainTable());
context.setResolver(JoinCompiler.getColumnResolver(projectedTable));
join.projectColumns(context.getScan(), join.getMainTable());
BasicQueryPlan plan = compileSingleQuery(context, JoinCompiler.getSubqueryWithoutJoin(select, join), binds);
Expression postJoinFilterExpression = join.compilePostFilterExpression(context);
HashJoinInfo joinInfo = new HashJoinInfo(projectedTable.getTable(), joinIds, joinExpressions, joinTypes, starJoinVector, tables, fieldPositions, postJoinFilterExpression);
return new HashJoinPlan(plan, joinInfo, hashExpressions, joinPlans);
}
JoinTable lastJoinTable = joinTables.get(joinTables.size() - 1);
JoinType type = lastJoinTable.getType();
if (type == JoinType.Full)
throw new SQLFeatureNotSupportedException("Full joins not supported.");
if (type == JoinType.Right || type == JoinType.Inner) {
SelectStatement lhs = JoinCompiler.getSubQueryWithoutLastJoin(select, join);
SelectStatement rhs = JoinCompiler.getSubqueryForLastJoinTable(select, join);
JoinSpec lhsJoin = JoinCompiler.getSubJoinSpecWithoutPostFilters(join);
Scan subScan = ScanUtil.newScan(scanCopy);
StatementContext lhsCtx = new StatementContext(statement, context.getResolver(), binds, subScan);
QueryPlan lhsPlan = compileJoinQuery(lhsCtx, lhs, binds, lhsJoin, true);
ColumnResolver lhsResolver = lhsCtx.getResolver();
PTableWrapper lhsProjTable = ((JoinedTableColumnResolver) (lhsResolver)).getPTableWrapper();
ProjectedPTableWrapper rhsProjTable = join.createProjectedTable(lastJoinTable.getTable(), !asSubquery);
ColumnResolver rhsResolver = JoinCompiler.getColumnResolver(rhsProjTable);
ImmutableBytesPtr[] joinIds = new ImmutableBytesPtr[] {new ImmutableBytesPtr(emptyByteArray)};
Pair<List<Expression>, List<Expression>> joinConditions = lastJoinTable.compileJoinConditions(context, lhsResolver, rhsResolver);
List<Expression> joinExpressions = joinConditions.getSecond();
List<Expression> hashExpressions = joinConditions.getFirst();
int fieldPosition = rhsProjTable.getTable().getColumns().size() - rhsProjTable.getTable().getPKColumns().size();
PTableWrapper projectedTable = JoinCompiler.mergeProjectedTables(rhsProjTable, lhsProjTable, type == JoinType.Inner);
ScanProjector.serializeProjectorIntoScan(context.getScan(), JoinCompiler.getScanProjector(rhsProjTable));
context.setCurrentTable(lastJoinTable.getTable());
context.setResolver(JoinCompiler.getColumnResolver(projectedTable));
join.projectColumns(context.getScan(), lastJoinTable.getTable());
BasicQueryPlan rhsPlan = compileSingleQuery(context, rhs, binds);
Expression postJoinFilterExpression = join.compilePostFilterExpression(context);
HashJoinInfo joinInfo = new HashJoinInfo(projectedTable.getTable(), joinIds, new List[] {joinExpressions}, new JoinType[] {type == JoinType.Inner ? type : JoinType.Left}, new boolean[] {true}, new PTable[] {lhsProjTable.getTable()}, new int[] {fieldPosition}, postJoinFilterExpression);
return new HashJoinPlan(rhsPlan, joinInfo, new List[] {hashExpressions}, new QueryPlan[] {lhsPlan});
}
// Do not support queries like "A right join B left join C" with hash-joins.