Merge pull request #767 from metamx/fix-search

Fix NPE when searching  real-time with a non-existing dimension
This commit is contained in:
Gian Merlino 2014-09-29 15:08:31 -07:00
commit 57ee69111f
2 changed files with 31 additions and 10 deletions

View File

@ -162,6 +162,8 @@ public class SearchQueryRunner implements QueryRunner<Result<SearchResultValue>>
while (!cursor.isDone()) {
for (Map.Entry<String, DimensionSelector> entry : dimSelectors.entrySet()) {
final DimensionSelector selector = entry.getValue();
if (selector != null) {
final IndexedInts vals = selector.getRow();
for (int i = 0; i < vals.size(); ++i) {
final String dimVal = selector.lookupName(vals.get(i));
@ -173,6 +175,7 @@ public class SearchQueryRunner implements QueryRunner<Result<SearchResultValue>>
}
}
}
}
cursor.advance();
}

View File

@ -366,6 +366,24 @@ public class SearchQueryRunnerTest
);
}
@Test
public void testSearchNonExistingDimension()
{
Map<String, Set<String>> expectedResults = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
checkSearchQuery(
Druids.newSearchQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource)
.granularity(QueryRunnerTestHelper.allGran)
.intervals(QueryRunnerTestHelper.fullOnInterval)
.dimensions("does_not_exist")
.query("a")
.build(),
expectedResults
);
}
private void checkSearchQuery(SearchQuery searchQuery, Map<String, Set<String>> expectedResults)
{
Iterable<Result<SearchResultValue>> results = Sequences.toList(