Program: 167097
Project: 167097
Buggy source:
/** 
 * Constructs a sql select statement from the SchemaTableTree call stack. The SchemaTableTree is not used as a tree. It is used only as as SchemaTable with a direction. first and last is needed to facilitate generating the from statement. If both first and last is true then the gremlin does not contain duplicate labels in its path and can be executed in one sql statement. If first and last is not equal then the sql will join across many select statements. The previous select needs to join onto the subsequent select. For this the from needs to select the appropriate field for the join.
 * @param distinctQueryStack
 * @param lastOfPrevious
 * @return
 */
private static String constructSinglePathSql(SqlgGraph sqlgGraph,LinkedList<SchemaTableTree> distinctQueryStack,SchemaTableTree lastOfPrevious,SchemaTableTree firstOfNextStack){
  String singlePathSql="String_Node_Str";
  SchemaTableTree firstSchemaTableTree=distinctQueryStack.getFirst();
  SchemaTable firstSchemaTable=firstSchemaTableTree.getSchemaTable();
  singlePathSql+=constructFromClause(sqlgGraph,distinctQueryStack,lastOfPrevious,firstOfNextStack);
  singlePathSql+="String_Node_Str";
  singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getSchema());
  singlePathSql+="String_Node_Str";
  singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getTable());
  SchemaTableTree previous=firstSchemaTableTree;
  boolean skipFirst=true;
  for (  SchemaTableTree schemaTableTree : distinctQueryStack) {
    if (skipFirst) {
      skipFirst=false;
      continue;
    }
    singlePathSql+=constructJoinBetweenSchemaTables(sqlgGraph,previous,schemaTableTree);
    previous=schemaTableTree;
  }
  if (lastOfPrevious == null && distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP) {
    singlePathSql+="String_Node_Str";
    singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema());
    singlePathSql+="String_Node_Str";
    singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable());
    singlePathSql+="String_Node_Str" + sqlgGraph.getSqlDialect().maybeWrapInQoutes(SchemaManager.ID);
    singlePathSql+="String_Node_Str";
  }
  boolean printedWhere=lastOfPrevious == null;
  for (  SchemaTableTree schemaTableTree : distinctQueryStack) {
    for (    HasContainer hasContainer : schemaTableTree.getHasContainers()) {
      if (!printedWhere) {
        printedWhere=true;
        singlePathSql+="String_Node_Str";
      }
 else {
        singlePathSql+="String_Node_Str";
      }
      singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTableTree.getSchemaTable().getSchema());
      singlePathSql+="String_Node_Str";
      singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTableTree.getSchemaTable().getTable());
      if (hasContainer.getKey().equals(T.id.getAccessor())) {
        singlePathSql+="String_Node_Str";
      }
 else {
        singlePathSql+="String_Node_Str" + sqlgGraph.getSqlDialect().maybeWrapInQoutes(hasContainer.getKey());
      }
      singlePathSql+="String_Node_Str";
    }
  }
  return singlePathSql;
}

Fixed version (ground truth):
/** 
 * Constructs a sql select statement from the SchemaTableTree call stack. The SchemaTableTree is not used as a tree. It is used only as as SchemaTable with a direction. first and last is needed to facilitate generating the from statement. If both first and last is true then the gremlin does not contain duplicate labels in its path and can be executed in one sql statement. If first and last is not equal then the sql will join across many select statements. The previous select needs to join onto the subsequent select. For this the from needs to select the appropriate field for the join.
 * @param distinctQueryStack
 * @param lastOfPrevious
 * @return
 */
private static String constructSinglePathSql(SqlgGraph sqlgGraph,LinkedList<SchemaTableTree> distinctQueryStack,SchemaTableTree lastOfPrevious,SchemaTableTree firstOfNextStack){
  String singlePathSql="String_Node_Str";
  SchemaTableTree firstSchemaTableTree=distinctQueryStack.getFirst();
  SchemaTable firstSchemaTable=firstSchemaTableTree.getSchemaTable();
  singlePathSql+=constructFromClause(sqlgGraph,distinctQueryStack,lastOfPrevious,firstOfNextStack);
  singlePathSql+="String_Node_Str";
  singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getSchema());
  singlePathSql+="String_Node_Str";
  singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getTable());
  SchemaTableTree previous=firstSchemaTableTree;
  boolean skipFirst=true;
  for (  SchemaTableTree schemaTableTree : distinctQueryStack) {
    if (skipFirst) {
      skipFirst=false;
      continue;
    }
    singlePathSql+=constructJoinBetweenSchemaTables(sqlgGraph,previous,schemaTableTree);
    previous=schemaTableTree;
  }
  if (lastOfPrevious == null && distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP) {
    singlePathSql+="String_Node_Str";
    singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema());
    singlePathSql+="String_Node_Str";
    singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable());
    singlePathSql+="String_Node_Str" + sqlgGraph.getSqlDialect().maybeWrapInQoutes(SchemaManager.ID);
    singlePathSql+="String_Node_Str";
  }
  boolean printedWhere=(lastOfPrevious == null) && (distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP);
  for (  SchemaTableTree schemaTableTree : distinctQueryStack) {
    for (    HasContainer hasContainer : schemaTableTree.getHasContainers()) {
      if (!printedWhere) {
        printedWhere=true;
        singlePathSql+="String_Node_Str";
      }
 else {
        singlePathSql+="String_Node_Str";
      }
      singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTableTree.getSchemaTable().getSchema());
      singlePathSql+="String_Node_Str";
      singlePathSql+=sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTableTree.getSchemaTable().getTable());
      if (hasContainer.getKey().equals(T.id.getAccessor())) {
        singlePathSql+="String_Node_Str";
      }
 else {
        singlePathSql+="String_Node_Str" + sqlgGraph.getSqlDialect().maybeWrapInQoutes(hasContainer.getKey());
      }
      singlePathSql+="String_Node_Str";
    }
  }
  return singlePathSql;
}