StarTreeRecordStoreCircularBufferImpl implements StarTreeRecordStore { @Override public MetricTimeSeries getTimeSeries(StarTreeQuery query) { synchronized (sync) { Map<Long, Number[]> allSums = new HashMap<Long, Number[]>(); Set<Long> timeBuckets = getTimeBuckets(query); if (timeBuckets == null) { throw new IllegalArgumentException("Must specify time range in query " + query); } int[] targetDimensions = translateDimensions(query.getDimensionKey()); int idx = binarySearch(targetDimensions); if (idx >= 0) { buffer.clear(); buffer.position(idx + dimensionSize); updateAllSums(allSums, timeBuckets); } else { buffer.clear(); int[] currentDimensions = new int[dimensionSpecs.size()]; while (buffer.position() < buffer.limit()) { buffer.mark(); getDimensions(currentDimensions); if (matches(targetDimensions, currentDimensions)) { updateAllSums(allSums, timeBuckets); } buffer.reset(); buffer.position(buffer.position() + entrySize); } } MetricTimeSeries timeSeries = new MetricTimeSeries(metricSchema); for (Map.Entry<Long, Number[]> entry : allSums.entrySet()) { for (int i = 0; i < config.getMetrics().size(); i++) { timeSeries.increment(entry.getKey(), config.getMetrics().get(i).getName(), entry.getValue()[i]); } } return timeSeries; } } 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 testGetTimeSeries() throws Exception { StarTreeQuery query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("*", "*", "*")) .setTimeRange(new TimeRange(0L, 3L)) .build(starTreeConfig); MetricTimeSeries timeSeries = recordStore.getTimeSeries(query); Assert.assertEquals(timeSeries.getTimeWindowSet().size(), 4); for (Long timeWindow : timeSeries.getTimeWindowSet()) { Assert.assertEquals(timeSeries.get(timeWindow, "M").intValue(), 25); } query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("*", "*", "*")) .build(starTreeConfig); try { recordStore.getTimeSeries(query); Assert.fail(); } catch (Exception e) { } }