Program: 9846
Project: 9846
Buggy source:
/** 
 * [    null,  h: int, i: string,   null ] [ a: int      null,      null, x: geo ] ?s = uri(concat("http://...", ?c1, ?c2)); ?s -> [c1: string, c2: int] with expr foo and restriction bar.
 */
public Mapping union(List<Mapping> rawMembers){
  List<Mapping> members=new ArrayList<Mapping>(rawMembers.size());
  for (  Mapping rawMember : rawMembers) {
    if (!rawMember.isEmpty()) {
      members.add(rawMember);
    }
  }
  if (members.isEmpty()) {
    Mapping result=createEmptyMapping();
    return result;
  }
  Generator aliasGen=Gensym.create("String_Node_Str");
  if (members.size() == 1) {
    logger.warn("String_Node_Str");
    Mapping result=members.get(0);
    return result;
  }
  Multimap<Var,RestrictedExpr> unionVarDefs=HashMultimap.create();
  List<Map<String,SqlExpr>> unionMemberProjections=new ArrayList<Map<String,SqlExpr>>();
  for (int i=0; i < members.size(); ++i) {
    Map<String,SqlExpr> tmp=new HashMap<String,SqlExpr>();
    unionMemberProjections.add(tmp);
  }
  Multimap<Var,Integer> varToMembers=HashMultimap.create();
  for (int i=0; i < members.size(); ++i) {
    Mapping mapping=members.get(i);
    for (    Var var : mapping.getVarDefinition().getMap().keySet()) {
      varToMembers.put(var,i);
    }
  }
  ExprCommonFactor factorizer=new ExprCommonFactor(aliasGen);
  Map<String,TypeToken> unionTypeMap=new HashMap<String,TypeToken>();
  for (  Entry<Var,Collection<Integer>> entry : varToMembers.asMap().entrySet()) {
    Var var=entry.getKey();
    Collection<Integer> memberIndexes=entry.getValue();
    Multimap<String,ArgExpr> cluster=HashMultimap.create();
    for (    int index : memberIndexes) {
      Mapping member=members.get(index);
      Collection<RestrictedExpr> exprsForVar=member.getVarDefinition().getDefinitions(var);
      for (      RestrictedExpr def : exprsForVar) {
        Map<String,TypeToken> typeMap=member.getSqlOp().getSchema().getTypeMap();
        Expr expr=def.getExpr();
        Expr datatypeNorm=exprNormalizer.normalize(expr,typeMap);
        String hash=datatypeNorm.toString();
        logger.debug("String_Node_Str" + expr + "String_Node_Str"+ hash+ "String_Node_Str");
        cluster.put(hash,new ArgExpr(expr,index));
      }
    }
    for (    Entry<String,Collection<ArgExpr>> clusterEntry : cluster.asMap().entrySet()) {
      Collection<ArgExpr> argExprs=clusterEntry.getValue();
      List<Expr> exprs=new ArrayList<Expr>();
      Map<Integer,Integer> exprToOp=new HashMap<Integer,Integer>();
      int i=0;
      for (      ArgExpr argExpr : argExprs) {
        Expr expr=argExpr.getExpr();
        exprs.add(expr);
        exprToOp.put(i,argExpr.getIndex());
        ++i;
      }
      List<Map<Var,Expr>> tmpPartialProjections=new ArrayList<Map<Var,Expr>>();
      Expr common=factorizer.transform(exprs,tmpPartialProjections);
      List<Map<String,SqlExpr>> partialProjections=new ArrayList<Map<String,SqlExpr>>();
      for (int j=0; j < tmpPartialProjections.size(); ++j) {
        int memberIndex=exprToOp.get(j);
        Mapping member=members.get(memberIndex);
        Map<String,TypeToken> typeMap=member.getSqlOp().getSchema().getTypeMap();
        Map<Var,Expr> tmpMap=tmpPartialProjections.get(j);
        Map<String,SqlExpr> map=new HashMap<String,SqlExpr>();
        for (        Entry<Var,Expr> e : tmpMap.entrySet()) {
          String columnName=e.getKey().getVarName();
          Expr expr=e.getValue();
          ExprSqlRewrite exprRewrite=sqlTranslator.translate(expr,null,typeMap);
          SqlExpr sqlExpr=SqlTranslatorImpl2.asSqlExpr(exprRewrite);
          map.put(columnName,sqlExpr);
          unionTypeMap.put(columnName,sqlExpr.getDatatype());
        }
        partialProjections.add(map);
      }
      unionVarDefs.put(var,new RestrictedExpr(common));
      for (int j=0; j < partialProjections.size(); ++j) {
        int originalIndex=exprToOp.get(j);
        Map<String,SqlExpr> projection=unionMemberProjections.get(originalIndex);
        Map<String,SqlExpr> partialProjection=partialProjections.get(j);
        for (        Entry<String,SqlExpr> ppEntry : partialProjection.entrySet()) {
          projection.put(ppEntry.getKey(),ppEntry.getValue());
        }
      }
    }
  }
  List<String> unionColumnOrder=new ArrayList<String>(unionTypeMap.keySet());
  List<SqlOp> extended=new ArrayList<SqlOp>();
  for (int i=0; i < members.size(); ++i) {
    Mapping member=members.get(i);
    Map<String,SqlExpr> unionMemberProjection=unionMemberProjections.get(i);
    Set<String> names=new HashSet<String>(unionMemberProjection.keySet());
    Set<String> unboundColumns=Sets.difference(unionTypeMap.keySet(),names);
    for (    String columnName : unboundColumns) {
      TypeToken datatype=unionTypeMap.get(columnName);
      S_Constant nullValue=new S_Constant(datatype);
      unionMemberProjection.put(columnName,nullValue);
    }
    Projection finalMemberProjection=new Projection(unionColumnOrder,unionMemberProjection);
    SqlOpExtend extend=SqlOpExtend.create(member.getSqlOp(),finalMemberProjection);
    SqlOpProject opProject=SqlOpProject.create(extend,unionColumnOrder);
    extended.add(opProject);
  }
  SqlOpUnionN newUnion=SqlOpUnionN.create(extended);
  VarDefinition varDefinition=new VarDefinition(unionVarDefs);
  Mapping result=new Mapping(varDefinition,newUnion);
  logger.info("String_Node_Str" + result);
  return result;
}

Fixed version (ground truth):
/** 
 * [    null,  h: int, i: string,   null ] [ a: int      null,      null, x: geo ] ?s = uri(concat("http://...", ?c1, ?c2)); ?s -> [c1: string, c2: int] with expr foo and restriction bar.
 */
public Mapping union(List<Mapping> rawMembers){
  List<Mapping> members=new ArrayList<Mapping>(rawMembers.size());
  for (  Mapping rawMember : rawMembers) {
    if (!rawMember.isEmpty()) {
      members.add(rawMember);
    }
  }
  if (members.isEmpty()) {
    Mapping result=createEmptyMapping();
    return result;
  }
  Set<String> columnNameBlacklist=new HashSet<String>();
  for (  Mapping member : members) {
    List<String> memberColumnNames=member.getSqlOp().getSchema().getColumnNames();
    columnNameBlacklist.addAll(memberColumnNames);
  }
  Generator aliasGen=GeneratorBlacklist.create("String_Node_Str",columnNameBlacklist);
  if (members.size() == 1) {
    logger.warn("String_Node_Str");
    Mapping result=members.get(0);
    return result;
  }
  Multimap<Var,RestrictedExpr> unionVarDefs=HashMultimap.create();
  List<Map<String,SqlExpr>> unionMemberProjections=new ArrayList<Map<String,SqlExpr>>();
  for (int i=0; i < members.size(); ++i) {
    Map<String,SqlExpr> tmp=new HashMap<String,SqlExpr>();
    unionMemberProjections.add(tmp);
  }
  Multimap<Var,Integer> varToMembers=HashMultimap.create();
  for (int i=0; i < members.size(); ++i) {
    Mapping mapping=members.get(i);
    for (    Var var : mapping.getVarDefinition().getMap().keySet()) {
      varToMembers.put(var,i);
    }
  }
  ExprCommonFactor factorizer=new ExprCommonFactor(aliasGen);
  Map<String,TypeToken> unionTypeMap=new HashMap<String,TypeToken>();
  for (  Entry<Var,Collection<Integer>> entry : varToMembers.asMap().entrySet()) {
    Var var=entry.getKey();
    Collection<Integer> memberIndexes=entry.getValue();
    Multimap<String,ArgExpr> cluster=HashMultimap.create();
    for (    int index : memberIndexes) {
      Mapping member=members.get(index);
      Collection<RestrictedExpr> exprsForVar=member.getVarDefinition().getDefinitions(var);
      for (      RestrictedExpr def : exprsForVar) {
        Map<String,TypeToken> typeMap=member.getSqlOp().getSchema().getTypeMap();
        Expr expr=def.getExpr();
        Expr datatypeNorm=exprNormalizer.normalize(expr,typeMap);
        String hash=datatypeNorm.toString();
        logger.debug("String_Node_Str" + expr + "String_Node_Str"+ hash+ "String_Node_Str");
        cluster.put(hash,new ArgExpr(expr,index));
      }
    }
    for (    Entry<String,Collection<ArgExpr>> clusterEntry : cluster.asMap().entrySet()) {
      Collection<ArgExpr> argExprs=clusterEntry.getValue();
      List<Expr> exprs=new ArrayList<Expr>();
      Map<Integer,Integer> exprToOp=new HashMap<Integer,Integer>();
      int i=0;
      for (      ArgExpr argExpr : argExprs) {
        Expr expr=argExpr.getExpr();
        exprs.add(expr);
        exprToOp.put(i,argExpr.getIndex());
        ++i;
      }
      List<Map<Var,Expr>> tmpPartialProjections=new ArrayList<Map<Var,Expr>>();
      Expr common=factorizer.transform(exprs,tmpPartialProjections);
      List<Map<String,SqlExpr>> partialProjections=new ArrayList<Map<String,SqlExpr>>();
      for (int j=0; j < tmpPartialProjections.size(); ++j) {
        int memberIndex=exprToOp.get(j);
        Mapping member=members.get(memberIndex);
        Map<String,TypeToken> typeMap=member.getSqlOp().getSchema().getTypeMap();
        Map<Var,Expr> tmpMap=tmpPartialProjections.get(j);
        Map<String,SqlExpr> map=new HashMap<String,SqlExpr>();
        for (        Entry<Var,Expr> e : tmpMap.entrySet()) {
          String columnName=e.getKey().getVarName();
          Expr expr=e.getValue();
          ExprSqlRewrite exprRewrite=sqlTranslator.translate(expr,null,typeMap);
          SqlExpr sqlExpr=SqlTranslatorImpl2.asSqlExpr(exprRewrite);
          map.put(columnName,sqlExpr);
          unionTypeMap.put(columnName,sqlExpr.getDatatype());
        }
        partialProjections.add(map);
      }
      unionVarDefs.put(var,new RestrictedExpr(common));
      for (int j=0; j < partialProjections.size(); ++j) {
        int originalIndex=exprToOp.get(j);
        Map<String,SqlExpr> projection=unionMemberProjections.get(originalIndex);
        Map<String,SqlExpr> partialProjection=partialProjections.get(j);
        for (        Entry<String,SqlExpr> ppEntry : partialProjection.entrySet()) {
          projection.put(ppEntry.getKey(),ppEntry.getValue());
        }
      }
    }
  }
  List<String> unionColumnOrder=new ArrayList<String>(unionTypeMap.keySet());
  List<SqlOp> extended=new ArrayList<SqlOp>();
  for (int i=0; i < members.size(); ++i) {
    Mapping member=members.get(i);
    Map<String,SqlExpr> unionMemberProjection=unionMemberProjections.get(i);
    Set<String> names=new HashSet<String>(unionMemberProjection.keySet());
    Set<String> unboundColumns=Sets.difference(unionTypeMap.keySet(),names);
    for (    String columnName : unboundColumns) {
      TypeToken datatype=unionTypeMap.get(columnName);
      S_Constant nullValue=new S_Constant(datatype);
      unionMemberProjection.put(columnName,nullValue);
    }
    Projection finalMemberProjection=new Projection(unionColumnOrder,unionMemberProjection);
    SqlOpExtend extend=SqlOpExtend.create(member.getSqlOp(),finalMemberProjection);
    SqlOpProject opProject=SqlOpProject.create(extend,unionColumnOrder);
    extended.add(opProject);
  }
  SqlOpUnionN newUnion=SqlOpUnionN.create(extended);
  VarDefinition varDefinition=new VarDefinition(unionVarDefs);
  Mapping result=new Mapping(varDefinition,newUnion);
  logger.info("String_Node_Str" + result);
  return result;
}