StarTreeRecordStoreCircularBufferImpl implements StarTreeRecordStore { @Override public Number[] getMetricSums(StarTreeQuery query) { synchronized (sync) { Number[] sums = new Number[metricSpecs.size()]; Arrays.fill(sums, 0); Set<Long> timeBuckets = getTimeBuckets(query); int[] targetDimensions = translateDimensions(query.getDimensionKey()); int idx = binarySearch(targetDimensions); if (idx >= 0) { buffer.clear(); buffer.position(idx + dimensionSize); updateSums(sums, timeBuckets); } else { buffer.clear(); int[] currentDimensions = new int[dimensionSpecs.size()]; while (buffer.position() < buffer.limit()) { buffer.mark(); getDimensions(currentDimensions); if (matches(targetDimensions, currentDimensions)) { updateSums(sums, timeBuckets); } buffer.reset(); buffer.position(buffer.position() + entrySize); } } return sums; } } StarTreeRecordStoreCircularBufferImpl(UUID nodeId,
                                               File file,
                                               StarTreeConfig config,
                                               Map<String, Map<String, Integer>> forwardIndex,
                                               int numTimeBuckets); @Override Long getMinTime(); @Override Long getMaxTime(); @Override Map<TimeRange, Integer> getTimeRangeCount(); @Override void update(StarTreeRecord record); @Override Iterator<StarTreeRecord> iterator(); @Override void clear(); @Override void open(); @Override void close(); @Override int getRecordCount(); @Override int getRecordCountEstimate(); @Override int getCardinality(String dimensionName); @Override String getMaxCardinalityDimension(); @Override String getMaxCardinalityDimension(Collection<String> blacklist); @Override Set<String> getDimensionValues(String dimensionName); @Override Number[] getMetricSums(StarTreeQuery query); @Override MetricTimeSeries getTimeSeries(StarTreeQuery query); static void fillBuffer(final OutputStream outputStream,
                                final StarTreeConfig config,
                                final Map<String, Map<String, Integer>> forwardIndex,
                                final Iterable<StarTreeRecord> records,
                                final int numTimeBuckets,
                                final boolean keepMetricValues); @Override Map<String, Map<String, Integer>> getForwardIndex();  }
@Test public void testGetMetricSums() throws Exception { StarTreeQuery query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("A0", "B0", "C0")) .build(starTreeConfig); Number[] result = recordStore.getMetricSums(query); Assert.assertEquals(result[0], 4 + 3 + 2); query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("*", "*", "*")) .build(starTreeConfig); result = recordStore.getMetricSums(query); Assert.assertEquals(result[0], numRecords); }