Search in sources :

Example 11 with SearchHit

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

the class SearchSortSpecTest method testAlphanumericComparator.

@Test
public void testAlphanumericComparator() {
    SearchSortSpec spec = new SearchSortSpec(StringComparators.ALPHANUMERIC);
    SearchHit hit1 = new SearchHit("test", "a100");
    SearchHit hit2 = new SearchHit("test", "a9");
    SearchHit hit3 = new SearchHit("test", "b0");
    Assert.assertTrue(spec.getComparator().compare(hit1, hit2) > 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit1) > 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit2) > 0);
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Test(org.junit.Test)

Example 12 with SearchHit

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

the class SearchSortSpecTest method testNumericComparator.

@Test
public void testNumericComparator() {
    SearchSortSpec spec = new SearchSortSpec(StringComparators.NUMERIC);
    SearchHit hit1 = new SearchHit("test", "1001001.12412");
    SearchHit hit2 = new SearchHit("test", "-1421");
    SearchHit hit3 = new SearchHit("test", "not-numeric-at-all");
    SearchHit hit4 = new SearchHit("best", "1001001.12412");
    Assert.assertTrue(spec.getComparator().compare(hit1, hit2) > 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit1) < 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit2) < 0);
    Assert.assertTrue(spec.getComparator().compare(hit1, hit4) > 0);
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Test(org.junit.Test)

Example 13 with SearchHit

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

the class SearchSortSpecTest method testStrlenComparator.

@Test
public void testStrlenComparator() {
    SearchSortSpec spec = new SearchSortSpec(StringComparators.LEXICOGRAPHIC);
    SearchHit hit1 = new SearchHit("test", "apple");
    SearchHit hit2 = new SearchHit("test", "banana");
    SearchHit hit3 = new SearchHit("test", "orange");
    Assert.assertTrue(spec.getComparator().compare(hit1, hit2) < 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit1) > 0);
    Assert.assertTrue(spec.getComparator().compare(hit3, hit2) > 0);
    Assert.assertTrue(spec.getComparator().compare(hit1, hit1) == 0);
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) Test(org.junit.Test)

Example 14 with SearchHit

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

the class SearchBinaryFnTest method testAlphanumericMerge.

@Test
public void testAlphanumericMerge() {
    SearchSortSpec searchSortSpec = new SearchSortSpec(StringComparators.ALPHANUMERIC);
    Comparator<SearchHit> c = searchSortSpec.getComparator();
    Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:a100", "blah:a9", "alah:a100")));
    Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:b0", "alah:c3")));
    Result<SearchResultValue> expected = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:a9", "alah:a100", "blah:a100", "blah:b0", "alah:c3")));
    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 15 with SearchHit

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

the class SearchBinaryFnTest method testMergeShiftedTimestamp.

@Test
public void testMergeShiftedTimestamp() {
    Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah", "foo"))));
    Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime.plusHours(2), new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah2", "foo2"))));
    Result<SearchResultValue> expected = new Result<SearchResultValue>(currTime, new SearchResultValue(ImmutableList.<SearchHit>of(new SearchHit("blah", "foo"), new SearchHit("blah2", "foo2"))));
    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)

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