Source:
<code>public void scanAndAggregate( TopNParams params, Aggregator[][] rowSelector, Map<Comparable, Aggregator[]> aggregatesStore, int numProcessed ) { final Cursor cursor = params.getCursor(); final DimensionSelector dimSelector = params.getDimSelector(); if (columnCapabilities.isDictionaryEncoded()) { while (!cursor.isDone()) { final IndexedInts dimValues = dimSelector.getRow(); for (int i = 0; i < dimValues.size(); ++i) { final int dimIndex = dimValues.get(i); Aggregator[] theAggregators = rowSelector[dimIndex]; if (theAggregators == null) { final String key = dimSelector.lookupName(dimIndex); theAggregators = aggregatesStore.get(key); if (theAggregators == null) { theAggregators = makeAggregators(cursor, query.getAggregatorSpecs()); aggregatesStore.put(key, theAggregators); } rowSelector[dimIndex] = theAggregators; } for (Aggregator aggregator : theAggregators) { aggregator.aggregate(); } } cursor.advance(); } } else { while (!cursor.isDone()) { Comparable key; <START> switch(columnCapabilities.getType()) { <END> case LONG: final IndexedLongs longVals = dimSelector.getLongRow(); key = dimSelector.getExtractedValueLong(longVals.get(0)); break; case FLOAT: final IndexedFloats floatVals = dimSelector.getFloatRow(); key = dimSelector.getExtractedValueFloat(floatVals.get(0)); break; case COMPLEX: final Comparable objVal = dimSelector.getComparableRow(); key = dimSelector.getExtractedValueComparable(objVal); break; default: throw new IAE("Invalid type: " + columnCapabilities.getType()); } Aggregator[] theAggregators = aggregatesStore.get(key); if (theAggregators == null) { theAggregators = makeAggregators(cursor, query.getAggregatorSpecs()); aggregatesStore.put(key, theAggregators); } for (Aggregator aggregator : theAggregators) { aggregator.aggregate(); } cursor.advance(); } } }</code><technical_language>move this logic cursor loop? improve performance</technical_language>

Target:
public void scanAndAggregate( TopNParams params, Aggregator[][] rowSelector, Map<Comparable, Aggregator[]> aggregatesStore, int numProcessed ) { final Cursor cursor = params.getCursor(); final DimensionSelector dimSelector = params.getDimSelector(); Comparable key; switch (columnCapabilities.getType()) { case STRING: while (!cursor.isDone()) { final IndexedInts dimValues = dimSelector.getRow(); for (int i = 0; i < dimValues.size(); ++i) { final int dimIndex = dimValues.get(i); Aggregator[] theAggregators = rowSelector[dimIndex]; if (theAggregators == null) { key = dimSelector.lookupName(dimIndex); theAggregators = aggregatesStore.get(key); if (theAggregators == null) { theAggregators = makeAggregators(cursor, query.getAggregatorSpecs()); aggregatesStore.put(key, theAggregators); } rowSelector[dimIndex] = theAggregators; } for (Aggregator aggregator : theAggregators) { aggregator.aggregate(); } } cursor.advance(); } break; case LONG: while (!cursor.isDone()) { final IndexedLongs longVals = dimSelector.getLongRow(); key = dimSelector.getExtractedValueLong(longVals.get(0)); updateAggsWithoutDictionary(cursor, aggregatesStore, key); cursor.advance(); } break; case FLOAT: while (!cursor.isDone()) { final IndexedFloats floatVals = dimSelector.getFloatRow(); key = dimSelector.getExtractedValueFloat(floatVals.get(0)); updateAggsWithoutDictionary(cursor, aggregatesStore, key); cursor.advance(); } break; case COMPLEX: while (!cursor.isDone()) { final Comparable objVal = dimSelector.getComparableRow(); key = dimSelector.getExtractedValueComparable(objVal); updateAggsWithoutDictionary(cursor, aggregatesStore, key); cursor.advance(); } break; default: throw new IAE("Invalid type: " + columnCapabilities.getType()); } }