From 75da039396e23a1aca7b949d40fd9efac96fe5e5 Mon Sep 17 00:00:00 2001 From: fjy Date: Thu, 30 Oct 2014 10:43:42 -0700 Subject: [PATCH 1/2] fix search with same value in multiple columns --- .../search/LexicographicSearchSortSpec.java | 6 ++++- .../query/search/SearchQueryRunnerTest.java | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/processing/src/main/java/io/druid/query/search/search/LexicographicSearchSortSpec.java b/processing/src/main/java/io/druid/query/search/search/LexicographicSearchSortSpec.java index 9f84a47292f..04c931112f1 100644 --- a/processing/src/main/java/io/druid/query/search/search/LexicographicSearchSortSpec.java +++ b/processing/src/main/java/io/druid/query/search/search/LexicographicSearchSortSpec.java @@ -41,7 +41,11 @@ public class LexicographicSearchSortSpec implements SearchSortSpec @Override public int compare(SearchHit searchHit, SearchHit searchHit1) { - return searchHit.getValue().compareTo(searchHit1.getValue()); + int retVal = searchHit.getValue().compareTo(searchHit1.getValue()); + if (retVal == 0) { + retVal = searchHit.getDimension().compareTo(searchHit1.getDimension()); + } + return retVal; } }; } 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 e5abe9b5d7f..17f2e090989 100644 --- a/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java @@ -93,6 +93,29 @@ public class SearchQueryRunnerTest checkSearchQuery(searchQuery, expectedResults); } + @Test + public void testSearchSameValueInMultiDims() + { + SearchQuery searchQuery = Druids.newSearchQueryBuilder() + .dataSource(QueryRunnerTestHelper.dataSource) + .granularity(QueryRunnerTestHelper.allGran) + .intervals(QueryRunnerTestHelper.fullOnInterval) + .dimensions( + Arrays.asList( + QueryRunnerTestHelper.placementDimension, + QueryRunnerTestHelper.placementishDimension + ) + ) + .query("e") + .build(); + + Map> expectedResults = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); + expectedResults.put(QueryRunnerTestHelper.placementDimension.toLowerCase(), Sets.newHashSet("preferred")); + expectedResults.put(QueryRunnerTestHelper.placementishDimension, Sets.newHashSet("e", "preferred")); + + checkSearchQuery(searchQuery, expectedResults); + } + @Test public void testFragmentSearch() { From 3e158f00eff0f0941c7820f4dde5f94f007f743a Mon Sep 17 00:00:00 2001 From: fjy Date: Thu, 30 Oct 2014 10:56:39 -0700 Subject: [PATCH 2/2] fix random lowercasing in test --- .../java/io/druid/query/search/SearchQueryRunnerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 17f2e090989..a12fd9a29df 100644 --- a/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/search/SearchQueryRunnerTest.java @@ -87,7 +87,7 @@ public class SearchQueryRunnerTest QueryRunnerTestHelper.qualityDimension, Sets.newHashSet("automotive", "mezzanine", "travel", "health", "entertainment") ); - expectedResults.put(QueryRunnerTestHelper.providerDimension.toLowerCase(), Sets.newHashSet("total_market")); + expectedResults.put(QueryRunnerTestHelper.providerDimension, Sets.newHashSet("total_market")); expectedResults.put(QueryRunnerTestHelper.placementishDimension, Sets.newHashSet("a")); checkSearchQuery(searchQuery, expectedResults); @@ -110,7 +110,7 @@ public class SearchQueryRunnerTest .build(); Map> expectedResults = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); - expectedResults.put(QueryRunnerTestHelper.placementDimension.toLowerCase(), Sets.newHashSet("preferred")); + expectedResults.put(QueryRunnerTestHelper.placementDimension, Sets.newHashSet("preferred")); expectedResults.put(QueryRunnerTestHelper.placementishDimension, Sets.newHashSet("e", "preferred")); checkSearchQuery(searchQuery, expectedResults);