use of org.apache.phoenix.expression.CorrelateVariableFieldAccessExpression in project phoenix by apache.
the class CorrelatePlanTest method testCorrelatePlan.
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);
}
}
}
Aggregations