use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchWithNullValueInDimension.
@Test
public void testSearchWithNullValueInDimension() throws Exception {
IncrementalIndex<Aggregator> index = new OnheapIncrementalIndex(new IncrementalIndexSchema.Builder().withQueryGranularity(Granularities.NONE).withMinTimestamp(new DateTime("2011-01-12T00:00:00.000Z").getMillis()).build(), true, 10);
index.add(new MapBasedInputRow(1481871600000L, Arrays.asList("name", "host"), ImmutableMap.<String, Object>of("name", "name1", "host", "host")));
index.add(new MapBasedInputRow(1481871670000L, Arrays.asList("name", "table"), ImmutableMap.<String, Object>of("name", "name2", "table", "table")));
SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec("table", "table")).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).context(ImmutableMap.<String, Object>of("searchStrategy", "cursorOnly")).build();
QueryRunnerFactory factory = new SearchQueryRunnerFactory(selector, toolChest, QueryRunnerTestHelper.NOOP_QUERYWATCHER);
QueryRunner runner = factory.createRunner(new QueryableIndexSegment("asdf", TestIndex.persistRealtimeAndLoadMMapped(index)));
List<SearchHit> expectedHits = Lists.newLinkedList();
expectedHits.add(new SearchHit("table", "table", 1));
expectedHits.add(new SearchHit("table", "", 1));
checkSearchQuery(searchQuery, runner, expectedHits);
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchBinaryFnTest method testStrlenMerge2.
@Test
public void testStrlenMerge2() {
SearchSortSpec searchSortSpec = new SearchSortSpec(StringComparators.STRLEN);
Comparator<SearchHit> c = searchSortSpec.getComparator();
Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah:thisislong", "blah2:thisislong")));
Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah2:thisislong")));
Result<SearchResultValue> expected = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah:thisislong", "blah2: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 SearchBinaryFnTest method assertSearchMergeResult.
private void assertSearchMergeResult(SearchResultValue o1, SearchResultValue o2) {
Iterator<SearchHit> i1 = ((Iterable) o1).iterator();
Iterator<SearchHit> i2 = ((Iterable) o2).iterator();
while (i1.hasNext() && i2.hasNext()) {
SearchHit s1 = i1.next();
SearchHit s2 = i2.next();
Assert.assertEquals(s1, s2);
Assert.assertEquals(s1.getCount(), s2.getCount());
}
Assert.assertTrue(!i1.hasNext() && !i2.hasNext());
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchBinaryFnTest method testMergeLimit.
@Test
public void testMergeLimit() {
Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah", "foo"))));
Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime, new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah2", "foo2"))));
Result<SearchResultValue> expected = r1;
Result<SearchResultValue> actual = new SearchBinaryFn(new SearchSortSpec(StringComparators.LEXICOGRAPHIC), Granularities.ALL, 1).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 SearchBinaryFnTest method toHits.
// merge function expects input to be sorted as per comparator
private List<SearchHit> toHits(Comparator<SearchHit> comparator, String... hits) {
List<SearchHit> result = new ArrayList<>();
for (String hit : hits) {
int index = hit.indexOf(':');
result.add(new SearchHit(hit.substring(0, index), hit.substring(index + 1)));
}
Collections.sort(result, comparator);
return result;
}
Aggregations