Program: 96135
Project: 96135
Buggy source:
private Expr transformForSingleFunction(Expr f,final List<TableUniqueName> stratifiedSampleTables){
  final Map<String,String> sub=source.tableSubstitution();
  ExprModifier v=new ExprModifier(){
    public Expr call(    Expr expr){
      if (expr instanceof FuncExpr) {
        FuncExpr f=(FuncExpr)expr;
        FuncExpr s=(FuncExpr)exprWithTableNamesSubstituted(expr,sub);
        double samplingProb=source.samplingProbabilityFor(f);
        if (f.getFuncName().equals(FuncExpr.FuncName.COUNT)) {
          Expr est=FuncExpr.sum(scaleForSampling(samplingProb,stratifiedSampleTables));
          return FuncExpr.round(est);
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.COUNT_DISTINCT)) {
          String dbname=vc.getDbms().getName();
          if (dbname.equals("String_Node_Str")) {
            return FuncExpr.round(BinaryOpExpr.from(new FuncExpr(FuncExpr.FuncName.IMPALA_APPROX_COUNT_DISTINCT,s.getUnaryExpr()),ConstantExpr.from(1.0 / samplingProb),"String_Node_Str"));
          }
 else {
            return FuncExpr.round(BinaryOpExpr.from(s,ConstantExpr.from(1.0 / samplingProb),"String_Node_Str"));
          }
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.SUM)) {
          Expr est=scaleForSampling(samplingProb,stratifiedSampleTables);
          est=FuncExpr.sum(BinaryOpExpr.from(s.getUnaryExpr(),est,"String_Node_Str"));
          return est;
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.AVG)) {
          Expr scale=scaleForSampling(samplingProb,stratifiedSampleTables);
          Expr sumEst=FuncExpr.sum(BinaryOpExpr.from(s.getUnaryExpr(),scale,"String_Node_Str"));
          Expr countEst=countNotNull(s.getUnaryExpr(),scale);
          return BinaryOpExpr.from(sumEst,countEst,"String_Node_Str");
        }
 else {
          return s;
        }
      }
 else {
        return expr;
      }
    }
  }
;
  return v.visit(f);
}

Fixed version (ground truth):
private Expr transformForSingleFunction(Expr f,final List<ColNameExpr> samplingProbCols){
  final Map<String,String> sub=source.tableSubstitution();
  ExprModifier v=new ExprModifier(){
    public Expr call(    Expr expr){
      if (expr instanceof FuncExpr) {
        FuncExpr f=(FuncExpr)expr;
        FuncExpr s=(FuncExpr)exprWithTableNamesSubstituted(expr,sub);
        double samplingProb=source.samplingProbabilityFor(f);
        if (f.getFuncName().equals(FuncExpr.FuncName.COUNT)) {
          Expr est=FuncExpr.sum(scaleForSampling(samplingProb,samplingProbCols));
          return FuncExpr.round(est);
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.COUNT_DISTINCT)) {
          String dbname=vc.getDbms().getName();
          if (dbname.equals("String_Node_Str")) {
            return FuncExpr.round(BinaryOpExpr.from(new FuncExpr(FuncExpr.FuncName.IMPALA_APPROX_COUNT_DISTINCT,s.getUnaryExpr()),ConstantExpr.from(1.0 / samplingProb),"String_Node_Str"));
          }
 else {
            return FuncExpr.round(BinaryOpExpr.from(s,ConstantExpr.from(1.0 / samplingProb),"String_Node_Str"));
          }
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.SUM)) {
          Expr est=scaleForSampling(samplingProb,samplingProbCols);
          est=FuncExpr.sum(BinaryOpExpr.from(s.getUnaryExpr(),est,"String_Node_Str"));
          return est;
        }
 else         if (f.getFuncName().equals(FuncExpr.FuncName.AVG)) {
          Expr scale=scaleForSampling(samplingProb,samplingProbCols);
          Expr sumEst=FuncExpr.sum(BinaryOpExpr.from(s.getUnaryExpr(),scale,"String_Node_Str"));
          Expr countEst=countNotNull(s.getUnaryExpr(),scale);
          return BinaryOpExpr.from(sumEst,countEst,"String_Node_Str");
        }
 else {
          return s;
        }
      }
 else {
        return expr;
      }
    }
  }
;
  return v.visit(f);
}