diff --git a/client/src/main/java/com/metamx/druid/query/group/GroupByQueryQueryToolChest.java b/client/src/main/java/com/metamx/druid/query/group/GroupByQueryQueryToolChest.java index f6e63b36acb..c90c4fd8ded 100644 --- a/client/src/main/java/com/metamx/druid/query/group/GroupByQueryQueryToolChest.java +++ b/client/src/main/java/com/metamx/druid/query/group/GroupByQueryQueryToolChest.java @@ -25,6 +25,7 @@ import com.google.common.base.Functions; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.metamx.common.ISE; import com.metamx.common.guava.Accumulator; import com.metamx.common.guava.ConcatSequence; @@ -33,8 +34,10 @@ import com.metamx.common.guava.Sequences; import com.metamx.druid.Query; import com.metamx.druid.QueryGranularity; import com.metamx.druid.aggregation.AggregatorFactory; +import com.metamx.druid.aggregation.post.PostAggregator; import com.metamx.druid.index.v1.IncrementalIndex; import com.metamx.druid.initialization.Initialization; +import com.metamx.druid.input.MapBasedInputRow; import com.metamx.druid.input.MapBasedRow; import com.metamx.druid.input.Row; import com.metamx.druid.input.Rows; @@ -42,6 +45,8 @@ import com.metamx.druid.query.MetricManipulationFn; import com.metamx.druid.query.QueryRunner; import com.metamx.druid.query.QueryToolChest; import com.metamx.druid.query.dimension.DimensionSpec; +import com.metamx.druid.result.Result; +import com.metamx.druid.result.TimeseriesResultValue; import com.metamx.druid.utils.PropUtils; import com.metamx.emitter.service.ServiceMetricEvent; @@ -57,7 +62,6 @@ import java.util.Properties; */ public class GroupByQueryQueryToolChest extends QueryToolChest { - private static final TypeReference TYPE_REFERENCE = new TypeReference(){}; private static final String GROUP_BY_MERGE_KEY = "groupByMerge"; private static final Map NO_MERGE_CONTEXT = ImmutableMap.of(GROUP_BY_MERGE_KEY, "false"); @@ -183,9 +187,24 @@ public class GroupByQueryQueryToolChest extends QueryToolChest makeMetricManipulatorFn(GroupByQuery query, MetricManipulationFn fn) + public Function makeMetricManipulatorFn(final GroupByQuery query, final MetricManipulationFn fn) { - return Functions.identity(); + return new Function() + { + @Override + public Row apply(Row input) + { + if (input instanceof MapBasedRow) { + final MapBasedRow inputRow = (MapBasedRow) input; + final Map values = Maps.newHashMap(((MapBasedRow) input).getEvent()); + for (AggregatorFactory agg : query.getAggregatorSpecs()) { + values.put(agg.getName(), fn.manipulate(agg, inputRow.getEvent().get(agg.getName()))); + } + return new MapBasedRow(inputRow.getTimestamp(), values); + } + return input; + } + }; } @Override diff --git a/index-common/src/main/java/com/metamx/druid/index/v1/IndexIO.java b/index-common/src/main/java/com/metamx/druid/index/v1/IndexIO.java index 6d3ff975549..b6991ffbe0b 100644 --- a/index-common/src/main/java/com/metamx/druid/index/v1/IndexIO.java +++ b/index-common/src/main/java/com/metamx/druid/index/v1/IndexIO.java @@ -358,11 +358,13 @@ public class IndexIO } ByteBuffer spatialBuffer = smooshedFiles.mapFile("spatial.drd"); - for (String dimension : IndexedIterable.create(availableDimensions)) { - spatialIndexed.put( - serializerUtils.readString(spatialBuffer), - GenericIndexed.read(spatialBuffer, IndexedRTree.objectStrategy) - ); + if (spatialBuffer != null) { + for (String dimension : IndexedIterable.create(availableDimensions)) { + spatialIndexed.put( + serializerUtils.readString(spatialBuffer), + GenericIndexed.read(spatialBuffer, IndexedRTree.objectStrategy) + ); + } } final MMappedIndex retVal = new MMappedIndex( @@ -422,7 +424,7 @@ public class IndexIO Map> spatialIndexes = Maps.newHashMap(); final ByteBuffer spatialBuffer = v8SmooshedFiles.mapFile("spatial.drd"); - while (spatialBuffer.hasRemaining()) { + while (spatialBuffer != null && spatialBuffer.hasRemaining()) { spatialIndexes.put( serializerUtils.readString(spatialBuffer), GenericIndexed.read(spatialBuffer, IndexedRTree.objectStrategy) diff --git a/index-common/src/main/java/com/metamx/druid/index/v1/MMappedIndex.java b/index-common/src/main/java/com/metamx/druid/index/v1/MMappedIndex.java index ea8347d96af..b5084d15f71 100644 --- a/index-common/src/main/java/com/metamx/druid/index/v1/MMappedIndex.java +++ b/index-common/src/main/java/com/metamx/druid/index/v1/MMappedIndex.java @@ -19,15 +19,26 @@ package com.metamx.druid.index.v1; +import com.google.common.base.Function; +import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.primitives.Ints; import com.metamx.common.logger.Logger; import com.metamx.common.spatial.rtree.ImmutableRTree; +import com.metamx.druid.kv.ConciseCompressedIndexedInts; import com.metamx.druid.kv.GenericIndexed; +import com.metamx.druid.kv.Indexed; +import com.metamx.druid.kv.IndexedList; import com.metamx.druid.kv.IndexedLongs; +import com.metamx.druid.kv.IndexedRTree; import com.metamx.druid.kv.VSizeIndexed; +import com.metamx.druid.kv.VSizeIndexedInts; import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet; import org.joda.time.Interval; +import java.nio.ByteOrder; +import java.nio.LongBuffer; +import java.util.Arrays; import java.util.Map; /** @@ -158,7 +169,6 @@ public class MMappedIndex return (retVal == null) ? emptySet : retVal; } -/* public static MMappedIndex fromIndex(Index index) { log.info("Converting timestamps"); @@ -249,6 +259,11 @@ public class MMappedIndex ConciseCompressedIndexedInts.objectStrategy ) ); + + spatialIndexes.put( + dimension, + GenericIndexed.fromIterable(Arrays.asList(index.getSpatialIndex(dimension)), IndexedRTree.objectStrategy) + ); } log.info("Making MMappedIndex"); @@ -264,5 +279,4 @@ public class MMappedIndex spatialIndexes ); } -*/ }