Program: 66396
Project: 66396
Buggy source:
/** 
 * @param query
 * @param dataSet
 * @return
 * @throws DataException
 */
public static Strategy getQueryExecutionStrategy(DataEngineSession session,IQueryDefinition query,IBaseDataSetDesign dataSet) throws DataException {
  if (session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE)   return Strategy.Complex;
  if (query.getGroups() != null && query.getGroups().size() > 0) {
    if (session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE)     return Strategy.Complex;
    for (    IGroupDefinition group : (List<IGroupDefinition>)query.getGroups()) {
      if (group.getFilters().isEmpty() && group.getSorts().isEmpty() && !query.getQueryExecutionHints().doSortBeforeGrouping())       continue;
      return Strategy.Complex;
    }
  }
  if (query.getFilters() != null && query.getFilters().size() > 0) {
    return Strategy.Complex;
  }
  if (query.getSorts() != null && query.getSorts().size() > 0)   return Strategy.Complex;
  if (query.getSubqueries() != null && query.getSubqueries().size() > 0)   return Strategy.Complex;
  if (!query.usesDetails()) {
    return Strategy.Complex;
  }
  boolean hasAggregation=false;
  if (query.getBindings() != null) {
    Iterator bindingIt=query.getBindings().values().iterator();
    while (bindingIt.hasNext()) {
      IBinding binding=(IBinding)bindingIt.next();
      if (binding.getAggrFunction() != null) {
        hasAggregation=true;
        IAggrFunction aggr=AggregationManager.getInstance().getAggregation(binding.getAggrFunction());
        if (aggr != null && aggr.getNumberOfPasses() > 1) {
          return Strategy.Complex;
        }
        List exprs=new ArrayList();
        exprs.addAll(binding.getArguments());
        if (binding.getExpression() != null)         exprs.add(binding.getExpression());
        for (int i=0; i < exprs.size(); i++) {
          Object expr=exprs.get(i);
          if (!(expr instanceof IScriptExpression)) {
            return Strategy.Complex;
          }
          IScriptExpression scriptExpr=(IScriptExpression)expr;
          try {
            List<IColumnBinding> columnExprs=ExpressionUtil.extractColumnExpressions(scriptExpr.getText());
            for (            IColumnBinding temp : columnExprs) {
              Object obj=query.getBindings().get(temp.getResultSetColumnName());
              if (obj instanceof IBinding) {
                IBinding bindingObj=(IBinding)obj;
                if (bindingObj.getAggrFunction() != null)                 return Strategy.Complex;
                IBaseExpression baseExpr=((IBinding)obj).getExpression();
                if (baseExpr instanceof IScriptExpression) {
                  String cb=ExpressionUtil.getColumnName(((IScriptExpression)baseExpr).getText());
                  if (ScriptEvalUtil.compare(bindingObj.getBindingName(),cb) != 0)                   return Strategy.Complex;
                }
              }
            }
          }
 catch (          BirtException e) {
            return Strategy.Complex;
          }
        }
      }
      if (ExpressionCompilerUtil.hasAggregationInExpr(binding.getExpression())) {
        return Strategy.Complex;
      }
    }
  }
  if (dataSet != null) {
    if (dataSet.getFilters() != null) {
      if (FilterUtil.hasMutipassFilters(dataSet.getFilters())) {
        return Strategy.Complex;
      }
    }
    if (dataSet.needDistinctValue())     return Strategy.Complex;
    if (dataSet.getComputedColumns() != null) {
      List computedColumns=dataSet.getComputedColumns();
      for (int i=0; i < computedColumns.size(); i++) {
        IComputedColumn computedColumn=(IComputedColumn)computedColumns.get(i);
        if (computedColumn.getAggregateFunction() != null)         return Strategy.Complex;
        if (computedColumn.getExpression() instanceof IScriptExpression) {
          if (ExpressionUtil.hasAggregation(((IScriptExpression)computedColumn.getExpression()).getText())) {
            return Strategy.Complex;
          }
        }
      }
    }
  }
  return hasAggregation ? Strategy.SimpleLookingFoward : Strategy.SimpleNoLookingFoward;
}

Fixed version (ground truth):
/** 
 * @param query
 * @param dataSet
 * @return
 * @throws DataException
 */
public static Strategy getQueryExecutionStrategy(DataEngineSession session,IQueryDefinition query,IBaseDataSetDesign dataSet) throws DataException {
  if (session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE)   return Strategy.Complex;
  if (query.getGroups() != null && query.getGroups().size() > 0) {
    if (session.getEngineContext().getMode() == DataEngineContext.MODE_UPDATE)     return Strategy.Complex;
    for (    IGroupDefinition group : (List<IGroupDefinition>)query.getGroups()) {
      if (group.getFilters().isEmpty() && group.getSorts().isEmpty() && !query.getQueryExecutionHints().doSortBeforeGrouping())       continue;
      SortingOptimizer opt=new SortingOptimizer(dataSet,query);
      if (opt.acceptGroupSorting()) {
        continue;
      }
      return Strategy.Complex;
    }
  }
  if (query.getFilters() != null && query.getFilters().size() > 0) {
    return Strategy.Complex;
  }
  if (query.getSorts() != null && query.getSorts().size() > 0)   return Strategy.Complex;
  if (query.getSubqueries() != null && query.getSubqueries().size() > 0)   return Strategy.Complex;
  if (!query.usesDetails()) {
    return Strategy.Complex;
  }
  boolean hasAggregation=false;
  if (query.getBindings() != null) {
    Iterator bindingIt=query.getBindings().values().iterator();
    while (bindingIt.hasNext()) {
      IBinding binding=(IBinding)bindingIt.next();
      if (binding.getAggrFunction() != null) {
        hasAggregation=true;
        IAggrFunction aggr=AggregationManager.getInstance().getAggregation(binding.getAggrFunction());
        if (aggr != null && aggr.getNumberOfPasses() > 1) {
          return Strategy.Complex;
        }
        List exprs=new ArrayList();
        exprs.addAll(binding.getArguments());
        if (binding.getExpression() != null)         exprs.add(binding.getExpression());
        for (int i=0; i < exprs.size(); i++) {
          Object expr=exprs.get(i);
          if (!(expr instanceof IScriptExpression)) {
            return Strategy.Complex;
          }
          IScriptExpression scriptExpr=(IScriptExpression)expr;
          try {
            List<IColumnBinding> columnExprs=ExpressionUtil.extractColumnExpressions(scriptExpr.getText());
            for (            IColumnBinding temp : columnExprs) {
              Object obj=query.getBindings().get(temp.getResultSetColumnName());
              if (obj instanceof IBinding) {
                IBinding bindingObj=(IBinding)obj;
                if (bindingObj.getAggrFunction() != null)                 return Strategy.Complex;
                IBaseExpression baseExpr=((IBinding)obj).getExpression();
                if (baseExpr instanceof IScriptExpression) {
                  String cb=ExpressionUtil.getColumnName(((IScriptExpression)baseExpr).getText());
                  if (ScriptEvalUtil.compare(bindingObj.getBindingName(),cb) != 0)                   return Strategy.Complex;
                }
              }
            }
          }
 catch (          BirtException e) {
            return Strategy.Complex;
          }
        }
      }
      if (ExpressionCompilerUtil.hasAggregationInExpr(binding.getExpression())) {
        return Strategy.Complex;
      }
    }
  }
  if (dataSet != null) {
    if (dataSet.getFilters() != null) {
      if (FilterUtil.hasMutipassFilters(dataSet.getFilters())) {
        return Strategy.Complex;
      }
    }
    if (dataSet.needDistinctValue())     return Strategy.Complex;
    if (dataSet.getComputedColumns() != null) {
      List computedColumns=dataSet.getComputedColumns();
      for (int i=0; i < computedColumns.size(); i++) {
        IComputedColumn computedColumn=(IComputedColumn)computedColumns.get(i);
        if (computedColumn.getAggregateFunction() != null)         return Strategy.Complex;
        if (computedColumn.getExpression() instanceof IScriptExpression) {
          if (ExpressionUtil.hasAggregation(((IScriptExpression)computedColumn.getExpression()).getText())) {
            return Strategy.Complex;
          }
        }
      }
    }
  }
  return hasAggregation ? Strategy.SimpleLookingFoward : Strategy.SimpleNoLookingFoward;
}