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());
}
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());
}
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);
}
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));
}
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());
}
Aggregations