StarTreeRecordStoreLogBufferImpl implements StarTreeRecordStore { @Override public MetricTimeSeries getTimeSeries(StarTreeQuery query) { if (query.getTimeRange() == null) { throw new IllegalArgumentException("Query must have time range " + query); } synchronized (sync) { MetricTimeSeries timeSeries = new MetricTimeSeries(metricSchema); ByteBuffer buffer = getBuffer(); buffer.rewind(); while (buffer.position() < buffer.limit()) { boolean matches = true; StarTreeRecord record = getRecord(buffer); for (int i = 0; i < dimensionSpecs.size(); i++) { String recordValue = record.getDimensionKey().getDimensionValues()[i]; String queryValue = query.getDimensionKey().getDimensionValues()[i]; if (!StarTreeConstants.STAR.equals(queryValue) && !queryValue.equals(recordValue)) { matches = false; } } if (matches) { for (Long time : record.getMetricTimeSeries().getTimeWindowSet()) { if (query.getTimeRange() == null || query.getTimeRange().contains(time)) { for (MetricSpec metricSpec : metricSpecs) { timeSeries.increment(time, metricSpec.getName(), record.getMetricTimeSeries().get(time, metricSpec.getName())); } } } } } return timeSeries; } } StarTreeRecordStoreLogBufferImpl(UUID nodeId,
                                          StarTreeConfig config,
                                          int bufferSize,
                                          boolean useDirect,
                                          double targetLoadFactor); @Override void update(StarTreeRecord record); @Override MetricTimeSeries getTimeSeries(StarTreeQuery query); @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 Long getMinTime(); @Override Long getMaxTime(); @Override Map<TimeRange, Integer> getTimeRangeCount(); @Override Map<String, Map<String, Integer>> getForwardIndex();  }
@Test(dataProvider = "recordStoreDataProvider") public void testGetTimeSeries(StarTreeRecordStore recordStore) throws Exception { for (int i = 0; i < 100; i++) { MetricTimeSeries ts = new MetricTimeSeries(metricSchema); ts.set(i / 25, "M", 1000); StarTreeRecord record = new StarTreeRecordImpl.Builder() .setDimensionKey(getDimensionKey("A1", "B1", "C1")) .setMetricTimeSeries(ts) .build(config); recordStore.update(record); } StarTreeQuery query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("*", "*", "*")) .setTimeRange(new TimeRange(0L, 4L)) .build(config); MetricTimeSeries timeSeries = recordStore.getTimeSeries(query); Assert.assertEquals(timeSeries.getTimeWindowSet().size(), 4); query = new StarTreeQueryImpl.Builder() .setDimensionKey(getDimensionKey("*", "*", "*")) .build(config); try { recordStore.getTimeSeries(query); Assert.fail(); } catch (Exception e) { } }