Search in sources :

Example 16 with SearchQuery

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

the class SchemalessTestSimpleTest method testFullOnSearch.

@Test
public void testFullOnSearch() {
    SearchQuery query = Druids.newSearchQueryBuilder().dataSource(dataSource).granularity(allGran).intervals(fullOnInterval).query("a").build();
    List<Result<SearchResultValue>> expectedResults = Arrays.asList(new Result<SearchResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SearchResultValue(Arrays.<SearchHit>asList(new SearchHit(placementishDimension, "a"), new SearchHit(qualityDimension, "automotive"), new SearchHit(placementDimension, "mezzanine"), new SearchHit(marketDimension, "total_market")))));
    QueryRunner runner = TestQueryRunners.makeSearchQueryRunner(segment);
    HashMap<String, Object> context = new HashMap<String, Object>();
    TestHelper.assertExpectedResults(expectedResults, runner.run(query, context));
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) SearchResultValue(io.druid.query.search.SearchResultValue) SearchHit(io.druid.query.search.search.SearchHit) HashMap(java.util.HashMap) DateTime(org.joda.time.DateTime) QueryRunner(io.druid.query.QueryRunner) Result(io.druid.query.Result) Test(org.junit.Test)

Example 17 with SearchQuery

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

the class ServerManagerTest method assertQueryable.

private <T> Future assertQueryable(Granularity granularity, String dataSource, Interval interval, List<Pair<String, Interval>> expected) {
    final Iterator<Pair<String, Interval>> expectedIter = expected.iterator();
    final List<Interval> intervals = Arrays.asList(interval);
    final SearchQuery query = Druids.newSearchQueryBuilder().dataSource(dataSource).intervals(intervals).granularity(granularity).limit(10000).query("wow").build();
    final QueryRunner<Result<SearchResultValue>> runner = serverManager.getQueryRunnerForIntervals(query, intervals);
    return serverManagerExec.submit(new Runnable() {

        @Override
        public void run() {
            Map<String, Object> context = new HashMap<String, Object>();
            Sequence<Result<SearchResultValue>> seq = runner.run(query, context);
            Sequences.toList(seq, Lists.<Result<SearchResultValue>>newArrayList());
            Iterator<SegmentForTesting> adaptersIter = factory.getAdapters().iterator();
            while (expectedIter.hasNext() && adaptersIter.hasNext()) {
                Pair<String, Interval> expectedVals = expectedIter.next();
                SegmentForTesting value = adaptersIter.next();
                Assert.assertEquals(expectedVals.lhs, value.getVersion());
                Assert.assertEquals(expectedVals.rhs, value.getInterval());
            }
            Assert.assertFalse(expectedIter.hasNext());
            Assert.assertFalse(adaptersIter.hasNext());
        }
    });
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) Sequence(io.druid.java.util.common.guava.Sequence) Result(io.druid.query.Result) SearchResultValue(io.druid.query.search.SearchResultValue) Iterator(java.util.Iterator) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Pair(io.druid.java.util.common.Pair) Interval(org.joda.time.Interval)

Example 18 with SearchQuery

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

the class SearchQueryRunnerTest method testSearchOnLongColumnWithExFn.

@Test
public void testSearchOnLongColumnWithExFn() {
    String jsFn = "function(str) { return 'super-' + str; }";
    ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, Column.TIME_COLUMN_NAME, jsExtractionFn)).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, "super-1297123200000", 13));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) SearchHit(io.druid.query.search.search.SearchHit) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 19 with SearchQuery

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

the class SearchQueryRunnerTest method testSearchOnFloatColumn.

@Test
public void testSearchOnFloatColumn() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec(QueryRunnerTestHelper.indexMetric, QueryRunnerTestHelper.indexMetric, ValueType.FLOAT)).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("100.7").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "100.706055", 1));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "100.7756", 1));
    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)

Example 20 with SearchQuery

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

the class SearchQueryRunnerTest method testFragmentSearch.

@Test
public void testFragmentSearch() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query(new FragmentSearchQuerySpec(Arrays.asList("auto", "ve"))).build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchHit(io.druid.query.search.search.SearchHit) Test(org.junit.Test)

Aggregations

SearchQuery (io.druid.query.search.search.SearchQuery)31 Test (org.junit.Test)25 SearchHit (io.druid.query.search.search.SearchHit)22 Result (io.druid.query.Result)12 SearchResultValue (io.druid.query.search.SearchResultValue)9 HashMap (java.util.HashMap)9 QueryRunner (io.druid.query.QueryRunner)8 DateTime (org.joda.time.DateTime)8 Druids (io.druid.query.Druids)5 Set (java.util.Set)5 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)4 Interval (org.joda.time.Interval)4 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)3 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)3 MultipleIntervalSegmentSpec (io.druid.query.spec.MultipleIntervalSegmentSpec)3 Map (java.util.Map)3 Function (com.google.common.base.Function)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ISE (io.druid.java.util.common.ISE)2