// Check if flatten fields are required by the successor.
LOSort sort = (LOSort)succ;
List<LogicalExpressionPlan> exps = sort.getSortColPlans();
for( int i = 0; i < exps.size(); i++ ) {
LogicalExpressionPlan exp = exps.get( i );
ProjectExpression proj = (ProjectExpression)exp.getOperators().next();
if( !uids.contains( proj.getFieldSchema().uid ) )
return false;
}
return true;
} else {
List<Operator> preds = currentPlan.getPredecessors( succ );
// We do not optimize if peer is ForEach with flatten. This is
// a simplification, may change in the future.
for( Operator op : preds ) {
if( op == foreach )
continue;
else if( op instanceof LOForEach &&
OptimizerUtils.hasFlatten( OptimizerUtils.findGenerate( (LOForEach)op ) ) )
return false;
}
if( ( (LogicalRelationalOperator)succ ).getSchema() == null )
return false;
if( succ instanceof LOCross ) {
return true;
} else {
LOJoin join = (LOJoin)succ;
for( int i = 0; i < preds.size(); i++ ) {
Operator op = preds.get( i );
if( op == foreach ) {
Collection<LogicalExpressionPlan> exprs = join.getJoinPlan( i );
for( LogicalExpressionPlan expr : exprs ) {
List<ProjectExpression> projs = getProjectExpressions( expr );
for( ProjectExpression proj : projs ) {
if( !uids.contains( proj.getFieldSchema().uid ) ) {
return false;
}
}
}
break;