nus-yam/ex-repair huggingface dataset:
Program: 13261
Project: 13261
Buggy source:
@Nullable public void decodeIdent(@Nullable String ident) throws IOException {
  if (ident == null) {
    return;
  }
  byte[] inputBytes=new Base32(true).decode(ident.toUpperCase(Locale.ROOT));
  BytesStreamInput in=new BytesStreamInput(inputBytes,true);
  int size=in.readVInt();
  for (int i=0; i < size; i++) {
    BytesRef value=(BytesRef)DataType.STRING.streamer().readFrom(in);
    if (value == null) {
      values.add(null);
    }
 else {
      values.add(value.utf8ToString());
    }
  }
}

Fixed version (ground truth):
@Nullable public void decodeIdent(@Nullable String ident) throws IOException {
  if (ident == null) {
    return;
  }
  byte[] inputBytes=BASE32.decode(ident.toUpperCase(Locale.ROOT));
  BytesStreamInput in=new BytesStreamInput(inputBytes,true);
  int size=in.readVInt();
  for (int i=0; i < size; i++) {
    BytesRef value=(BytesRef)DataType.STRING.streamer().readFrom(in);
    if (value == null) {
      values.add(null);
    }
 else {
      values.add(value.utf8ToString());
    }
  }
}
Program: 13262
Project: 13262
Buggy source:
public LineCollectorExpression<?> getImplementation(ReferenceInfo info){
  LineCollectorExpression<?> expression=implementations.get(info.ident().columnIdent().name());
  if (expression != null) {
    return expression;
  }
  return new ColumnExtractingLineExpression(info.ident().columnIdent());
}

Fixed version (ground truth):
public LineCollectorExpression<?> getImplementation(ReferenceInfo info){
  ExpressionBuilder builder=expressionBuilder.get(info.ident().columnIdent().name());
  if (builder != null) {
    return builder.create();
  }
  return new ColumnExtractingLineExpression(info.ident().columnIdent());
}
Program: 13263
Project: 13263
Buggy source:
@Before public void initTestData() throws Exception {
}

Fixed version (ground truth):
@Before public void initTestData() throws Exception {
  setup.groupBySetup();
  execute("String_Node_Str");
  BlobIndices blobIndices=cluster().getInstance(BlobIndices.class);
  blobIndices.createBlobTable("String_Node_Str",new NumberOfReplicas(1),5);
  ensureGreen();
}
Program: 13264
Project: 13264
Buggy source:
private ListenableFuture<Object[][]> getUpstreamResult(int numRows){
  SettableFuture<Object[][]> upstreamResult=SettableFuture.create();
  Object[][] resultRows=new Object[numRows][];
  for (int i=0; i < numRows; i++) {
    double d=(double)numRows * i;
    MinimumAggregation.MinimumAggState<Double> aggState=minAggFunction.newState();
    aggState.setValue(d);
    resultRows[i]=new Object[]{d % 4,aggState};
  }
  upstreamResult.set(resultRows);
  return upstreamResult;
}

Fixed version (ground truth):
private ListenableFuture<Object[][]> getUpstreamResult(int numRows){
  Object[][] resultRows=new Object[numRows][];
  for (int i=0; i < numRows; i++) {
    double d=(double)numRows * i;
    MinimumAggregation.MinimumAggState<Double> aggState=minAggFunction.newState();
    aggState.setValue(d);
    resultRows[i]=new Object[]{d % 4,aggState};
  }
  return Futures.immediateFuture(resultRows);
}
Program: 13265
Project: 13265
Buggy source:
@Test public void testLocalMerge() throws Exception {
  TopNProjection topNProjection=new TopNProjection(3,TopN.NO_OFFSET,Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)),new boolean[]{true,true});
  topNProjection.outputs(Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)));
  MergeNode mergeNode=new MergeNode("String_Node_Str",2);
  mergeNode.projections(Arrays.asList(groupProjection,topNProjection));
  List<ListenableFuture<Object[][]>> upstreamResults=new ArrayList<>(1);
  for (int i=1; i < 14; i++) {
    upstreamResults.add(getUpstreamResult(i));
  }
  ThreadPool threadPool=new ThreadPool();
  LocalMergeTask localMergeTask=new LocalMergeTask(threadPool,symbolVisitor,mergeNode);
  localMergeTask.upstreamResult(upstreamResults);
  localMergeTask.start();
  List<ListenableFuture<Object[][]>> localMergeResults=localMergeTask.result();
  assertThat(localMergeResults.size(),is(1));
  Object[][] result=localMergeResults.get(0).get();
  assertThat(result.length,is(3));
  assertThat(result[0].length,is(2));
  assertThat((Double)result[0][0],is(3.0));
  assertThat((Double)result[0][1],is(3.0));
  assertThat((Double)result[1][0],is(2.0));
  assertThat((Double)result[1][1],is(2.0));
  assertThat((Double)result[2][0],is(1.0));
  assertThat((Double)result[2][1],is(5.0));
}

Fixed version (ground truth):
@Test public void testLocalMerge() throws Exception {
  for (int run=0; run < 100; run++) {
    TopNProjection topNProjection=new TopNProjection(3,TopN.NO_OFFSET,Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)),new boolean[]{true,true});
    topNProjection.outputs(Arrays.<Symbol>asList(new InputColumn(0),new InputColumn(1)));
    MergeNode mergeNode=new MergeNode("String_Node_Str",2);
    mergeNode.projections(Arrays.<Projection>asList(groupProjection,topNProjection));
    List<ListenableFuture<Object[][]>> upstreamResults=new ArrayList<>(1);
    for (int i=1; i < 14; i++) {
      upstreamResults.add(getUpstreamResult(i));
    }
    ThreadPool threadPool=new ThreadPool();
    LocalMergeTask localMergeTask=new LocalMergeTask(threadPool,symbolVisitor,mergeNode);
    localMergeTask.upstreamResult(upstreamResults);
    localMergeTask.start();
    ListenableFuture<List<Object[][]>> allAsList=Futures.allAsList(localMergeTask.result());
    Object[][] result=allAsList.get().get(0);
    assertThat(result.length,is(3));
    assertThat(result[0].length,is(2));
    assertThat((Double)result[0][0],is(3.0));
    assertThat((Double)result[0][1],is(3.0));
    assertThat((Double)result[1][0],is(2.0));
    assertThat((Double)result[1][1],is(2.0));
    assertThat((Double)result[2][0],is(1.0));
    assertThat((Double)result[2][1],is(5.0));
  }
}
Program: 13266
Project: 13266
Buggy source:
public static Reference createReference(String tableName,String columnName,DataType dataType){
  return new Reference(new ReferenceInfo(new ReferenceIdent(new TableIdent(null,tableName),columnName),RowGranularity.DOC,dataType));
}

Fixed version (ground truth):
public static Reference createReference(String tableName,ColumnIdent columnIdent,DataType dataType){
  return new Reference(new ReferenceInfo(new ReferenceIdent(new TableIdent(null,tableName),columnIdent),RowGranularity.DOC,dataType));
}
Program: 13267
Project: 13267
Buggy source:
private FieldExtractor[] buildExtractors(String[] fields,DataType[] types){
  FieldExtractor[] extractors=new FieldExtractor[fields.length];
  int i=0;
  for (  final String field : fields) {
    if (field.equals("String_Node_Str")) {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          return response.getVersion();
        }
      }
;
    }
 else     if (field.equals("String_Node_Str")) {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          return new BytesRef(response.getId());
        }
      }
;
    }
 else {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          return response.getField(field).getValue();
        }
      }
;
    }
    i++;
  }
  return extractors;
}

Fixed version (ground truth):
private FieldExtractor[] buildExtractors(String[] fields,DataType[] types){
  FieldExtractor[] extractors=new FieldExtractor[fields.length];
  int i=0;
  for (  final String field : fields) {
    if (field.equals("String_Node_Str")) {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          return response.getVersion();
        }
      }
;
    }
 else     if (field.equals("String_Node_Str")) {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          return new BytesRef(response.getId());
        }
      }
;
    }
 else {
      extractors[i]=new FieldExtractor(){
        @Override public Object extract(        GetResponse response){
          GetField getField=response.getField(field);
          if (getField != null) {
            return getField.getValue();
          }
          return null;
        }
      }
;
    }
    i++;
  }
  return extractors;
}
Program: 13268
Project: 13268
Buggy source:
@Override public boolean iterate(CountAggState state,Input... args){
  state.value++;
  return true;
}

Fixed version (ground truth):
@Override public boolean iterate(CountAggState state,Input... args){
  if (args.length > 0 && args[0].value() != null) {
    state.value++;
  }
  return true;
}
Program: 13269
Project: 13269
Buggy source:
/** 
 * get bucket number by doing modulo hashcode of first row-element
 */
@Override protected int getBucket(@Nullable Object[] row){
  if (row == null || row.length == 0) {
    return 0;
  }
 else {
    return row[0].hashCode() % this.numBuckets;
  }
}

Fixed version (ground truth):
/** 
 * get bucket number by doing modulo hashcode of first row-element
 */
@Override protected int getBucket(@Nullable Object[] row){
  if (row == null || row.length == 0) {
    return 0;
  }
 else {
    return Math.abs(row[0].hashCode()) % this.numBuckets;
  }
}
Program: 13271
Project: 13271
Buggy source:
protected static String expressionToRegex(String patternString,char escapeChar,boolean shouldEscape){
  StringBuilder regex=new StringBuilder(patternString.length() * 2);
  regex.append('^');
  boolean escaped=false;
  for (  char currentChar : patternString.toCharArray()) {
    if (shouldEscape && !escaped && currentChar == escapeChar) {
      escaped=true;
    }
 else {
switch (currentChar) {
case '%':
        if (escaped) {
          regex.append("String_Node_Str");
        }
 else {
          regex.append("String_Node_Str");
        }
      escaped=false;
    break;
case '_':
  if (escaped) {
    regex.append("String_Node_Str");
  }
 else {
    regex.append('.');
  }
escaped=false;
break;
default :
switch (currentChar) {
case '\\':
case '^':
case '$':
case '.':
case '*':
regex.append('\\');
}
regex.append(currentChar);
escaped=false;
}
}
}
regex.append('$');
return regex.toString();
}

Fixed version (ground truth):
protected static String expressionToRegex(String patternString,char escapeChar,boolean shouldEscape){
  StringBuilder regex=new StringBuilder(patternString.length() * 2);
  regex.append('^');
  boolean escaped=false;
  for (  char currentChar : patternString.toCharArray()) {
    if (shouldEscape && !escaped && currentChar == escapeChar) {
      escaped=true;
    }
 else {
switch (currentChar) {
case '%':
        if (escaped) {
          regex.append("String_Node_Str");
        }
 else {
          regex.append("String_Node_Str");
        }
      escaped=false;
    break;
case '_':
  if (escaped) {
    regex.append("String_Node_Str");
  }
 else {
    regex.append('.');
  }
escaped=false;
break;
default :
switch (currentChar) {
case '\\':
case '^':
case '$':
case '.':
case '*':
case '[':
case ']':
case '(':
case ')':
regex.append('\\');
}
regex.append(currentChar);
escaped=false;
}
}
}
regex.append('$');
return regex.toString();
}
Program: 13272
Project: 13272
Buggy source:
@Override public Symbol normalizeSymbol(Function symbol){
  assert(symbol != null);
  assert(symbol.arguments().size() == 2);
  StringLiteral expression=(StringLiteral)symbol.arguments().get(0);
  StringLiteral pattern=(StringLiteral)symbol.arguments().get(1);
  return new BooleanLiteral(matches(expression,pattern));
}

Fixed version (ground truth):
@Override public Symbol normalizeSymbol(Function symbol){
  assert(symbol != null);
  assert(symbol.arguments().size() == 2);
  if (!symbol.arguments().get(0).symbolType().isLiteral()) {
    return symbol;
  }
  StringLiteral expression=(StringLiteral)symbol.arguments().get(0);
  StringLiteral pattern=(StringLiteral)symbol.arguments().get(1);
  return new BooleanLiteral(matches(expression,pattern));
}
Program: 13273
Project: 13273
Buggy source:
@Override public void convert(Function function,Context context) throws IOException {
  Preconditions.checkNotNull(function);
  Preconditions.checkArgument(function.arguments().size() == 2);
  Symbol left=function.arguments().get(0);
  Symbol right=function.arguments().get(1);
  Preconditions.checkArgument(left.symbolType() == SymbolType.REFERENCE);
  Preconditions.checkArgument(right.symbolType() == SymbolType.SET_LITERAL);
  String refName=((Reference)left).info().ident().columnIdent().fqn();
  SetLiteral setLiteral=(SetLiteral)right;
  context.builder.startObject("String_Node_Str").field(refName);
  context.builder.startArray();
  for (  Object o : setLiteral.value()) {
    context.builder.value(o);
  }
  context.builder.endArray().endObject();
}

Fixed version (ground truth):
@Override public void convert(Function function,Context context) throws IOException {
  assert(function != null);
  assert(function.arguments().size() == 2);
  Symbol left=function.arguments().get(0);
  Symbol right=function.arguments().get(1);
  String refName=((Reference)left).info().ident().columnIdent().fqn();
  SetLiteral setLiteral=(SetLiteral)right;
  boolean convertBytesRef=false;
  if (setLiteral.valueType() == DataType.STRING_SET) {
    convertBytesRef=true;
  }
  context.builder.startObject("String_Node_Str").field(refName);
  context.builder.startArray();
  for (  Object o : setLiteral.value()) {
    if (convertBytesRef) {
      context.builder.value(((BytesRef)o).utf8ToString());
    }
 else {
      context.builder.value(o);
    }
  }
  context.builder.endArray().endObject();
}
Program: 13274
Project: 13274
Buggy source:
@Override protected Symbol visitFunctionCall(FunctionCall node,Analysis context){
  List<Symbol> arguments=new ArrayList<>(node.getArguments().size());
  List<DataType> argumentTypes=new ArrayList<>(node.getArguments().size());
  for (  Expression expression : node.getArguments()) {
    ValueSymbol vs=(ValueSymbol)expression.accept(this,context);
    arguments.add(vs);
    argumentTypes.add(vs.valueType());
  }
  FunctionInfo functionInfo=null;
  if (node.isDistinct()) {
    if (argumentTypes.size() > 1) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    FunctionIdent innerIdent=new FunctionIdent(CollectSetAggregation.NAME,argumentTypes);
    FunctionInfo innerInfo=context.getFunctionInfo(innerIdent);
    Function innerFunction=new Function(innerInfo,arguments);
    String nodeName="String_Node_Str" + node.getName().toString();
    List<Symbol> outerArguments=new ArrayList<>();
    List<DataType> outerArgumentTypes=new ArrayList<>();
    outerArguments.add(innerFunction);
    outerArgumentTypes.add(DataType.SET_TYPES.get(argumentTypes.get(0).ordinal()));
    FunctionIdent ident=new FunctionIdent(nodeName,outerArgumentTypes);
    functionInfo=context.getFunctionInfo(ident);
    arguments=outerArguments;
  }
 else {
    FunctionIdent ident=new FunctionIdent(node.getName().toString(),argumentTypes);
    functionInfo=context.getFunctionInfo(ident);
  }
  return context.allocateFunction(functionInfo,arguments);
}

Fixed version (ground truth):
@Override protected Symbol visitFunctionCall(FunctionCall node,Analysis context){
  List<Symbol> arguments=new ArrayList<>(node.getArguments().size());
  List<DataType> argumentTypes=new ArrayList<>(node.getArguments().size());
  for (  Expression expression : node.getArguments()) {
    ValueSymbol vs=(ValueSymbol)expression.accept(this,context);
    arguments.add(vs);
    argumentTypes.add(vs.valueType());
  }
  FunctionInfo functionInfo=null;
  if (node.isDistinct()) {
    if (argumentTypes.size() > 1) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    FunctionIdent innerIdent=new FunctionIdent(CollectSetAggregation.NAME,argumentTypes);
    FunctionInfo innerInfo=context.getFunctionInfo(innerIdent);
    Function innerFunction=context.allocateFunction(innerInfo,arguments);
    String nodeName="String_Node_Str" + node.getName().toString();
    ImmutableList<Symbol> outerArguments=ImmutableList.<Symbol>of(innerFunction);
    ImmutableList<DataType> outerArgumentTypes=ImmutableList.of(DataType.SET_TYPES.get(argumentTypes.get(0).ordinal()));
    FunctionIdent ident=new FunctionIdent(nodeName,outerArgumentTypes);
    functionInfo=context.getFunctionInfo(ident);
    arguments=outerArguments;
  }
 else {
    FunctionIdent ident=new FunctionIdent(node.getName().toString(),argumentTypes);
    functionInfo=context.getFunctionInfo(ident);
  }
  return context.allocateFunction(functionInfo,arguments);
}
Program: 13275
Project: 13275
Buggy source:
private Function getFunctionByName(String functionName,Collection c){
  Function function=null;
  Iterator<Function> it=c.iterator();
  while (function == null && it.hasNext()) {
    Function f=it.next();
    if (f.info().ident().name().equals(functionName)) {
      function=f;
    }
  }
  return function;
}

Fixed version (ground truth):
private static Function getFunctionByName(String functionName,Collection c){
  Function function=null;
  Iterator<Function> it=c.iterator();
  while (function == null && it.hasNext()) {
    Function f=it.next();
    if (f.info().ident().name().equals(functionName)) {
      function=f;
    }
  }
  return function;
}
Program: 13276
Project: 13276
Buggy source:
@Test public void testAggregationDistinct(){
  Statement statement=SqlParser.createStatement("String_Node_Str");
  Analysis analysis=analyzer.analyze(statement);
  assertFalse(analysis.hasAggregates());
  Function collectionCount=getFunctionByName(CollectionCountFunction.NAME,analysis.functions());
  assertNotNull(collectionCount);
  List<Symbol> args=collectionCount.arguments();
  assertEquals(1,args.size());
  Function innerFunction=(Function)args.get(0);
  assertTrue(innerFunction.info().isAggregate());
  assertEquals(innerFunction.info().ident().name(),CollectSetAggregation.NAME);
  List<Symbol> innerArguments=innerFunction.arguments();
  assertThat(innerArguments.get(0),IsInstanceOf.instanceOf(StringLiteral.class));
  assertThat(((StringLiteral)innerArguments.get(0)).value(),is("String_Node_Str"));
}

Fixed version (ground truth):
@Test public void testAggregationDistinct(){
  Analysis analysis=analyze("String_Node_Str");
  assertTrue(analysis.hasAggregates());
  assertEquals(2,analysis.functions().size());
  Function collectionCount=getFunctionByName(CollectionCountFunction.NAME,analysis.functions());
  Function collectSet=getFunctionByName(CollectSetAggregation.NAME,analysis.functions());
  assertNotNull(collectionCount);
  assertNotNull(collectSet);
  List<Symbol> args=collectionCount.arguments();
  assertEquals(1,args.size());
  Function innerFunction=(Function)args.get(0);
  assertTrue(innerFunction.info().isAggregate());
  assertEquals(innerFunction.info().ident().name(),CollectSetAggregation.NAME);
  List<Symbol> innerArguments=innerFunction.arguments();
  assertThat(innerArguments.get(0),IsInstanceOf.instanceOf(Reference.class));
  assertThat(((Reference)innerArguments.get(0)).info(),IsInstanceOf.instanceOf(ReferenceInfo.class));
  ReferenceInfo refInfo=((Reference)innerArguments.get(0)).info();
  assertThat(refInfo.ident().columnIdent().name(),is("String_Node_Str"));
  assertThat(refInfo.ident().columnIdent().path().get(0),is("String_Node_Str"));
  assertSame(collectSet,innerFunction);
}
Program: 13278
Project: 13278
Buggy source:
@Before public void prepare(){
  Injector injector=new ModulesBuilder().add(new TestModule()).createInjector();
  Injector shard0Injector=injector.createChildInjector(new TestShardModule(0));
  Injector shard1Injector=injector.createChildInjector(new TestShardModule(1));
  when(indexService.shardInjectorSafe(0)).thenReturn(shard0Injector);
  when(indexService.shardInjectorSafe(1)).thenReturn(shard1Injector);
  when(indexService.shardSafe(0)).thenReturn(shard0Injector.getInstance(IndexShard.class));
  when(indexService.shardSafe(1)).thenReturn(shard1Injector.getInstance(IndexShard.class));
  operation=injector.getInstance(DistributingCollectOperation.class);
}

Fixed version (ground truth):
@Before public void prepare(){
  Injector injector=new ModulesBuilder().add(new OperatorModule()).add(new TestModule()).createInjector();
  Injector shard0Injector=injector.createChildInjector(new TestShardModule(0));
  Injector shard1Injector=injector.createChildInjector(new TestShardModule(1));
  when(indexService.shardInjectorSafe(0)).thenReturn(shard0Injector);
  when(indexService.shardInjectorSafe(1)).thenReturn(shard1Injector);
  when(indexService.shardSafe(0)).thenReturn(shard0Injector.getInstance(IndexShard.class));
  when(indexService.shardSafe(1)).thenReturn(shard1Injector.getInstance(IndexShard.class));
  operation=injector.getInstance(DistributingCollectOperation.class);
}
Program: 13279
Project: 13279
Buggy source:
@Override public void writeTo(StreamOutput out) throws IOException {
  super.writeTo(out);
  out.writeLong(contextId.getMostSignificantBits());
  out.writeLong(contextId.getLeastSignificantBits());
  out.writeBoolean(failed);
  if (!failed) {
    groupByResult.writeTo(out);
  }
}

Fixed version (ground truth):
@Override public void writeTo(StreamOutput out) throws IOException {
  super.writeTo(out);
  try {
    out.writeLong(contextId.getMostSignificantBits());
    out.writeLong(contextId.getLeastSignificantBits());
    out.writeBoolean(failed);
    if (!failed) {
      groupByResult.writeTo(out);
    }
  }
 catch (  Exception e) {
    logger.error(e.getMessage(),e);
    throw e;
  }
}
Program: 13280
Project: 13280
Buggy source:
@Override public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  try {
    contextId=new UUID(in.readLong(),in.readLong());
    status=jobStatusContext.get(contextId);
    failed=in.readBoolean();
    if (!failed) {
      if (status == null) {
        Streams.copy(in,memoryOutputStream);
      }
 else {
        groupByResult=SQLGroupByResult.readSQLGroupByResult(status.parsedStatement,cacheRecycler,in);
      }
    }
  }
 catch (  Exception e) {
    logger.error(e.getMessage(),e);
    throw new IOException(e);
  }
}

Fixed version (ground truth):
@Override public void readFrom(StreamInput in) throws IOException {
  super.readFrom(in);
  try {
    contextId=new UUID(in.readLong(),in.readLong());
    status=jobStatusContext.get(contextId);
    failed=in.readBoolean();
    if (!failed) {
      if (status == null) {
        Streams.copy(in,memoryOutputStream);
      }
 else {
        groupByResult=SQLGroupByResult.readSQLGroupByResult(status.parsedStatement,cacheRecycler,in);
      }
    }
  }
 catch (  Exception e) {
    logger.error(e.getMessage(),e);
    throw e;
  }
}
Program: 13281
Project: 13281
Buggy source:
public synchronized void merge(SQLGroupByResult groupByResult){
  if (reducedRows == null) {
    reducedRows=groupByResult.rows();
  }
 else {
    reducedRows.merge(groupByResult.rows());
  }
  countDown();
}

Fixed version (ground truth):
public void merge(SQLGroupByResult groupByResult){
synchronized (lock) {
    if (reducedRows == null) {
      reducedRows=groupByResult.rows();
    }
 else {
      reducedRows.merge(groupByResult.rows());
    }
  }
  countDown();
}
Program: 13282
Project: 13282
Buggy source:
public void push(final SQLMapperResultRequest request) throws IOException {
  if (request.groupByResult != null) {
    request.status.merge(request.groupByResult);
    return;
  }
synchronized (lock) {
    SQLReduceJobStatus status=reduceJobs.get(request.contextId);
    if (status == null) {
      List<BytesReference> bytesStreamOutputs=unreadStreams.get(request.contextId);
      if (bytesStreamOutputs == null) {
        bytesStreamOutputs=new ArrayList<>();
        unreadStreams.put(request.contextId,bytesStreamOutputs);
      }
      bytesStreamOutputs.add(request.memoryOutputStream.bytes());
    }
 else {
      mergeFromBytesReference(request.memoryOutputStream.bytes(),status);
    }
  }
}

Fixed version (ground truth):
public void push(final SQLMapperResultRequest request) throws IOException {
  if (request.groupByResult != null) {
    request.status.merge(request.groupByResult);
    return;
  }
synchronized (lock) {
    SQLReduceJobStatus status=reduceJobs.get(request.contextId);
    if (request.failed) {
      status.countDown();
      return;
    }
    if (status == null) {
      List<BytesReference> bytesStreamOutputs=unreadStreams.get(request.contextId);
      if (bytesStreamOutputs == null) {
        bytesStreamOutputs=new ArrayList<>();
        unreadStreams.put(request.contextId,bytesStreamOutputs);
      }
      bytesStreamOutputs.add(request.memoryOutputStream.bytes());
    }
 else {
      mergeFromBytesReference(request.memoryOutputStream.bytes(),status);
    }
  }
}
Program: 13283
Project: 13283
Buggy source:
private void countDown(){
  if (reduceJobStatusContext != null) {
    if (shardsToProcess.decrementAndGet() == 0) {
      reduceJobStatusContext.remove(contextId);
      set(new SQLReduceJobResponse(terminate(),parsedStatement));
    }
  }
}

Fixed version (ground truth):
/** 
 * countdown the number of shards to process. called implicitly from   {@link #merge(SQLGroupByResult)}
 */
public void countDown(){
  if (reduceJobStatusContext != null) {
    if (shardsToProcess.decrementAndGet() == 0) {
      reduceJobStatusContext.remove(contextId);
      set(new SQLReduceJobResponse(terminate(),parsedStatement));
    }
  }
}
Program: 13284
Project: 13284
Buggy source:
@Override public BytesRef evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  values.nextValue();
  return values.copyShared();
}

Fixed version (ground truth):
@Override public BytesRef evaluate() throws CrateException {
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  values.nextValue();
return values.copyShared();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13285
Project: 13285
Buggy source:
public abstract ReturnType evaluate();

Fixed version (ground truth):
public abstract ReturnType evaluate() throws CrateException ;
Program: 13286
Project: 13286
Buggy source:
@Override public Double evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return values.nextValue();
}

Fixed version (ground truth):
@Override public Double evaluate(){
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  return values.nextValue();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13287
Project: 13287
Buggy source:
@Override public Float evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Double)values.nextValue()).floatValue();
}

Fixed version (ground truth):
@Override public Float evaluate(){
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  return ((Double)values.nextValue()).floatValue();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13288
Project: 13288
Buggy source:
@Override public Integer evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Long)values.nextValue()).intValue();
}

Fixed version (ground truth):
@Override public Integer evaluate(){
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  return ((Long)values.nextValue()).intValue();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13289
Project: 13289
Buggy source:
@Override public Long evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return values.nextValue();
}

Fixed version (ground truth):
@Override public Long evaluate(){
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  return values.nextValue();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13290
Project: 13290
Buggy source:
@Override public Short evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Long)values.nextValue()).shortValue();
}

Fixed version (ground truth):
@Override public Short evaluate(){
switch (values.setDocument(docId)) {
case 0:
    return null;
case 1:
  return ((Long)values.nextValue()).shortValue();
default :
throw new GroupByOnArrayUnsupportedException(columnName());
}
}
Program: 13291
Project: 13291
Buggy source:
@SuppressWarnings("String_Node_Str") public GroupByRow getRow(){
  ObjectObjectMap m=null;
  Object[] key=new Object[depth];
  for (int i=0; i < depth; i++) {
    boolean last=(i == depth - 1);
    key[i]=expressions.get(i).evaluate();
    if (i == 0) {
      m=maps[getRouting(key[0])];
    }
    Object value=m.get(key[i]);
    if (value == null) {
      if (last) {
        GroupByRow row=GroupByRow.createEmptyRow(new GroupByKey(Arrays.copyOf(key,key.length)),stmt);
        m.put(key[i],row);
        return row;
      }
 else {
        ObjectObjectMap subMap=mapFactories[i].create();
        m.put(key[i],subMap);
        m=subMap;
      }
    }
 else {
      if (last) {
        return (GroupByRow)value;
      }
 else {
        m=(ObjectObjectMap)value;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public GroupByRow getRow() throws CrateException {
  ObjectObjectMap m=null;
  Object[] key=new Object[depth];
  for (int i=0; i < depth; i++) {
    boolean last=(i == depth - 1);
    key[i]=expressions.get(i).evaluate();
    if (i == 0) {
      m=maps[getRouting(key[0])];
    }
    Object value=m.get(key[i]);
    if (value == null) {
      if (last) {
        GroupByRow row=GroupByRow.createEmptyRow(new GroupByKey(Arrays.copyOf(key,key.length)),stmt);
        m.put(key[i],row);
        return row;
      }
 else {
        ObjectObjectMap subMap=mapFactories[i].create();
        m.put(key[i],subMap);
        m=subMap;
      }
    }
 else {
      if (last) {
        return (GroupByRow)value;
      }
 else {
        m=(ObjectObjectMap)value;
      }
    }
  }
  return null;
}
Program: 13292
Project: 13292
Buggy source:
public ReduceJobStatusContext(){
}

Fixed version (ground truth):
public ReduceJobStatusContext(CacheRecycler cacheRecycler){
  this.cacheRecycler=cacheRecycler;
}
Program: 13293
Project: 13293
Buggy source:
private void mergeFromBytesReference(BytesReference bytesReference,SQLReduceJobStatus status) throws IOException {
  SQLGroupByResult sqlGroupByResult=SQLGroupByResult.readSQLGroupByResult(status.parsedStatement.aggregateExpressions,status.seenIdxMapper,new HandlesStreamInput(new BytesStreamInput(bytesReference)));
  status.merge(sqlGroupByResult);
}

Fixed version (ground truth):
private void mergeFromBytesReference(BytesReference bytesReference,SQLReduceJobStatus status) throws IOException {
  SQLGroupByResult sqlGroupByResult=SQLGroupByResult.readSQLGroupByResult(status.parsedStatement,cacheRecycler,new HandlesStreamInput(new BytesStreamInput(bytesReference)));
  status.merge(sqlGroupByResult);
}
Program: 13294
Project: 13294
Buggy source:
public SQLMapperResultRequest(ReduceJobStatusContext jobStatusContext,CacheRecycler cacheRecycler){
  this.jobStatusContext=jobStatusContext;
  this.cacheRecycler=cacheRecycler;
}

Fixed version (ground truth):
public SQLMapperResultRequest(ReduceJobStatusContext jobStatusContext){
  this.jobStatusContext=jobStatusContext;
  cacheRecycler=jobStatusContext.cacheRecycler();
}
Program: 13295
Project: 13295
Buggy source:
private void countDown(){
  if (reduceJobStatusContext != null) {
    if (shardsToProcess.decrementAndGet() == 0) {
      reduceJobStatusContext.remove(contextId);
      set(new SQLReduceJobResponse(trimRows(reducedResult.values())));
    }
  }
}

Fixed version (ground truth):
private void countDown(){
  if (reduceJobStatusContext != null) {
    if (shardsToProcess.decrementAndGet() == 0) {
      reduceJobStatusContext.remove(contextId);
      set(new SQLReduceJobResponse(terminate(),parsedStatement));
    }
  }
}
Program: 13297
Project: 13297
Buggy source:
public ListenableActionFuture<SQLReduceJobResponse> reduceOperationStart(SQLReduceJobRequest request){
  ParsedStatement parsedStatement=sqlParseService.parse(request.request.stmt(),request.request.args());
  SQLReduceJobStatus reduceJobStatus=new SQLReduceJobStatus(parsedStatement,threadPool,resultRecycler.obtain(-1).v(),request.expectedShardResults,request.contextId,reduceJobStatusContext);
  final WeakReference<SQLReduceJobStatus> weakStatus=new WeakReference<>(reduceJobStatus);
  scheduledExecutorService.schedule(new Runnable(){
    @Override public void run(){
      SQLReduceJobStatus status=weakStatus.get();
      if (status != null) {
        status.timeout();
      }
    }
  }
,Constants.GROUP_BY_TIMEOUT,TimeUnit.SECONDS);
  try {
    reduceJobStatusContext.put(request.contextId,reduceJobStatus);
  }
 catch (  IOException e) {
    logger.error(e.getMessage(),e);
  }
  return reduceJobStatus;
}

Fixed version (ground truth):
public ListenableActionFuture<SQLReduceJobResponse> reduceOperationStart(SQLReduceJobRequest request){
  ParsedStatement parsedStatement=sqlParseService.parse(request.request.stmt(),request.request.args());
  SQLReduceJobStatus reduceJobStatus=new SQLReduceJobStatus(parsedStatement,threadPool,request.expectedShardResults,request.contextId,reduceJobStatusContext);
  final WeakReference<SQLReduceJobStatus> weakStatus=new WeakReference<>(reduceJobStatus);
  scheduledExecutorService.schedule(new Runnable(){
    @Override public void run(){
      SQLReduceJobStatus status=weakStatus.get();
      if (status != null) {
        status.timeout();
      }
    }
  }
,Constants.GROUP_BY_TIMEOUT,TimeUnit.SECONDS);
  try {
    reduceJobStatusContext.put(request.contextId,reduceJobStatus);
  }
 catch (  IOException e) {
    logger.error(e.getMessage(),e);
  }
  return reduceJobStatus;
}
Program: 13298
Project: 13298
Buggy source:
@Inject public TransportSQLReduceHandler(TransportService transportService,ClusterService clusterService,SQLParseService sqlParseService,CacheRecycler cacheRecycler,ThreadPool threadPool){
  this.cacheRecycler=cacheRecycler;
  this.sqlParseService=sqlParseService;
  this.clusterService=clusterService;
  this.transportService=transportService;
  this.threadPool=threadPool;
  this.reduceJobStatusContext=new ReduceJobStatusContext();
  this.scheduledExecutorService=new ScheduledThreadPoolExecutor(2);
  this.resultRecycler=new SoftThreadLocalRecycler<>(new Recycler.C<ConcurrentMap<GroupByKey,GroupByRow>>(){
    @Override public ConcurrentMap<GroupByKey,GroupByRow> newInstance(    int sizing){
      return ConcurrentCollections.newConcurrentMap();
    }
    @Override public void clear(    ConcurrentMap<GroupByKey,GroupByRow> value){
      value.clear();
    }
  }
,10);
}

Fixed version (ground truth):
@Inject public TransportSQLReduceHandler(TransportService transportService,ClusterService clusterService,SQLParseService sqlParseService,CacheRecycler cacheRecycler,ThreadPool threadPool){
  this.cacheRecycler=cacheRecycler;
  this.sqlParseService=sqlParseService;
  this.clusterService=clusterService;
  this.transportService=transportService;
  this.threadPool=threadPool;
  this.reduceJobStatusContext=new ReduceJobStatusContext(cacheRecycler);
  this.scheduledExecutorService=new ScheduledThreadPoolExecutor(2);
}
Program: 13299
Project: 13299
Buggy source:
@Override public SQLMapperResultRequest newInstance(){
  return new SQLMapperResultRequest(reduceJobStatusContext,cacheRecycler);
}

Fixed version (ground truth):
@Override public SQLMapperResultRequest newInstance(){
  return new SQLMapperResultRequest(reduceJobStatusContext);
}
Program: 13300
Project: 13300
Buggy source:
@Override public void setNextReader(AtomicReaderContext context){
  super.setNextReader(context);
  values=indexFieldData.load(context).getBytesValues();
}

Fixed version (ground truth):
@Override public void setNextReader(AtomicReaderContext context){
  super.setNextReader(context);
  values=indexFieldData.load(context).getBytesValues(true);
}
Program: 13301
Project: 13301
Buggy source:
@Override public BytesRef evaluate(){
  BytesRef v=values.getValue(docId);
  if (v != null) {
    return values.makeSafe(v);
  }
  return null;
}

Fixed version (ground truth):
@Override public BytesRef evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  values.nextValue();
  return values.copyShared();
}
Program: 13302
Project: 13302
Buggy source:
@Override public void setNextReader(AtomicReaderContext context){
  super.setNextReader(context);
  values=((IndexNumericFieldData)indexFieldData).load(context).getDoubleValues();
}

Fixed version (ground truth):
@Override public void setNextReader(AtomicReaderContext context){
  super.setNextReader(context);
  values=(indexFieldData).load(context).getDoubleValues();
}
Program: 13303
Project: 13303
Buggy source:
@Override public Double evaluate(){
  Double value=values.getValue(docId);
  if (value == 0.0 && !values.hasValue(docId)) {
    return null;
  }
  return value;
}

Fixed version (ground truth):
@Override public Double evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return values.nextValue();
}
Program: 13304
Project: 13304
Buggy source:
@Override public Float evaluate(){
  Float value=((Double)values.getValue(docId)).floatValue();
  if (value == 0 && !values.hasValue(docId)) {
    return null;
  }
  return value;
}

Fixed version (ground truth):
@Override public Float evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Double)values.nextValue()).floatValue();
}
Program: 13305
Project: 13305
Buggy source:
@Override public Integer evaluate(){
  Integer value=((Long)values.getValue(docId)).intValue();
  if (value == 0 && !values.hasValue(docId)) {
    return null;
  }
  return value;
}

Fixed version (ground truth):
@Override public Integer evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Long)values.nextValue()).intValue();
}
Program: 13306
Project: 13306
Buggy source:
@Override public Long evaluate(){
  Long value=values.getValue(docId);
  if (value == 0 && !values.hasValue(docId)) {
    return null;
  }
  return value;
}

Fixed version (ground truth):
@Override public Long evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return values.nextValue();
}
Program: 13307
Project: 13307
Buggy source:
@Override public Short evaluate(){
  Short value=((Long)values.getValue(docId)).shortValue();
  if (value == 0 && !values.hasValue(docId)) {
    return null;
  }
  return value;
}

Fixed version (ground truth):
@Override public Short evaluate(){
  if (values.setDocument(docId) == 0) {
    return null;
  }
  return ((Long)values.nextValue()).shortValue();
}
Program: 13308
Project: 13308
Buggy source:
public void readFrom(StreamInput in,GroupByKey key,ParsedStatement stmt) throws IOException {
  this.key=key;
  Set<Object> values;
  int valuesSize;
  int seenValuesSize=in.readVInt();
  seenValuesList=new ArrayList<>(seenValuesSize);
  for (int i=0; i < seenValuesSize; i++) {
    valuesSize=in.readVInt();
    values=new HashSet<>(valuesSize);
    for (int j=0; j < valuesSize; j++) {
      values.add(in.readGenericValue());
    }
    seenValuesList.add(values);
  }
  aggStates=new ArrayList<>(stmt.aggregateExpressions().size());
  AggExpr aggExpr;
  int seenIdxIndex=0;
  for (int i=0; i < aggStates.size(); i++) {
    aggExpr=stmt.aggregateExpressions().get(i);
    aggStates.add(i,aggExpr.createAggState());
    aggStates.get(i).readFrom(in);
    if (aggExpr.isDistinct) {
      aggStates.get(i).setSeenValuesRef(seenValuesList.get(stmt.seenIdxMap().get(seenIdxIndex++)));
    }
  }
}

Fixed version (ground truth):
public void readFrom(StreamInput in,GroupByKey key,ParsedStatement stmt) throws IOException {
  this.key=key;
  Set<Object> values;
  int valuesSize;
  int seenValuesSize=in.readVInt();
  seenValuesList=new ArrayList<>(seenValuesSize);
  for (int i=0; i < seenValuesSize; i++) {
    valuesSize=in.readVInt();
    values=new HashSet<>(valuesSize);
    for (int j=0; j < valuesSize; j++) {
      values.add(in.readGenericValue());
    }
    seenValuesList.add(values);
  }
  aggStates=new ArrayList<>(stmt.aggregateExpressions().size());
  AggExpr aggExpr;
  int seenIdxIndex=0;
  for (int i=0; i < stmt.aggregateExpressions().size(); i++) {
    aggExpr=stmt.aggregateExpressions().get(i);
    aggStates.add(i,aggExpr.createAggState());
    aggStates.get(i).readFrom(in);
    if (aggExpr.isDistinct) {
      aggStates.get(i).setSeenValuesRef(seenValuesList.get(stmt.seenIdxMap().get(seenIdxIndex++)));
    }
  }
}
Program: 13309
Project: 13309
Buggy source:
@Test public void testGroupTree() throws Exception {
  NodeExecutionContext nec=HitchhikerMocks.nodeExecutionContext();
  TableExecutionContext tec=mock(TableExecutionContext.class);
  when(nec.tableContext(anyString(),anyString())).thenReturn(tec);
  when(tec.getCollectorExpression(any(ValueNode.class))).thenReturn(fakeExpression);
  SQLParseService parseService=new SQLParseService(nec);
  ParsedStatement stmt=parseService.parse("String_Node_Str");
  CacheRecycler cacheRecycler=new CacheRecycler(ImmutableSettings.EMPTY);
  GroupTree t1=new GroupTree(1,stmt,cacheRecycler);
  GroupTree t2=new GroupTree(1,stmt,cacheRecycler);
  GroupByRow row=t1.getRow();
  row=t1.getRow();
  BytesStreamOutput out=new BytesStreamOutput();
  t1.writeBucket(out,0);
  BytesStreamInput in=new BytesStreamInput(out.bytes());
  t2.readBucket(in,0);
  assertEquals(t2.maps().length,t2.maps().length);
  assertMapEquals(t1.maps()[0],t2.maps()[0]);
}

Fixed version (ground truth):
@Test public void testGroupTree() throws Exception {
  CacheRecycler cacheRecycler=new CacheRecycler(ImmutableSettings.EMPTY);
  NodeExecutionContext nec=HitchhikerMocks.nodeExecutionContext();
  TableExecutionContext tec=mock(TableExecutionContext.class);
  when(nec.tableContext(anyString(),anyString())).thenReturn(tec);
  when(tec.getCollectorExpression(any(ValueNode.class))).thenReturn(fakeExpression);
  SQLParseService parseService=new SQLParseService(nec);
  ParsedStatement stmt=parseService.parse("String_Node_Str");
  SQLMapperResultRequest requestSender=new SQLMapperResultRequest();
  GroupTree t1=new GroupTree(1,stmt,cacheRecycler);
  requestSender.contextId=UUID.randomUUID();
  requestSender.groupByResult=new SQLGroupByResult(0,t1);
  t1.getRow();
  t1.getRow();
  BytesStreamOutput out=new BytesStreamOutput();
  requestSender.writeTo(out);
  FutureConcurrentMap<UUID,SQLReduceJobStatus> reduceJobs=FutureConcurrentMap.newMap();
  reduceJobs.put(requestSender.contextId,new SQLReduceJobStatus(stmt,1));
  SQLMapperResultRequest requestReceiver=new SQLMapperResultRequest(reduceJobs,cacheRecycler);
  BytesStreamInput in=new BytesStreamInput(out.bytes());
  requestReceiver.readFrom(in);
  GroupTree t2=(GroupTree)requestReceiver.groupByResult.rows();
  assertEquals(t2.maps().length,t2.maps().length);
  assertMapEquals(t1.maps()[0],t2.maps()[0]);
}
Program: 13310
Project: 13310
Buggy source:
public static Object[][] sortedRowsToObjectArray(Collection<GroupByRow> rows,ParsedStatement parsedStatement,GroupByFieldExtractor[] fieldExtractors){
  int rowCount=parsedStatement.isGlobalAggregate() ? 1 : Math.max(0,rows.size() - parsedStatement.offset());
  Object[][] result=new Object[rowCount][parsedStatement.outputFields().size()];
  int currentRow=-1;
  int remainingOffset=parsedStatement.offset();
  if (parsedStatement.isGlobalAggregate()) {
    if (rowCount == 0) {
      for (int i=0; i < result[0].length; i++) {
        result[0][i]=parsedStatement.aggregateExpressions().get(i).createAggState().value();
      }
      return result;
    }
 else {
      Iterator<GroupByRow> iter=rows.iterator();
      final GroupByRow resultRow=iter.next();
      while (iter.hasNext()) {
        resultRow.merge(iter.next());
      }
      rows=new ArrayList<GroupByRow>(1){
{
          add(resultRow);
        }
      }
;
    }
  }
  for (  GroupByRow row : rows) {
    if (remainingOffset > 0) {
      remainingOffset--;
      continue;
    }
    currentRow++;
    for (int i=0; i < result[currentRow].length; i++) {
      result[currentRow][i]=fieldExtractors[i].getValue(row);
    }
  }
  return result;
}

Fixed version (ground truth):
public static Object[][] sortedRowsToObjectArray(Collection<GroupByRow> rows,ParsedStatement parsedStatement,GroupByFieldExtractor[] fieldExtractors){
  int rowCount=Math.max(0,rows.size() - parsedStatement.offset());
  Object[][] result=new Object[parsedStatement.isGlobalAggregate() ? 1 : rowCount][parsedStatement.outputFields().size()];
  int currentRow=-1;
  int remainingOffset=parsedStatement.offset();
  if (parsedStatement.isGlobalAggregate()) {
    if (rowCount == 0) {
      for (int i=0; i < result[0].length; i++) {
        result[0][i]=parsedStatement.aggregateExpressions().get(i).createAggState().value();
      }
      return result;
    }
 else {
      Iterator<GroupByRow> iter=rows.iterator();
      final GroupByRow resultRow=iter.next();
      while (iter.hasNext()) {
        resultRow.merge(iter.next());
      }
      rows=new ArrayList<GroupByRow>(1){
{
          add(resultRow);
        }
      }
;
    }
  }
  for (  GroupByRow row : rows) {
    if (remainingOffset > 0) {
      remainingOffset--;
      continue;
    }
    currentRow++;
    for (int i=0; i < result[currentRow].length; i++) {
      result[currentRow][i]=fieldExtractors[i].getValue(row);
    }
  }
  return result;
}
Program: 13311
Project: 13311
Buggy source:
public boolean equals(Object o){
  if (this == o)   return true;
  if (!(o instanceof ParameterInfo))   return false;
  ParameterInfo that=(ParameterInfo)o;
  if (isAllColumn != that.isAllColumn)   return false;
  if (columnName != that.columnName)   return false;
  return true;
}

Fixed version (ground truth):
public boolean equals(Object o){
  if (this == o)   return true;
  if (!(o instanceof ParameterInfo))   return false;
  ParameterInfo that=(ParameterInfo)o;
  if (isAllColumn != that.isAllColumn)   return false;
  if (columnName != null && !columnName.equals(that.columnName))   return false;
  if (that.columnName != null && !that.columnName.equals(columnName))   return false;
  return true;
}
Program: 13312
Project: 13312
Buggy source:
@Override public void collect(int doc) throws IOException {
  groupByFieldLookup.setNextDocId(doc);
  Object[] keyValue=new Object[parsedStatement.groupByColumnNames.size()];
  for (int i=0; i < parsedStatement.groupByColumnNames.size(); i++) {
    keyValue[i]=groupByFieldLookup.lookupField(parsedStatement.groupByColumnNames.get(i));
  }
  GroupByKey key=new GroupByKey(keyValue);
  String reducer=partitionByKey(reducers,key);
  Map<GroupByKey,GroupByRow> resultMap=partitionedResult.get(reducer);
  GroupByRow row=resultMap.get(key);
  if (row == null) {
    row=GroupByRow.createEmptyRow(key,parsedStatement.aggregateExpressions,aggFunctionMap);
    resultMap.put(key,row);
  }
  for (int i=0; i < parsedStatement.aggregateExpressions.size(); i++) {
    AggExpr aggExpr=parsedStatement.aggregateExpressions.get(i);
    Object value=null;
    if (!aggExpr.parameterInfo.isAllColumn && aggExpr.parameterInfo.columnName != null) {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    if (aggExpr.parameterInfo.columnName != null) {
      value=groupByFieldLookup.lookupField(aggExpr.parameterInfo.columnName);
    }
    AggFunction function=aggFunctionMap.get(aggExpr.functionName);
    function.iterate(row.aggStates[i],value);
  }
}

Fixed version (ground truth):
@Override public void collect(int doc) throws IOException {
  groupByFieldLookup.setNextDocId(doc);
  Object[] keyValue=new Object[parsedStatement.groupByColumnNames.size()];
  for (int i=0; i < parsedStatement.groupByColumnNames.size(); i++) {
    keyValue[i]=groupByFieldLookup.lookupField(parsedStatement.groupByColumnNames.get(i));
  }
  GroupByKey key=new GroupByKey(keyValue);
  String reducer=partitionByKey(reducers,key);
  Map<GroupByKey,GroupByRow> resultMap=partitionedResult.get(reducer);
  GroupByRow row=resultMap.get(key);
  if (row == null) {
    row=GroupByRow.createEmptyRow(key,parsedStatement.aggregateExpressions,aggFunctionMap);
    resultMap.put(key,row);
  }
  for (int i=0; i < parsedStatement.aggregateExpressions.size(); i++) {
    AggExpr aggExpr=parsedStatement.aggregateExpressions.get(i);
    Object value=null;
    if (!aggExpr.parameterInfo.isAllColumn && aggExpr.parameterInfo.columnName == null) {
      throw new UnsupportedOperationException(String.format("String_Node_Str",aggExpr.functionName));
    }
    if (aggExpr.parameterInfo.columnName != null) {
      value=groupByFieldLookup.lookupField(aggExpr.parameterInfo.columnName);
    }
    AggFunction function=aggFunctionMap.get(aggExpr.functionName);
    function.iterate(row.aggStates[i],value);
  }
}