public CorrelatePlan(QueryPlan lhs, QueryPlan rhs, String variableId, JoinType joinType, boolean isSingleValueOnly, RuntimeContext runtimeContext, PTable joinedTable, PTable lhsTable, PTable rhsTable, int rhsFieldPosition) { super(lhs); if (joinType != JoinType.Inner && joinType != JoinType.Left && joinType != JoinType.Semi && joinType != JoinType.Anti) throw new IllegalArgumentException("Unsupported join type '" + joinType + "' by CorrelatePlan"); this.rhs = rhs; this.variableId = variableId; this.joinType = joinType; this.isSingleValueOnly = isSingleValueOnly; this.runtimeContext = runtimeContext; this.joinedSchema = buildSchema(joinedTable); this.lhsSchema = buildSchema(lhsTable); this.rhsSchema = buildSchema(rhsTable); this.rhsFieldPosition = rhsFieldPosition; }
@Override public Double visit(CorrelatePlan plan) { Double lhsRows = plan.getDelegate().accept(this); if (lhsRows != null) { return lhsRows * SEMI_OR_ANTI_JOIN_FACTOR; } return null; }
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException { ProjectedValueTuple t; if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = getContext().getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return t; } };
private void testCorrelatePlan(Object[][] leftRelation, Object[][] rightRelation, int leftCorrelColumn, int rightCorrelColumn, JoinType type, Object[][] expectedResult, Integer offset) throws SQLException { TableRef leftTable = createProjectedTableFromLiterals(leftRelation[0]); TableRef rightTable = createProjectedTableFromLiterals(rightRelation[0]); String varName = "$cor0"; RuntimeContext runtimeContext = new RuntimeContextImpl(); runtimeContext.defineCorrelateVariable(varName, leftTable); QueryPlan leftPlan = newLiteralResultIterationPlan(leftRelation, offset); QueryPlan rightPlan = newLiteralResultIterationPlan(rightRelation, offset); Expression columnExpr = new ColumnRef(rightTable, rightCorrelColumn).newColumnExpression(); Expression fieldAccess = new CorrelateVariableFieldAccessExpression(runtimeContext, varName, new ColumnRef(leftTable, leftCorrelColumn).newColumnExpression()); Expression filter = ComparisonExpression.create(CompareOp.EQUAL, Arrays.asList(columnExpr, fieldAccess), CONTEXT.getTempPtr(), false); rightPlan = new ClientScanPlan(CONTEXT, SelectStatement.SELECT_ONE, rightTable, RowProjector.EMPTY_PROJECTOR, null, null, filter, OrderBy.EMPTY_ORDER_BY, rightPlan); PTable joinedTable = JoinCompiler.joinProjectedTables(leftTable.getTable(), rightTable.getTable(), type); CorrelatePlan correlatePlan = new CorrelatePlan(leftPlan, rightPlan, varName, type, false, runtimeContext, joinedTable, leftTable.getTable(), rightTable.getTable(), leftTable.getTable().getColumns().size()); ResultIterator iter = correlatePlan.iterator(); ImmutableBytesWritable ptr = new ImmutableBytesWritable(); for (Object[] row : expectedResult) { Tuple next = iter.next(); assertNotNull(next); for (int i = 0; i < row.length; i++) { PColumn column = joinedTable.getColumns().get(i); boolean eval = new ProjectedColumnExpression(column, joinedTable, column.getName().getString()).evaluate(next, ptr); Object o = eval ? column.getDataType().toObject(ptr) : null; assertEquals(row[i], o); } } }
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException { ProjectedValueTuple t; if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = getContext().getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return t; } };
@Override public Double visit(CorrelatePlan plan) { return plan.getDelegate().accept(this); }
private ProjectedValueTuple convertLhs(Tuple lhs) throws IOException { ProjectedValueTuple t; if (lhs instanceof ProjectedValueTuple) { t = (ProjectedValueTuple) lhs; } else { ImmutableBytesWritable ptr = getContext().getTempPtr(); TupleProjector.decodeProjectedValue(lhs, ptr); lhsBitSet.clear(); lhsBitSet.or(ptr); int bitSetLen = lhsBitSet.getEstimatedLength(); t = new ProjectedValueTuple(lhs, lhs.getValue(0).getTimestamp(), ptr.get(), ptr.getOffset(), ptr.getLength(), bitSetLen); } return t; } };
public CorrelatePlan(QueryPlan lhs, QueryPlan rhs, String variableId, JoinType joinType, boolean isSingleValueOnly, RuntimeContext runtimeContext, PTable joinedTable, PTable lhsTable, PTable rhsTable, int rhsFieldPosition) { super(lhs); if (joinType != JoinType.Inner && joinType != JoinType.Left && joinType != JoinType.Semi && joinType != JoinType.Anti) throw new IllegalArgumentException("Unsupported join type '" + joinType + "' by CorrelatePlan"); this.rhs = rhs; this.variableId = variableId; this.joinType = joinType; this.isSingleValueOnly = isSingleValueOnly; this.runtimeContext = runtimeContext; this.joinedSchema = buildSchema(joinedTable); this.lhsSchema = buildSchema(lhsTable); this.rhsSchema = buildSchema(rhsTable); this.rhsFieldPosition = rhsFieldPosition; }
@Override public Double visit(CorrelatePlan plan) { Double lhsRows = plan.getDelegate().accept(this); if (lhsRows != null) { return lhsRows * SEMI_OR_ANTI_JOIN_FACTOR; } return null; }
public CorrelatePlan(QueryPlan lhs, QueryPlan rhs, String variableId, JoinType joinType, boolean isSingleValueOnly, RuntimeContext runtimeContext, PTable joinedTable, PTable lhsTable, PTable rhsTable, int rhsFieldPosition) { super(lhs); if (joinType != JoinType.Inner && joinType != JoinType.Left && joinType != JoinType.Semi && joinType != JoinType.Anti) throw new IllegalArgumentException("Unsupported join type '" + joinType + "' by CorrelatePlan"); this.rhs = rhs; this.variableId = variableId; this.joinType = joinType; this.isSingleValueOnly = isSingleValueOnly; this.runtimeContext = runtimeContext; this.joinedSchema = buildSchema(joinedTable); this.lhsSchema = buildSchema(lhsTable); this.rhsSchema = buildSchema(rhsTable); this.rhsFieldPosition = rhsFieldPosition; }
@Override public Double visit(CorrelatePlan plan) { Double lhsRows = plan.getDelegate().accept(this); if (lhsRows != null) { return lhsRows * SEMI_OR_ANTI_JOIN_FACTOR; } return null; }
@Override public Double visit(CorrelatePlan plan) { return plan.getDelegate().accept(this); }
@Override public Double visit(CorrelatePlan plan) { return plan.getDelegate().accept(this); }