use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchBinaryFnTest method testStrlenMerge.
@Test
public void testStrlenMerge() {
SearchSortSpec searchSortSpec = new SearchSortSpec(StringComparators.STRLEN);
Comparator<SearchHit> c = searchSortSpec.getComparator();
Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:thisislong")));
Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short")));
Result<SearchResultValue> expected = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah:thisislong")));
Result<SearchResultValue> actual = new SearchBinaryFn(searchSortSpec, Granularities.ALL, Integer.MAX_VALUE).apply(r1, r2);
Assert.assertEquals(expected.getTimestamp(), actual.getTimestamp());
assertSearchMergeResult(expected.getValue(), actual.getValue());
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchHitSerDe.
@Test
public void testSearchHitSerDe() throws Exception {
for (SearchHit hit : Arrays.asList(new SearchHit("dim1", "val1"), new SearchHit("dim2", "val2", 3))) {
SearchHit read = TestHelper.JSON_MAPPER.readValue(TestHelper.JSON_MAPPER.writeValueAsString(hit), SearchHit.class);
Assert.assertEquals(hit, read);
if (hit.getCount() == null) {
Assert.assertNull(read.getCount());
} else {
Assert.assertEquals(hit.getCount(), read.getCount());
}
}
}
use of io.druid.query.search.search.SearchHit 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 io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchOnTime.
@Test
public void testSearchOnTime() {
SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("Friday").dimensions(new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, "__time2", new TimeFormatExtractionFn("EEEE", null, null, null, false))).build();
List<SearchHit> expectedHits = Lists.newLinkedList();
expectedHits.add(new SearchHit("__time2", "Friday", 169));
checkSearchQuery(searchQuery, expectedHits);
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchWithDimensionProvider.
@Test
public void testSearchWithDimensionProvider() {
List<SearchHit> expectedHits = Lists.newLinkedList();
expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186));
checkSearchQuery(Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimensions("market").intervals(QueryRunnerTestHelper.fullOnInterval).query("a").build(), expectedHits);
}
Aggregations