insertFilter( prev, predecessor, filter );
return;
}
// Find the predecessor of join that contains all required uids.
LogicalExpressionPlan filterPlan = filter.getFilterPlan();
List<Operator> preds = currentPlan.getPredecessors( predecessor );
Map<Integer, Operator> inputs = findInputsToAddFilter( filterPlan, predecessor, preds );
LOFilter newFilter = null;
for( Entry<Integer, Operator> entry : inputs.entrySet() ) {
int inputIndex = entry.getKey();
Operator pred = entry.getValue();
// Find projection field offset
int columnOffset = 0;
if( predecessor instanceof LOJoin || predecessor instanceof LOCross ) {
for( int i = 0; i < inputIndex; i++ ) {
columnOffset += ( (LogicalRelationalOperator)preds.get( i ) ).getSchema().size();
}
}
// Reuse the filter for the first match. For others, need to make a copy of the filter
// and add it between input and predecessor.
newFilter = newFilter == null ? filter : new LOFilter( (LogicalPlan)currentPlan );
currentPlan.add( newFilter );
subPlan.add( newFilter );
subPlan.add( pred );
LogicalExpressionPlan fPlan = filterPlan.deepCopy();
List<Operator> sinks = fPlan.getSinks();
List<ProjectExpression> projExprs = new ArrayList<ProjectExpression>();
for( Operator sink : sinks ) {
if( sink instanceof ProjectExpression )
projExprs.add( (ProjectExpression)sink );
}
if( predecessor instanceof LOCogroup ) {
for( ProjectExpression projExpr : projExprs ) {
// Need to merge filter condition and cogroup by expression;
LogicalExpressionPlan plan = ((LOCogroup) predecessor).getExpressionPlans().get( inputIndex ).iterator().next();
LogicalExpressionPlan copy = plan.deepCopy();
LogicalExpression root = (LogicalExpression)copy.getSinks().get( 0 );
List<Operator> predecessors = fPlan.getPredecessors( projExpr );
if( predecessors == null || predecessors.size() == 0 ) {
fPlan.remove( projExpr );
fPlan.add( root );
} else {