Search in sources :

Example 16 with SearchHit

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());
}
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 17 with SearchHit

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

Example 18 with SearchHit

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

Example 19 with SearchHit

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);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) SearchHit(io.druid.query.search.search.SearchHit) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 20 with SearchHit

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