Program: 25324
Project: 25324
Buggy source:
/** 
 * Builds the query.
 * @throws SemanticException the semantic exception
 * @throws HiveException the hive exception
 */
public void buildQuery() throws SemanticException, HiveException {
  analyzeInternal();
  replaceWithUnderlyingStorage(fromAST);
  fromTree=HQLParser.getString(fromAST);
  getFilterInJoinCond(fromAST);
  getAggregateColumns(selectAST);
  getJoinCond(fromAST);
  getAllFilters(whereAST);
  buildSubqueries(fromAST);
  String limit=getLimitClause(ast);
  if (whereTree == null || joinTree == null || allSubQueries.length() == 0) {
    LOG.info("String_Node_Str");
    constructQuery(selectTree,fromTree,whereTree,groupByTree,havingTree,orderByTree,limit,joinTree);
    return;
  }
 else {
    String factNameAndAlias=getFactNameAlias(fromAST).trim();
    factInLineQuery.append("String_Node_Str").append(factKeys);
    if (!aggColumn.isEmpty()) {
      factInLineQuery.append(aggColumn.toString().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
    }
    if (factInLineQuery.toString().substring(factInLineQuery.toString().length() - 1).equals("String_Node_Str")) {
      factInLineQuery.setLength(factInLineQuery.length() - 1);
    }
    factInLineQuery.append("String_Node_Str").append(factNameAndAlias);
    if (allSubQueries != null) {
      factInLineQuery.append("String_Node_Str");
      factInLineQuery.append(allSubQueries.toString().substring(0,allSubQueries.lastIndexOf("String_Node_Str")));
    }
    if (!aggColumn.isEmpty()) {
      factInLineQuery.append("String_Node_Str");
      factInLineQuery.append(factKeys.toString().substring(0,factKeys.toString().lastIndexOf("String_Node_Str")));
    }
    factInLineQuery.append("String_Node_Str");
  }
  for (  Map.Entry<String,String> entry : mapAggTabAlias.entrySet()) {
    selectTree=selectTree.replace(entry.getKey(),entry.getValue());
    if (orderByTree != null) {
      orderByTree=orderByTree.replace(entry.getKey(),entry.getValue());
    }
    if (havingTree != null) {
      havingTree=havingTree.replace(entry.getKey(),entry.getValue());
    }
  }
  constructQuery(selectTree,fromTree,whereTree,groupByTree,havingTree,orderByTree,limit,joinTree);
}

Fixed version (ground truth):
/** 
 * Builds the query.
 * @throws SemanticException the semantic exception
 * @throws HiveException the hive exception
 */
public void buildQuery() throws SemanticException, HiveException {
  analyzeInternal();
  replaceWithUnderlyingStorage(fromAST);
  fromTree=HQLParser.getString(fromAST);
  getFilterInJoinCond(fromAST);
  getAggregateColumns(selectAST);
  getJoinCond(fromAST);
  getAllFilters(whereAST);
  buildSubqueries(fromAST);
  String limit=getLimitClause(ast);
  if (whereTree == null || joinTree == null || allSubQueries.length() == 0 || aggColumn.isEmpty()) {
    LOG.info("String_Node_Str");
    constructQuery(selectTree,fromTree,whereTree,groupByTree,havingTree,orderByTree,limit,joinTree);
    return;
  }
 else {
    String factNameAndAlias=getFactNameAlias(fromAST).trim();
    factInLineQuery.append("String_Node_Str").append(factKeys);
    if (!aggColumn.isEmpty()) {
      factInLineQuery.append(aggColumn.toString().replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str"));
    }
    if (factInLineQuery.toString().substring(factInLineQuery.toString().length() - 1).equals("String_Node_Str")) {
      factInLineQuery.setLength(factInLineQuery.length() - 1);
    }
    factInLineQuery.append("String_Node_Str").append(factNameAndAlias);
    if (allSubQueries != null) {
      factInLineQuery.append("String_Node_Str");
      factInLineQuery.append(allSubQueries.toString().substring(0,allSubQueries.lastIndexOf("String_Node_Str")));
    }
    if (!aggColumn.isEmpty()) {
      factInLineQuery.append("String_Node_Str");
      factInLineQuery.append(factKeys.toString().substring(0,factKeys.toString().lastIndexOf("String_Node_Str")));
    }
    factInLineQuery.append("String_Node_Str");
  }
  for (  Map.Entry<String,String> entry : mapAggTabAlias.entrySet()) {
    selectTree=selectTree.replace(entry.getKey(),entry.getValue());
    if (orderByTree != null) {
      orderByTree=orderByTree.replace(entry.getKey(),entry.getValue());
    }
    if (havingTree != null) {
      havingTree=havingTree.replace(entry.getKey(),entry.getValue());
    }
  }
  if (selectTree.toLowerCase().matches("String_Node_Str")) {
    System.out.println(selectTree);
    selectTree=selectTree.replaceAll("String_Node_Str","String_Node_Str");
  }
  constructQuery(selectTree,fromTree,whereTree,groupByTree,havingTree,orderByTree,limit,joinTree);
}