From a5170666b61764017c3711b15ff68e3653243d9b Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Wed, 8 Mar 2017 10:47:46 -0800 Subject: [PATCH] groupBy v2: Always merge queries. (#4023) This fixes #4020 because it means the timestamp will always be included for outermost queries. Historicals receiving queries from older brokers will think they're outermost (because CTX_KEY_OUTERMOST isn't set to "false"), so they'll include a timestamp, so the older brokers will be OK. --- .../query/groupby/GroupByQueryQueryToolChest.java | 7 ++++--- .../druid/query/groupby/strategy/GroupByStrategy.java | 5 +++++ .../query/groupby/strategy/GroupByStrategyV1.java | 10 ++++++++-- .../query/groupby/strategy/GroupByStrategyV2.java | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java index 8b0a9f8e473..9701370ce60 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -108,9 +108,10 @@ public class GroupByQueryQueryToolChest extends QueryToolChestof( //setting sort to false avoids unnecessary sorting while merging results. we only need to sort - //in the end when returning results to user. + //in the end when returning results to user. (note this is only respected by groupBy v1) GroupByQueryHelper.CTX_KEY_SORT_RESULTS, false ) diff --git a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategy.java b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategy.java index 5d140fae826..c170db1520d 100644 --- a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategy.java +++ b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategy.java @@ -53,6 +53,11 @@ public interface GroupByStrategy */ boolean isCacheable(boolean willMergeRunners); + /** + * Indicates if this query should undergo "mergeResults" or not. + */ + boolean doMergeResults(final GroupByQuery query); + /** * Decorate a runner with an interval chunking decorator. */ diff --git a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV1.java b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV1.java index 544e6c9ce1c..9b2c9163818 100644 --- a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV1.java +++ b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV1.java @@ -101,6 +101,12 @@ public class GroupByStrategyV1 implements GroupByStrategy return decorator.decorate(runner, toolChest); } + @Override + public boolean doMergeResults(final GroupByQuery query) + { + return query.getContextBoolean(GroupByQueryQueryToolChest.GROUP_BY_MERGE_KEY, true); + } + @Override public Sequence mergeResults( final QueryRunner baseRunner, @@ -131,10 +137,10 @@ public class GroupByStrategyV1 implements GroupByStrategy ImmutableMap.of( "finalize", false, //setting sort to false avoids unnecessary sorting while merging results. we only need to sort - //in the end when returning results to user. + //in the end when returning results to user. (note this is only respected by groupBy v1) GroupByQueryHelper.CTX_KEY_SORT_RESULTS, false, //no merging needed at historicals because GroupByQueryRunnerFactory.mergeRunners(..) would return - //merged results + //merged results. (note this is only respected by groupBy v1) GroupByQueryQueryToolChest.GROUP_BY_MERGE_KEY, false, GroupByQueryConfig.CTX_KEY_STRATEGY, GroupByStrategySelector.STRATEGY_V1 ) diff --git a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV2.java b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV2.java index e4dc798d17c..45dbd954d1c 100644 --- a/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV2.java +++ b/processing/src/main/java/io/druid/query/groupby/strategy/GroupByStrategyV2.java @@ -179,6 +179,12 @@ public class GroupByStrategyV2 implements GroupByStrategy return willMergeRunners; } + @Override + public boolean doMergeResults(final GroupByQuery query) + { + return true; + } + @Override public QueryRunner createIntervalChunkingRunner( final IntervalChunkingQueryRunnerDecorator decorator,