Search in sources :

Example 46 with SearchHit

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);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) SearchHit(io.druid.query.search.search.SearchHit) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) Aggregator(io.druid.query.aggregation.Aggregator) DateTime(org.joda.time.DateTime) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) QueryRunner(io.druid.query.QueryRunner) QueryRunnerFactory(io.druid.query.QueryRunnerFactory) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Example 47 with SearchHit

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());
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Result(io.druid.query.Result) Test(org.junit.Test)

Example 48 with SearchHit

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());
}
Also used : SearchHit(io.druid.query.search.search.SearchHit)

Example 49 with SearchHit

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());
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Result(io.druid.query.Result) Test(org.junit.Test)

Example 50 with SearchHit

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;
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) ArrayList(java.util.ArrayList)

Aggregations

SearchHit (io.druid.query.search.search.SearchHit)57 Test (org.junit.Test)45 Result (io.druid.query.Result)25 SearchQuery (io.druid.query.search.search.SearchQuery)22 SearchSortSpec (io.druid.query.search.search.SearchSortSpec)16 DateTime (org.joda.time.DateTime)12 QueryRunner (io.druid.query.QueryRunner)8 SearchResultValue (io.druid.query.search.SearchResultValue)7 HashMap (java.util.HashMap)6 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)4 AndDimFilter (io.druid.query.filter.AndDimFilter)4 DimFilter (io.druid.query.filter.DimFilter)4 ExtractionDimFilter (io.druid.query.filter.ExtractionDimFilter)4 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)4 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)3 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)3 QueryableIndexSegment (io.druid.segment.QueryableIndexSegment)3 ExtractionFn (io.druid.query.extraction.ExtractionFn)2 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)2