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.
This commit is contained in:
Gian Merlino 2017-03-08 10:47:46 -08:00 committed by Himanshu
parent c155d9a5e9
commit a5170666b6
4 changed files with 23 additions and 5 deletions

View File

@ -108,9 +108,10 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
return runner.run(query, responseContext); return runner.run(query, responseContext);
} }
if (query.getContextBoolean(GROUP_BY_MERGE_KEY, true)) { final GroupByQuery groupByQuery = (GroupByQuery) query;
if (strategySelector.strategize(groupByQuery).doMergeResults(groupByQuery)) {
return initAndMergeGroupByResults( return initAndMergeGroupByResults(
(GroupByQuery) query, groupByQuery,
runner, runner,
responseContext responseContext
); );
@ -181,7 +182,7 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
subquery.withOverriddenContext( subquery.withOverriddenContext(
ImmutableMap.<String, Object>of( ImmutableMap.<String, Object>of(
//setting sort to false avoids unnecessary sorting while merging results. we only need to sort //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, GroupByQueryHelper.CTX_KEY_SORT_RESULTS,
false false
) )

View File

@ -53,6 +53,11 @@ public interface GroupByStrategy
*/ */
boolean isCacheable(boolean willMergeRunners); 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. * Decorate a runner with an interval chunking decorator.
*/ */

View File

@ -101,6 +101,12 @@ public class GroupByStrategyV1 implements GroupByStrategy
return decorator.decorate(runner, toolChest); return decorator.decorate(runner, toolChest);
} }
@Override
public boolean doMergeResults(final GroupByQuery query)
{
return query.getContextBoolean(GroupByQueryQueryToolChest.GROUP_BY_MERGE_KEY, true);
}
@Override @Override
public Sequence<Row> mergeResults( public Sequence<Row> mergeResults(
final QueryRunner<Row> baseRunner, final QueryRunner<Row> baseRunner,
@ -131,10 +137,10 @@ public class GroupByStrategyV1 implements GroupByStrategy
ImmutableMap.<String, Object>of( ImmutableMap.<String, Object>of(
"finalize", false, "finalize", false,
//setting sort to false avoids unnecessary sorting while merging results. we only need to sort //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, GroupByQueryHelper.CTX_KEY_SORT_RESULTS, false,
//no merging needed at historicals because GroupByQueryRunnerFactory.mergeRunners(..) would return //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, GroupByQueryQueryToolChest.GROUP_BY_MERGE_KEY, false,
GroupByQueryConfig.CTX_KEY_STRATEGY, GroupByStrategySelector.STRATEGY_V1 GroupByQueryConfig.CTX_KEY_STRATEGY, GroupByStrategySelector.STRATEGY_V1
) )

View File

@ -179,6 +179,12 @@ public class GroupByStrategyV2 implements GroupByStrategy
return willMergeRunners; return willMergeRunners;
} }
@Override
public boolean doMergeResults(final GroupByQuery query)
{
return true;
}
@Override @Override
public QueryRunner<Row> createIntervalChunkingRunner( public QueryRunner<Row> createIntervalChunkingRunner(
final IntervalChunkingQueryRunnerDecorator decorator, final IntervalChunkingQueryRunnerDecorator decorator,