Program: 50876
Project: 50876
Buggy source:
/** 
 * Generates the SQL statement to access the children of <code>member</code> in a parent-child hierarchy. For example, <blockquote> <pre>SELECT "employee_id" FROM "employee" WHERE "supervisor_id" = 5</pre> </blockquote> retrieves the children of the member <code>[Employee].[5]</code>. <p>See also   {@link SqlTupleReader#makeLevelMembersSql}.
 */
private Pair<String,List<SqlStatement.Type>> makeChildMemberSqlPC(RolapMember member){
  SqlQuery sqlQuery=SqlQuery.newQuery(dataSource,"String_Node_Str" + "String_Node_Str" + member);
  RolapLevel level=member.getLevel();
  Util.assertTrue(!level.isAll(),"String_Node_Str");
  Util.assertTrue(level.isUnique(),"String_Node_Str" + level + "String_Node_Str"+ "String_Node_Str");
  hierarchy.addToFrom(sqlQuery,level.getParentExp());
  String parentId=level.getParentExp().getExpression(sqlQuery);
  StringBuilder buf=new StringBuilder();
  sqlQuery.getDialect().quote(buf,member.getKey(),level.getDatatype());
  sqlQuery.addWhere(parentId,"String_Node_Str",buf.toString());
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String childId=level.getKeyExp().getExpression(sqlQuery);
  sqlQuery.addSelectGroupBy(childId,level.getInternalType());
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  sqlQuery.addOrderBy(orderBy,true,false,true);
  if (!orderBy.equals(childId)) {
    sqlQuery.addSelectGroupBy(orderBy,null);
  }
  RolapProperty[] properties=level.getProperties();
  for (  RolapProperty property : properties) {
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    String alias=sqlQuery.addSelect(s,null);
    if (!sqlQuery.getDialect().allowsSelectNotInGroupBy() || !property.dependsOnLevelValue()) {
      sqlQuery.addGroupBy(s,alias);
    }
  }
  return sqlQuery.toSqlAndTypes();
}

Fixed version (ground truth):
/** 
 * Generates the SQL statement to access the children of <code>member</code> in a parent-child hierarchy. For example, <blockquote> <pre>SELECT "employee_id" FROM "employee" WHERE "supervisor_id" = 5</pre> </blockquote> retrieves the children of the member <code>[Employee].[5]</code>. <p>See also   {@link SqlTupleReader#makeLevelMembersSql}.
 */
private Pair<String,List<SqlStatement.Type>> makeChildMemberSqlPC(RolapMember member){
  SqlQuery sqlQuery=SqlQuery.newQuery(dataSource,"String_Node_Str" + "String_Node_Str" + member);
  RolapLevel level=member.getLevel();
  Util.assertTrue(!level.isAll(),"String_Node_Str");
  Util.assertTrue(level.isUnique(),"String_Node_Str" + level + "String_Node_Str"+ "String_Node_Str");
  hierarchy.addToFrom(sqlQuery,level.getParentExp());
  String parentId=level.getParentExp().getExpression(sqlQuery);
  StringBuilder buf=new StringBuilder();
  sqlQuery.getDialect().quote(buf,member.getKey(),level.getDatatype());
  sqlQuery.addWhere(parentId,"String_Node_Str",buf.toString());
  hierarchy.addToFrom(sqlQuery,level.getKeyExp());
  String childId=level.getKeyExp().getExpression(sqlQuery);
  String idAlias=sqlQuery.addSelectGroupBy(childId,level.getInternalType());
  hierarchy.addToFrom(sqlQuery,level.getOrdinalExp());
  final String orderBy=level.getOrdinalExp().getExpression(sqlQuery);
  if (!orderBy.equals(childId)) {
    String orderAlias=sqlQuery.addSelectGroupBy(orderBy,null);
    sqlQuery.addOrderBy(orderBy,orderAlias,true,false,true,true);
  }
 else {
    sqlQuery.addOrderBy(childId,idAlias,true,false,true,true);
  }
  RolapProperty[] properties=level.getProperties();
  for (  RolapProperty property : properties) {
    final MondrianDef.Expression exp=property.getExp();
    hierarchy.addToFrom(sqlQuery,exp);
    final String s=exp.getExpression(sqlQuery);
    String alias=sqlQuery.addSelect(s,null);
    if (!sqlQuery.getDialect().allowsSelectNotInGroupBy() || !property.dependsOnLevelValue()) {
      sqlQuery.addGroupBy(s,alias);
    }
  }
  return sqlQuery.toSqlAndTypes();
}