use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerWithCaseTest method checkSearchQuery.
private void checkSearchQuery(SearchQuery searchQuery, Map<String, Set<String>> expectedResults) {
HashMap<String, List> context = new HashMap<>();
Iterable<Result<SearchResultValue>> results = Sequences.toList(runner.run(searchQuery, context), Lists.<Result<SearchResultValue>>newArrayList());
for (Result<SearchResultValue> result : results) {
Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), result.getTimestamp());
Assert.assertNotNull(result.getValue());
Iterable<SearchHit> resultValues = result.getValue();
for (SearchHit resultValue : resultValues) {
String dimension = resultValue.getDimension();
String theValue = resultValue.getValue();
Assert.assertTrue(String.format("Result had unknown dimension[%s]", dimension), expectedResults.containsKey(dimension));
Set<String> expectedSet = expectedResults.get(dimension);
Assert.assertTrue(String.format("Couldn't remove dim[%s], value[%s]", dimension, theValue), expectedSet.remove(theValue));
}
}
for (Map.Entry<String, Set<String>> entry : expectedResults.entrySet()) {
Assert.assertTrue(String.format("Dimension[%s] should have had everything removed, still has[%s]", entry.getKey(), entry.getValue()), entry.getValue().isEmpty());
}
expectedResults.clear();
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchMultiAndFilter.
@Test
public void testSearchMultiAndFilter() {
List<SearchHit> expectedHits = Lists.newLinkedList();
expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
DimFilter filter = Druids.newAndDimFilterBuilder().fields(Arrays.<DimFilter>asList(Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.marketDimension).value("spot").build(), Druids.newSelectorDimFilterBuilder().dimension(QueryRunnerTestHelper.qualityDimension).value("automotive").build())).build();
checkSearchQuery(Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).filters(filter).dimensions(QueryRunnerTestHelper.qualityDimension).intervals(QueryRunnerTestHelper.fullOnInterval).query("a").build(), expectedHits);
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchWithNotExistedDimension.
@Test
public void testSearchWithNotExistedDimension() throws Exception {
SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec("asdf", "asdf")).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).build();
List<SearchHit> noHit = Lists.newLinkedList();
checkSearchQuery(searchQuery, noHit);
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method fail.
private void fail(List<SearchHit> expectedResults, Iterable<Result<SearchResultValue>> results, String errorMsg) {
LOG.info("Expected..");
for (SearchHit expected : expectedResults) {
LOG.info(expected.toString());
}
LOG.info("Result..");
for (Result<SearchResultValue> r : results) {
for (SearchHit v : r.getValue()) {
LOG.info(v.toString());
}
}
Assert.fail(errorMsg);
}
use of io.druid.query.search.search.SearchHit in project druid by druid-io.
the class SearchQueryRunnerTest method testSearchOnLongColumn.
@Test
public void testSearchOnLongColumn() {
SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec(Column.TIME_COLUMN_NAME, Column.TIME_COLUMN_NAME, ValueType.LONG)).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, "1297123200000", 13));
checkSearchQuery(searchQuery, expectedHits);
}
Aggregations