use of org.joda.time.DateTime in project druid by druid-io.
the class TimeBoundaryQueryRunnerTest method testTimeBoundary.
@Test
@SuppressWarnings("unchecked")
public void testTimeBoundary() {
TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").build();
Assert.assertFalse(timeBoundaryQuery.hasFilters());
HashMap<String, Object> context = new HashMap<String, Object>();
Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList());
TimeBoundaryResultValue val = results.iterator().next().getValue();
DateTime minTime = val.getMinTime();
DateTime maxTime = val.getMaxTime();
Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), minTime);
Assert.assertEquals(new DateTime("2011-04-15T00:00:00.000Z"), maxTime);
}
use of org.joda.time.DateTime in project druid by druid-io.
the class TimeBoundaryQueryRunnerTest method testMergeResults.
@Test
public void testMergeResults() throws Exception {
List<Result<TimeBoundaryResultValue>> results = Arrays.asList(new Result<>(new DateTime(), new TimeBoundaryResultValue(ImmutableMap.of("maxTime", "2012-01-01", "minTime", "2011-01-01"))), new Result<>(new DateTime(), new TimeBoundaryResultValue(ImmutableMap.of("maxTime", "2012-02-01", "minTime", "2011-01-01"))));
TimeBoundaryQuery query = new TimeBoundaryQuery(new TableDataSource("test"), null, null, null, null);
Iterable<Result<TimeBoundaryResultValue>> actual = query.mergeResults(results);
Assert.assertTrue(actual.iterator().next().getValue().getMaxTime().equals(new DateTime("2012-02-01")));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class TimeBoundaryQueryRunnerTest method testTimeBoundaryMin.
@Test
@SuppressWarnings("unchecked")
public void testTimeBoundaryMin() {
TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").bound(TimeBoundaryQuery.MIN_TIME).build();
Map<String, Object> context = new MapMaker().makeMap();
context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList());
Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList());
TimeBoundaryResultValue val = results.iterator().next().getValue();
DateTime minTime = val.getMinTime();
DateTime maxTime = val.getMaxTime();
Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), minTime);
Assert.assertNull(maxTime);
}
use of org.joda.time.DateTime in project druid by druid-io.
the class TimeseriesQueryRunnerBonusTest method testOneRowAtATime.
@Test
public void testOneRowAtATime() throws Exception {
final IncrementalIndex oneRowIndex = new OnheapIncrementalIndex(new DateTime("2012-01-01T00:00:00Z").getMillis(), Granularities.NONE, new AggregatorFactory[] {}, 1000);
List<Result<TimeseriesResultValue>> results;
oneRowIndex.add(new MapBasedInputRow(new DateTime("2012-01-01T00:00:00Z").getMillis(), ImmutableList.of("dim1"), ImmutableMap.<String, Object>of("dim1", "x")));
results = runTimeseriesCount(oneRowIndex);
Assert.assertEquals("index size", 1, oneRowIndex.size());
Assert.assertEquals("result size", 1, results.size());
Assert.assertEquals("result timestamp", new DateTime("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
Assert.assertEquals("result count metric", 1, (long) results.get(0).getValue().getLongMetric("rows"));
oneRowIndex.add(new MapBasedInputRow(new DateTime("2012-01-01T00:00:00Z").getMillis(), ImmutableList.of("dim1"), ImmutableMap.<String, Object>of("dim1", "y")));
results = runTimeseriesCount(oneRowIndex);
Assert.assertEquals("index size", 2, oneRowIndex.size());
Assert.assertEquals("result size", 1, results.size());
Assert.assertEquals("result timestamp", new DateTime("2012-01-01T00:00:00Z"), results.get(0).getTimestamp());
Assert.assertEquals("result count metric", 2, (long) results.get(0).getValue().getLongMetric("rows"));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNLongColumn.
@Test
public void testFullOnTopNLongColumn() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new DefaultDimensionSpec("qualityLong", "ql_alias", ValueType.LONG)).metric("maxIndex").threshold(4).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(QueryRunnerTestHelper.commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("ql_alias", 1400L).put(QueryRunnerTestHelper.indexMetric, 217725.42022705078D).put("rows", 279L).put("addRowsIndexConstant", 218005.42022705078D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.06103515625D).put("minIndex", 91.27055358886719D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", 1600L).put(QueryRunnerTestHelper.indexMetric, 210865.67966461182D).put("rows", 279L).put("addRowsIndexConstant", 211145.67966461182D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.7379150390625D).put("minIndex", 99.2845230102539D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", 1000L).put(QueryRunnerTestHelper.indexMetric, 12270.807106018066D).put("rows", 93L).put("addRowsIndexConstant", 12364.807106018066D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 277.2735290527344D).put("minIndex", 71.31593322753906D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", 1200L).put(QueryRunnerTestHelper.indexMetric, 12086.472755432129D).put("rows", 93L).put("addRowsIndexConstant", 12180.472755432129D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 193.78756713867188D).put("minIndex", 84.71052551269531D).build()))));
assertExpectedResults(expectedResults, query);
}
Aggregations