Search in sources :

Example 11 with SearchSortSpec

use of io.druid.query.search.search.SearchSortSpec 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)

Example 12 with SearchSortSpec

use of io.druid.query.search.search.SearchSortSpec 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 13 with SearchSortSpec

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

the class SearchSortSpecTest method testLexicographicComparator.

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

Example 14 with SearchSortSpec

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

the class SearchSortSpecTest method testSerde.

@Test
public void testSerde() throws IOException {
    ObjectMapper jsonMapper = new DefaultObjectMapper();
    SearchSortSpec spec = new SearchSortSpec(StringComparators.ALPHANUMERIC);
    String expectJsonSpec = "{\"type\":{\"type\":\"alphanumeric\"}}";
    String jsonSpec = jsonMapper.writeValueAsString(spec);
    Assert.assertEquals(expectJsonSpec, jsonSpec);
    Assert.assertEquals(spec, jsonMapper.readValue(jsonSpec, SearchSortSpec.class));
    String expectJsonSpec2 = "{\"type\":\"alphanumeric\"}";
    Assert.assertEquals(spec, jsonMapper.readValue(expectJsonSpec2, SearchSortSpec.class));
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) SearchSortSpec(io.druid.query.search.search.SearchSortSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 15 with SearchSortSpec

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

the class SearchBinaryFnTest method testStrlenMerge2.

@Test
public void testStrlenMerge2() {
    SearchSortSpec searchSortSpec = new SearchSortSpec(StringComparators.STRLEN);
    Comparator<SearchHit> c = searchSortSpec.getComparator();
    Result<SearchResultValue> r1 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah:thisislong", "blah2:thisislong")));
    Result<SearchResultValue> r2 = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah2:thisislong")));
    Result<SearchResultValue> expected = new Result<SearchResultValue>(currTime, new SearchResultValue(toHits(c, "blah:short", "blah:thisislong", "blah2: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)

Aggregations

SearchSortSpec (io.druid.query.search.search.SearchSortSpec)17 Test (org.junit.Test)17 SearchHit (io.druid.query.search.search.SearchHit)16 Result (io.druid.query.Result)10 SearchQuery (io.druid.query.search.search.SearchQuery)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1