Source:
public QueryRunner<SegmentAnalysis> mergeResults(final QueryRunner<SegmentAnalysis> runner) { return new ResultMergeQueryRunner<SegmentAnalysis>(runner) { @Override public Sequence<SegmentAnalysis> doRun( QueryRunner<SegmentAnalysis> baseRunner, QueryPlus<SegmentAnalysis> queryPlus, Map<String, Object> context ) { SegmentMetadataQuery castedQuery = (SegmentMetadataQuery) queryPlus.getQuery(); SegmentMetadataQuery updatedQuery =(SegmentMetadataQuery) (castedQuery.withAnalysisTypes(getFinalAnalysisTypes(castedQuery))); QueryPlus<SegmentAnalysis> updatedQueryPlus = queryPlus.withQuery(updatedQuery); return new MappedSequence<>( CombiningSequence.create( baseRunner.run(updatedQueryPlus, context), makeOrdering(updatedQuery), createMergeFn(updatedQuery) ), MERGE_TRANSFORM_FN ); } @Override protected Ordering<SegmentAnalysis> makeOrdering(Query<SegmentAnalysis> query) { SegmentMetadataQuery castedQuery = (SegmentMetadataQuery) query; SegmentMetadataQuery updatedQuery =(SegmentMetadataQuery) (castedQuery.withAnalysisTypes(getFinalAnalysisTypes(castedQuery))); if ((updatedQuery).isMerge()) { return new Ordering<SegmentAnalysis>() { @Override public int compare( @Nullable SegmentAnalysis left, @Nullable SegmentAnalysis right ) { return 0; } }; } return updatedQuery.getResultOrdering(); } @Override protected BinaryFn<SegmentAnalysis, SegmentAnalysis, SegmentAnalysis> createMergeFn(final Query<SegmentAnalysis> inQ) { SegmentMetadataQuery query = (SegmentMetadataQuery) inQ; SegmentMetadataQuery updatedQuery = (SegmentMetadataQuery) query.withAnalysisTypes(getFinalAnalysisTypes(query)); return new BinaryFn<SegmentAnalysis, SegmentAnalysis, SegmentAnalysis>() { private final SegmentMetadataQuery query = updatedQuery; @Override public SegmentAnalysis apply(SegmentAnalysis arg1, SegmentAnalysis arg2) { return mergeAnalyses(arg1, arg2, query.isLenientAggregatorMerge()); } }; } }; }

Target:
public QueryRunner<SegmentAnalysis> mergeResults(final QueryRunner<SegmentAnalysis> runner) { return new BySegmentSkippingQueryRunner<SegmentAnalysis>(runner) { @Override public Sequence<SegmentAnalysis> doRun( QueryRunner<SegmentAnalysis> baseRunner, QueryPlus<SegmentAnalysis> queryPlus, Map<String, Object> context ) { SegmentMetadataQuery updatedQuery = ((SegmentMetadataQuery) queryPlus.getQuery()).withFinalizedAnalysisTypes(config); QueryPlus<SegmentAnalysis> updatedQueryPlus = queryPlus.withQuery(updatedQuery); return new MappedSequence<>( CombiningSequence.create( baseRunner.run(updatedQueryPlus, context), makeOrdering(updatedQuery), createMergeFn(updatedQuery) ), MERGE_TRANSFORM_FN ); } private Ordering<SegmentAnalysis> makeOrdering(SegmentMetadataQuery query) { if (query.isMerge()) { return new Ordering<SegmentAnalysis>() { @Override public int compare( @Nullable SegmentAnalysis left, @Nullable SegmentAnalysis right ) { return 0; } }; } return query.getResultOrdering(); } private BinaryFn<SegmentAnalysis, SegmentAnalysis, SegmentAnalysis> createMergeFn(final SegmentMetadataQuery inQ) { return new BinaryFn<SegmentAnalysis, SegmentAnalysis, SegmentAnalysis>() { @Override public SegmentAnalysis apply(SegmentAnalysis arg1, SegmentAnalysis arg2) { return mergeAnalyses(arg1, arg2, inQ.isLenientAggregatorMerge()); } }; } }; }