Search in sources :

Example 36 with SearchHit

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

the class SearchQueryRunnerWithCaseTest method checkSearchQuery.

private void checkSearchQuery(SearchQuery searchQuery, Map<String, Set<String>> expectedResults) {
    HashMap<String, List> context = new HashMap<>();
    Iterable<Result<SearchResultValue>> results = Sequences.toList(runner.run(searchQuery, context), Lists.<Result<SearchResultValue>>newArrayList());
    for (Result<SearchResultValue> result : results) {
        Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), result.getTimestamp());
        Assert.assertNotNull(result.getValue());
        Iterable<SearchHit> resultValues = result.getValue();
        for (SearchHit resultValue : resultValues) {
            String dimension = resultValue.getDimension();
            String theValue = resultValue.getValue();
            Assert.assertTrue(String.format("Result had unknown dimension[%s]", dimension), expectedResults.containsKey(dimension));
            Set<String> expectedSet = expectedResults.get(dimension);
            Assert.assertTrue(String.format("Couldn't remove dim[%s], value[%s]", dimension, theValue), expectedSet.remove(theValue));
        }
    }
    for (Map.Entry<String, Set<String>> entry : expectedResults.entrySet()) {
        Assert.assertTrue(String.format("Dimension[%s] should have had everything removed, still has[%s]", entry.getKey(), entry.getValue()), entry.getValue().isEmpty());
    }
    expectedResults.clear();
}
Also used : Set(java.util.Set) SearchHit(io.druid.query.search.search.SearchHit) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with SearchHit

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

the class SearchQueryRunnerTest method testSearchMultiAndFilter.

@Test
public void testSearchMultiAndFilter() {
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
    DimFilter filter = Druids.newAndDimFilterBuilder().fields(Arrays.<DimFilter>asList(Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.marketDimension).value("spot").build(), Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.qualityDimension).value("automotive").build())).build();
    checkSearchQuery(Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).filters(filter).dimensions(QueryRunnerTestHelper.qualityDimension).intervals(QueryRunnerTestHelper.fullOnInterval).query("a").build(), expectedHits);
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) ExtractionDimFilter(io.druid.query.filter.ExtractionDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) Test(org.junit.Test)

Example 38 with SearchHit

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

the class SearchQueryRunnerTest method testSearchWithNotExistedDimension.

@Test
public void testSearchWithNotExistedDimension() throws Exception {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec("asdf", "asdf")).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).build();
    List<SearchHit> noHit = Lists.newLinkedList();
    checkSearchQuery(searchQuery, noHit);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 39 with SearchHit

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

the class SearchQueryRunnerTest method fail.

private void fail(List<SearchHit> expectedResults, Iterable<Result<SearchResultValue>> results, String errorMsg) {
    LOG.info("Expected..");
    for (SearchHit expected : expectedResults) {
        LOG.info(expected.toString());
    }
    LOG.info("Result..");
    for (Result<SearchResultValue> r : results) {
        for (SearchHit v : r.getValue()) {
            LOG.info(v.toString());
        }
    }
    Assert.fail(errorMsg);
}
Also used : SearchHit(io.druid.query.search.search.SearchHit)

Example 40 with SearchHit

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

the class SearchQueryRunnerTest method testSearchOnLongColumn.

@Test
public void testSearchOnLongColumn() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec(Column.TIME_COLUMN_NAME, Column.TIME_COLUMN_NAME, ValueType.LONG)).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("1297123200000").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(Column.TIME_COLUMN_NAME, "1297123200000", 13));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchHit(io.druid.query.search.search.SearchHit) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) 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