Program: 96126
Project: 96126
Buggy source:
/** 
 * Creates a stratified sample from a temp table, which is created by  {@link DbmsImpala#createTempTableWithGroupCountsAndRand createTempTableWithGroupCountsAndRand}. The created stratified sample includes a sampling probability for every tuple (in column name "verdict_sampling_prob") so that it can be used for computing the final answer. The sampling probability for each tuple is determined as: min( 1.0, (original table size) * (sampling ratio param) / (number of groups) / (size of the group) )
 * @param tempTableName
 * @param param
 * @throws VerdictException
 */
protected void createStratifiedSampleFromTempTable(TableUniqueName rnTempTable,TableUniqueName grpTempTable,SampleParam param) throws VerdictException {
  TableUniqueName originalTableName=param.originalTable;
  TableUniqueName sampleTempTable=generateTempTableName();
  String samplingProbColName=vc.samplingProbColName();
  VerdictLogger.debug(this,"String_Node_Str" + rnTempTable + "String_Node_Str"+ grpTempTable);
  ApproxRelation r=ApproxSingleRelation.from(vc,new SampleParam(param.originalTable,"String_Node_Str",null,new ArrayList<String>()));
  long originalTableSize=r.countValue();
  long groupCount=SingleRelation.from(vc,grpTempTable).countValue();
  String tmpCol1=Relation.genColumnAlias();
  String sql1=String.format("String_Node_Str",sampleTempTable) + String.format("String_Node_Str",columnNamesInString(originalTableName,"String_Node_Str")) + String.format("String_Node_Str",originalTableSize,param.samplingRatio,groupCount,tmpCol1,rnTempTable)+ "String_Node_Str"+ tmpCol1;
  VerdictLogger.debug(this,"String_Node_Str");
  VerdictLogger.debugPretty(this,Relation.prettyfySql(sql1),"String_Node_Str");
  executeUpdate(sql1);
  List<String> joinCond=new ArrayList<String>();
  for (  String g : param.columnNames) {
    joinCond.add(String.format("String_Node_Str",g,g));
  }
  ExactRelation grpRatioBase=SingleRelation.from(vc,sampleTempTable).groupby(param.columnNames).agg("String_Node_Str").join(SingleRelation.from(vc,grpTempTable),Joiner.on("String_Node_Str").join(joinCond));
  List<String> groupNamesWithTabName=new ArrayList<String>();
  for (  String col : param.columnNames) {
    groupNamesWithTabName.add(grpTempTable + "String_Node_Str" + col);
  }
  ExactRelation grpRatioRel=grpRatioBase.select(Joiner.on("String_Node_Str").join(groupNamesWithTabName) + String.format("String_Node_Str",samplingProbColName));
  ExactRelation stSampleRel=SingleRelation.from(vc,sampleTempTable).join(grpRatioRel,Joiner.on("String_Node_Str").join(joinCond)).select(columnNamesInString(originalTableName,sampleTempTable.tableName) + String.format("String_Node_Str",samplingProbColName));
  String sql2=String.format("String_Node_Str",param.sampleTableName()) + stSampleRel.toSql();
  VerdictLogger.debug(this,"String_Node_Str");
  VerdictLogger.debugPretty(this,Relation.prettyfySql(sql2),"String_Node_Str");
  executeUpdate(sql2);
  dropTable(sampleTempTable);
}

Fixed version (ground truth):
/** 
 * Creates a stratified sample from a temp table, which is created by  {@link DbmsImpala#createTempTableWithGroupCountsAndRand createTempTableWithGroupCountsAndRand}. The created stratified sample includes a sampling probability for every tuple (in column name "verdict_sampling_prob") so that it can be used for computing the final answer. The sampling probability for each tuple is determined as: min( 1.0, (original table size) * (sampling ratio param) / (number of groups) / (size of the group) )
 * @param tempTableName
 * @param param
 * @throws VerdictException
 */
protected void createStratifiedSampleFromTempTable(TableUniqueName rnTempTable,TableUniqueName grpTempTable,SampleParam param) throws VerdictException {
  TableUniqueName originalTableName=param.originalTable;
  TableUniqueName sampleTempTable=Relation.getTempTableName(vc);
  String samplingProbColName=vc.samplingProbColName();
  VerdictLogger.debug(this,"String_Node_Str" + rnTempTable + "String_Node_Str"+ grpTempTable);
  ApproxRelation r=ApproxSingleRelation.from(vc,new SampleParam(param.originalTable,"String_Node_Str",null,new ArrayList<String>()));
  long originalTableSize=r.countValue();
  long groupCount=SingleRelation.from(vc,grpTempTable).countValue();
  String tmpCol1=Relation.genColumnAlias();
  String sql1=String.format("String_Node_Str",sampleTempTable) + String.format("String_Node_Str",columnNamesInString(originalTableName,"String_Node_Str")) + String.format("String_Node_Str",originalTableSize,param.samplingRatio,groupCount,tmpCol1,rnTempTable)+ "String_Node_Str"+ tmpCol1;
  VerdictLogger.debug(this,"String_Node_Str");
  VerdictLogger.debugPretty(this,Relation.prettyfySql(sql1),"String_Node_Str");
  executeUpdate(sql1);
  List<String> joinCond=new ArrayList<String>();
  for (  String g : param.columnNames) {
    joinCond.add(String.format("String_Node_Str",g,g));
  }
  ExactRelation grpRatioBase=SingleRelation.from(vc,sampleTempTable).groupby(param.columnNames).agg("String_Node_Str").join(SingleRelation.from(vc,grpTempTable),Joiner.on("String_Node_Str").join(joinCond));
  List<String> groupNamesWithTabName=new ArrayList<String>();
  for (  String col : param.columnNames) {
    groupNamesWithTabName.add(grpTempTable + "String_Node_Str" + col);
  }
  ExactRelation grpRatioRel=grpRatioBase.select(Joiner.on("String_Node_Str").join(groupNamesWithTabName) + String.format("String_Node_Str",samplingProbColName));
  ExactRelation stSampleRel=SingleRelation.from(vc,sampleTempTable).join(grpRatioRel,Joiner.on("String_Node_Str").join(joinCond)).select(columnNamesInString(originalTableName,sampleTempTable.tableName) + String.format("String_Node_Str",samplingProbColName));
  String sql2=String.format("String_Node_Str",param.sampleTableName()) + stSampleRel.toSql();
  VerdictLogger.debug(this,"String_Node_Str");
  VerdictLogger.debugPretty(this,Relation.prettyfySql(sql2),"String_Node_Str");
  executeUpdate(sql2);
  dropTable(sampleTempTable);
}