From b57ac513bd3553407d8cbcb11891dd6501c84e9c Mon Sep 17 00:00:00 2001 From: fjy Date: Mon, 29 Sep 2014 14:56:43 -0700 Subject: [PATCH] Fixes #761 --- .../druid/query/search/SearchQueryRunner.java | 17 +++++++------ .../query/search/SearchQueryRunnerTest.java | 24 ++++++++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java b/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java index e74729a0f60..878151bfb64 100644 --- a/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java +++ b/processing/src/main/java/io/druid/query/search/SearchQueryRunner.java @@ -162,13 +162,16 @@ public class SearchQueryRunner implements QueryRunner> while (!cursor.isDone()) { for (Map.Entry entry : dimSelectors.entrySet()) { final DimensionSelector selector = entry.getValue(); - final IndexedInts vals = selector.getRow(); - for (int i = 0; i < vals.size(); ++i) { - final String dimVal = selector.lookupName(vals.get(i)); - if (searchQuerySpec.accept(dimVal)) { - set.add(new SearchHit(entry.getKey(), dimVal)); - if (set.size() >= limit) { - return set; + + if (selector != null) { + final IndexedInts vals = selector.getRow(); + for (int i = 0; i < vals.size(); ++i) { + final String dimVal = selector.lookupName(vals.get(i)); + if (searchQuerySpec.accept(dimVal)) { + set.add(new SearchHit(entry.getKey(), dimVal)); + if (set.size() >= limit) { + return set; + } } } } diff --git a/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java b/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java index 1b5d6e8b42c..e5abe9b5d7f 100644 --- a/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java @@ -115,10 +115,10 @@ public class SearchQueryRunnerTest Map> expectedResults = new HashMap>(); expectedResults.put( QueryRunnerTestHelper.qualityDimension, new HashSet( - Arrays.asList( - "automotive", "mezzanine", "travel", "health", "entertainment" + Arrays.asList( + "automotive", "mezzanine", "travel", "health", "entertainment" + ) ) - ) ); checkSearchQuery( @@ -366,6 +366,24 @@ public class SearchQueryRunnerTest ); } + + @Test + public void testSearchNonExistingDimension() + { + Map> 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> expectedResults) { Iterable> results = Sequences.toList(