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