use of org.joda.time.DateTime in project druid by druid-io.
the class SelectBinaryFnTest method testColumnMerge.
@Test
public void testColumnMerge() throws Exception {
SelectBinaryFn binaryFn = new SelectBinaryFn(Granularities.ALL, new PagingSpec(null, 5), false);
Result<SelectResultValue> res1 = new Result<>(new DateTime("2013-01-01"), new SelectResultValue(ImmutableMap.<String, Integer>of(), Sets.newHashSet("first", "second", "fourth"), Sets.newHashSet("eight", "nineth"), Lists.<EventHolder>newArrayList(new EventHolder(segmentId1, 0, ImmutableMap.<String, Object>of(EventHolder.timestampKey, new DateTime("2013-01-01T00"), "dim", "first")))));
Result<SelectResultValue> res2 = new Result<>(new DateTime("2013-01-01"), new SelectResultValue(ImmutableMap.<String, Integer>of(), Sets.newHashSet("third", "second", "fifth"), Sets.newHashSet("seventh"), Lists.<EventHolder>newArrayList(new EventHolder(segmentId2, 0, ImmutableMap.<String, Object>of(EventHolder.timestampKey, new DateTime("2013-01-01T00"), "dim", "second")))));
Result<SelectResultValue> merged = binaryFn.apply(res1, res2);
Set<String> exDimensions = Sets.newHashSet("first", "second", "fourth", "third", "fifth");
Set<String> exMetrics = Sets.newHashSet("eight", "nineth", "seventh");
Set<String> acDimensions = merged.getValue().getDimensions();
Set<String> acMetrics = merged.getValue().getMetrics();
Assert.assertEquals(exDimensions, acDimensions);
Assert.assertEquals(exMetrics, acMetrics);
}
use of org.joda.time.DateTime in project druid by druid-io.
the class SearchQueryRunnerTest method checkSearchQuery.
private void checkSearchQuery(Query searchQuery, QueryRunner runner, List<SearchHit> expectedResults) {
Iterable<Result<SearchResultValue>> results = Sequences.toList(runner.run(searchQuery, ImmutableMap.of()), Lists.<Result<SearchResultValue>>newArrayList());
List<SearchHit> copy = Lists.newLinkedList(expectedResults);
for (Result<SearchResultValue> result : results) {
Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), result.getTimestamp());
Assert.assertTrue(result.getValue() instanceof Iterable);
Iterable<SearchHit> resultValues = result.getValue();
for (SearchHit resultValue : resultValues) {
int index = copy.indexOf(resultValue);
if (index < 0) {
fail(expectedResults, results, "No result found containing " + resultValue.getDimension() + " and " + resultValue.getValue());
}
SearchHit expected = copy.remove(index);
if (!resultValue.toString().equals(expected.toString())) {
fail(expectedResults, results, "Invalid count for " + resultValue + ".. which was expected to be " + expected.getCount());
}
}
}
if (!copy.isEmpty()) {
fail(expectedResults, results, "Some expected results are not shown: " + copy);
}
}
use of org.joda.time.DateTime in project druid by druid-io.
the class SelectQueryRunnerTest method testFullOnSelectWithLongAndFloatWithExFn.
@Test
public void testFullOnSelectWithLongAndFloatWithExFn() {
String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
List<DimensionSpec> dimSpecs = Arrays.<DimensionSpec>asList(new ExtractionDimensionSpec(QueryRunnerTestHelper.indexMetric, "floatIndex", jsExtractionFn), new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, "longTime", jsExtractionFn));
SelectQuery query = newTestQuery().dimensionSpecs(dimSpecs).metrics(Arrays.asList(Column.TIME_COLUMN_NAME, "index")).intervals(I_0112_0114).build();
HashMap<String, Object> context = new HashMap<String, Object>();
Iterable<Result<SelectResultValue>> results = Sequences.toList(runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());
List<Result<SelectResultValue>> expectedResultsAsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2), Sets.newHashSet("null_column", "floatIndex", "longTime"), Sets.newHashSet("__time", "index"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, 0, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build())))));
List<Result<SelectResultValue>> expectedResultsDsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, -3), Sets.newHashSet("null_column", "floatIndex", "longTime"), Sets.newHashSet("__time", "index"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, -1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-1564.61767578125").put(QueryRunnerTestHelper.indexMetric, 1564.6177f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-826.0601806640625").put(QueryRunnerTestHelper.indexMetric, 826.0602f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -3, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-1689.0128173828125").put(QueryRunnerTestHelper.indexMetric, 1689.0128f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build())))));
verify(descending ? expectedResultsDsc : expectedResultsAsc, populateNullColumnAtLastForQueryableIndexCase(results, "null_column"));
}
use of org.joda.time.DateTime in project druid by druid-io.
the class SelectQueryRunnerTest method testFullOnSelectWithDimensionSpec.
@Test
public void testFullOnSelectWithDimensionSpec() {
Map<String, String> map = new HashMap<>();
map.put("automotive", "automotive0");
map.put("business", "business0");
map.put("entertainment", "entertainment0");
map.put("health", "health0");
map.put("mezzanine", "mezzanine0");
map.put("news", "news0");
map.put("premium", "premium0");
map.put("technology", "technology0");
map.put("travel", "travel0");
SelectQuery query = newTestQuery().dimensionSpecs(Arrays.<DimensionSpec>asList(new DefaultDimensionSpec(QueryRunnerTestHelper.marketDimension, "mar"), new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, "qual", new LookupExtractionFn(new MapLookupExtractor(map, true), false, null, true, false)), new DefaultDimensionSpec(QueryRunnerTestHelper.placementDimension, "place"))).build();
HashMap<String, Object> context = new HashMap<String, Object>();
Iterable<Result<SelectResultValue>> results = Sequences.toList(runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());
List<Result<SelectResultValue>> expectedResultsAsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2), Sets.newHashSet("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, 0, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "automotive0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "business0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "entertainment0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build())))));
List<Result<SelectResultValue>> expectedResultsDsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, -3), Sets.newHashSet("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, -1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 780.27197265625F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "mezzanine0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 962.731201171875F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -3, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "total_market").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 1029.0570068359375F).build())))));
verify(descending ? expectedResultsDsc : expectedResultsAsc, results);
}
use of org.joda.time.DateTime in project druid by druid-io.
the class SpecificSegmentQueryRunnerTest method testRetry2.
@SuppressWarnings("unchecked")
@Test
public void testRetry2() throws Exception {
final ObjectMapper mapper = new DefaultObjectMapper();
SegmentDescriptor descriptor = new SegmentDescriptor(new Interval("2012-01-01T00:00:00Z/P1D"), "version", 0);
TimeseriesResultBuilder builder = new TimeseriesResultBuilder(new DateTime("2012-01-01T00:00:00Z"));
CountAggregator rows = new CountAggregator();
rows.aggregate();
builder.addMetric("rows", rows);
final Result<TimeseriesResultValue> value = builder.build();
final SpecificSegmentQueryRunner queryRunner = new SpecificSegmentQueryRunner(new QueryRunner() {
@Override
public Sequence run(Query query, Map responseContext) {
return Sequences.withEffect(Sequences.simple(Arrays.asList(value)), new Runnable() {
@Override
public void run() {
throw new SegmentMissingException("FAILSAUCE");
}
}, MoreExecutors.sameThreadExecutor());
}
}, new SpecificSegmentSpec(descriptor));
final Map<String, Object> responseContext = Maps.newHashMap();
TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("foo").granularity(Granularities.ALL).intervals(ImmutableList.of(new Interval("2012-01-01T00:00:00Z/P1D"))).aggregators(ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("rows"))).build();
Sequence results = queryRunner.run(query, responseContext);
List<Result<TimeseriesResultValue>> res = Sequences.toList(results, Lists.<Result<TimeseriesResultValue>>newArrayList());
Assert.assertEquals(1, res.size());
Result<TimeseriesResultValue> theVal = res.get(0);
Assert.assertTrue(1L == theVal.getValue().getLongMetric("rows"));
validate(mapper, descriptor, responseContext);
}
Aggregations