}
@Override
public boolean check(List<LogicalOperator> nodes) throws OptimizerException {
try {
LOFilter filter = (LOFilter) getOperator(nodes);
List<LogicalOperator> predecessors = (mPlan.getPredecessors(filter) == null ? null
: new ArrayList<LogicalOperator>(mPlan
.getPredecessors(filter)));
// if there are no predecessors return false
if (predecessors == null) {
return false;
}
// if the filter has no predecessors or more than one predecessor
// return false
if (predecessors.size() == 0 || predecessors.size() > 1) {
return false;
}
LogicalOperator predecessor = predecessors.get(0);
// if the predecessor is one of LOLoad/LOStore/LOStream/LOLimit
// return false
if (predecessor instanceof LOLoad || predecessor instanceof LOStore
|| predecessor instanceof LOStream
|| predecessor instanceof LOLimit) {
return false;
}
// TODO
// for now filters cannot be combined
// remove this check when filters can be combined
if (predecessor instanceof LOFilter)
return false;
// TODO
// same rule as filters
if (predecessor instanceof LOSplitOutput) {
return false;
}
if (predecessor instanceof LOSplit) {
return false;
}
UDFFinder udfFinder = new UDFFinder(filter.getComparisonPlan());
udfFinder.visit();
// if the filter's inner plan contains any UDF then return false
if (udfFinder.foundAnyUDF()) {
return false;
}
CastFinder castFinder = new CastFinder(filter.getComparisonPlan());
castFinder.visit();
// if the filter's inner plan contains any casts then return false
if (castFinder.foundAnyCast()) {
return false;
}
List<RequiredFields> filterRequiredFields = filter
.getRequiredFields();
if (filterRequiredFields == null) {
return false;
}
RequiredFields requiredField = filterRequiredFields.get(0);