Search in sources :

Example 6 with SearchHit

use of io.druid.query.search.search.SearchHit in project druid by druid-io.

the class SearchBinaryFnTest method testMergeUniqueResults.

@Test
public void testMergeUniqueResults() {
    Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah", "foo"))));
    Result<SearchResultValue> r2 = r1;
    Result<SearchResultValue> expected = r1;
    Result<SearchResultValue> actual = new SearchBinaryFn(new SearchSortSpec(StringComparators.LEXICOGRAPHIC), 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 7 with SearchHit

use of io.druid.query.search.search.SearchHit in project druid by druid-io.

the class SearchQueryQueryToolChestTest method testCacheStrategy.

@Test
public void testCacheStrategy() throws Exception {
    CacheStrategy<Result<SearchResultValue>, Object, SearchQuery> strategy = new SearchQueryQueryToolChest(null, null).getCacheStrategy(new SearchQuery(new TableDataSource("dummy"), null, Granularities.ALL, 1, new MultipleIntervalSegmentSpec(ImmutableList.of(new Interval("2015-01-01/2015-01-02"))), ImmutableList.of(Druids.DIMENSION_IDENTITY.apply("dim1")), new FragmentSearchQuerySpec(ImmutableList.of("a", "b")), null, null));
    final Result<SearchResultValue> result = new Result<>(new DateTime(123L), new SearchResultValue(ImmutableList.of(new SearchHit("dim1", "a"))));
    Object preparedValue = strategy.prepareForCache().apply(result);
    ObjectMapper objectMapper = new DefaultObjectMapper();
    Object fromCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedValue), strategy.getCacheObjectClazz());
    Result<SearchResultValue> fromCacheResult = strategy.pullFromCache().apply(fromCacheValue);
    Assert.assertEquals(result, fromCacheResult);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchHit(io.druid.query.search.search.SearchHit) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) TableDataSource(io.druid.query.TableDataSource) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 8 with SearchHit

use of io.druid.query.search.search.SearchHit in project druid by druid-io.

the class SearchQueryRunnerTest method testSearchWithNumericSort.

@Test
public void testSearchWithNumericSort() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("a").sortSpec(new SearchSortSpec(StringComparators.NUMERIC)).build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "a", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "entertainment", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "health", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 279));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.partialNullDimension, "value", 186));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Test(org.junit.Test)

Example 9 with SearchHit

use of io.druid.query.search.search.SearchHit in project druid by druid-io.

the class SearchQueryRunnerTest method testSearch.

@Test
public void testSearch() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("a").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "mezzanine", 279));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "travel", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "health", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "entertainment", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.marketDimension, "total_market", 186));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "a", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.partialNullDimension, "value", 186));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) Test(org.junit.Test)

Example 10 with SearchHit

use of io.druid.query.search.search.SearchHit in project druid by druid-io.

the class SearchQueryRunnerTest method testSearchSameValueInMultiDims2.

@Test
public void testSearchSameValueInMultiDims2() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).dimensions(Arrays.asList(QueryRunnerTestHelper.placementDimension, QueryRunnerTestHelper.placementishDimension)).sortSpec(new SearchSortSpec(StringComparators.STRLEN)).query("e").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "e", 93));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementDimension, "preferred", 1209));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.placementishDimension, "preferred", 1209));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Test(org.junit.Test)

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