Program: 25279
Project: 25279
Buggy source:
private void resolveFactStoragePartitions(CubeQueryContext cubeql) throws SemanticException {
  Iterator<CandidateFact> i=cubeql.getCandidateFactTables().iterator();
  while (i.hasNext()) {
    CandidateFact cfact=i.next();
    List<FactPartition> answeringParts=new ArrayList<FactPartition>();
    HashMap<String,SkipStorageCause> skipStorageCauses=new HashMap<String,SkipStorageCause>();
    Map<UpdatePeriod,RangesPartitionTimeline> missingPartitionRanges=Maps.newHashMap();
    boolean noPartsForRange=false;
    for (    TimeRange range : cubeql.getTimeRanges()) {
      Set<FactPartition> rangeParts=getPartitions(cfact.fact,range,skipStorageCauses,missingPartitionRanges);
      if (rangeParts == null || rangeParts.isEmpty()) {
        LOG.info("String_Node_Str" + range);
        noPartsForRange=true;
        continue;
      }
      cfact.incrementPartsQueried(rangeParts.size());
      answeringParts.addAll(rangeParts);
      cfact.getPartsQueried().addAll(rangeParts);
      cfact.getRangeToWhereClause().put(range,rangeWriter.getTimeRangeWhereClause(cubeql,cubeql.getAliasForTabName(cubeql.getCube().getName()),rangeParts));
    }
    Set<String> nonExistingParts=Sets.newHashSet();
    if (!missingPartitionRanges.isEmpty()) {
      for (      UpdatePeriod period : missingPartitionRanges.keySet()) {
        for (        TimePartition.TimePartitionRange range : missingPartitionRanges.get(period).getRanges()) {
          nonExistingParts.add(range.toString());
        }
      }
    }
    if (!nonExistingParts.isEmpty()) {
      addNonExistingParts(cfact.fact.getName(),nonExistingParts);
    }
    if (cfact.getNumQueriedParts() == 0 || (failOnPartialData && (noPartsForRange || !nonExistingParts.isEmpty()))) {
      LOG.info("String_Node_Str" + cfact.fact + "String_Node_Str"+ "String_Node_Str"+ cubeql.getTimeRanges());
      if (!nonExistingParts.isEmpty()) {
        cubeql.addFactPruningMsgs(cfact.fact,CandidateTablePruneCause.missingPartitions(nonExistingParts));
      }
 else       if (!skipStorageCauses.isEmpty()) {
        CandidateTablePruneCause cause=CandidateTablePruneCause.noCandidateStorages(skipStorageCauses);
        cubeql.addFactPruningMsgs(cfact.fact,cause);
      }
 else {
        CandidateTablePruneCause cause=new CandidateTablePruneCause(CandidateTablePruneCode.NO_FACT_UPDATE_PERIODS_FOR_GIVEN_RANGE);
        cubeql.addFactPruningMsgs(cfact.fact,cause);
      }
      i.remove();
      continue;
    }
    Map<String,Set<FactPartition>> minimalStorageTables=new LinkedHashMap<String,Set<FactPartition>>();
    boolean enabledMultiTableSelect=StorageUtil.getMinimalAnsweringTables(answeringParts,minimalStorageTables);
    if (minimalStorageTables.isEmpty()) {
      LOG.info("String_Node_Str" + cfact + "String_Node_Str"+ "String_Node_Str");
      cubeql.addFactPruningMsgs(cfact.fact,CandidateTablePruneCause.noCandidateStorages(skipStorageCauses));
      i.remove();
      continue;
    }
    Set<String> storageTables=new LinkedHashSet<String>();
    storageTables.addAll(minimalStorageTables.keySet());
    cfact.setStorageTables(storageTables);
    if (cfact.isEnabledMultiTableSelect()) {
      cfact.setEnabledMultiTableSelect(enabledMultiTableSelect);
    }
    LOG.info("String_Node_Str" + cfact + "String_Node_Str"+ answeringParts+ "String_Node_Str"+ storageTables);
  }
}

Fixed version (ground truth):
private void resolveFactStoragePartitions(CubeQueryContext cubeql) throws SemanticException {
  Iterator<CandidateFact> i=cubeql.getCandidateFactTables().iterator();
  while (i.hasNext()) {
    CandidateFact cfact=i.next();
    List<FactPartition> answeringParts=new ArrayList<FactPartition>();
    HashMap<String,SkipStorageCause> skipStorageCauses=new HashMap<String,SkipStorageCause>();
    Map<UpdatePeriod,RangesPartitionTimeline> missingPartitionRanges=Maps.newHashMap();
    boolean noPartsForRange=false;
    for (    TimeRange range : cubeql.getTimeRanges()) {
      Set<FactPartition> rangeParts=getPartitions(cfact.fact,range,skipStorageCauses,missingPartitionRanges);
      if (rangeParts == null || rangeParts.isEmpty()) {
        LOG.info("String_Node_Str" + range);
        noPartsForRange=true;
        continue;
      }
      cfact.incrementPartsQueried(rangeParts.size());
      answeringParts.addAll(rangeParts);
      cfact.getPartsQueried().addAll(rangeParts);
      cfact.getRangeToWhereClause().put(range,rangeWriter.getTimeRangeWhereClause(cubeql,cubeql.getAliasForTabName(cubeql.getCube().getName()),rangeParts));
    }
    Set<String> nonExistingParts=Sets.newHashSet();
    if (!missingPartitionRanges.isEmpty()) {
      for (      UpdatePeriod period : missingPartitionRanges.keySet()) {
        for (        TimePartition.TimePartitionRange range : missingPartitionRanges.get(period).getRanges()) {
          nonExistingParts.add(range.toString());
        }
      }
    }
    if (!nonExistingParts.isEmpty()) {
      addNonExistingParts(cfact.fact.getName(),nonExistingParts);
    }
    if (cfact.getNumQueriedParts() == 0 || (failOnPartialData && (noPartsForRange || !nonExistingParts.isEmpty()))) {
      LOG.info("String_Node_Str" + cfact.fact + "String_Node_Str"+ "String_Node_Str"+ cubeql.getTimeRanges());
      if (failOnPartialData && !nonExistingParts.isEmpty()) {
        cubeql.addFactPruningMsgs(cfact.fact,CandidateTablePruneCause.missingPartitions(nonExistingParts));
      }
 else       if (!skipStorageCauses.isEmpty()) {
        CandidateTablePruneCause cause=CandidateTablePruneCause.noCandidateStorages(skipStorageCauses);
        cubeql.addFactPruningMsgs(cfact.fact,cause);
      }
 else {
        CandidateTablePruneCause cause=new CandidateTablePruneCause(CandidateTablePruneCode.NO_FACT_UPDATE_PERIODS_FOR_GIVEN_RANGE);
        cubeql.addFactPruningMsgs(cfact.fact,cause);
      }
      i.remove();
      continue;
    }
    Map<String,Set<FactPartition>> minimalStorageTables=new LinkedHashMap<String,Set<FactPartition>>();
    boolean enabledMultiTableSelect=StorageUtil.getMinimalAnsweringTables(answeringParts,minimalStorageTables);
    if (minimalStorageTables.isEmpty()) {
      LOG.info("String_Node_Str" + cfact + "String_Node_Str"+ "String_Node_Str");
      cubeql.addFactPruningMsgs(cfact.fact,CandidateTablePruneCause.noCandidateStorages(skipStorageCauses));
      i.remove();
      continue;
    }
    Set<String> storageTables=new LinkedHashSet<String>();
    storageTables.addAll(minimalStorageTables.keySet());
    cfact.setStorageTables(storageTables);
    if (cfact.isEnabledMultiTableSelect()) {
      cfact.setEnabledMultiTableSelect(enabledMultiTableSelect);
    }
    LOG.info("String_Node_Str" + cfact + "String_Node_Str"+ answeringParts+ "String_Node_Str"+ storageTables);
  }
}