Source:
public <T> QueryRunner<T> getQueryRunnerForSegments(final Query<T> query, final Iterable<SegmentDescriptor> specs) { final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query); if (factory == null) { throw new ISE("Unknown query type[%s].", query.getClass()); } final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(query.getDataSource()); if (!analysis.isConcreteTableBased()) { throw new ISE("Cannot handle datasource: %s", query.getDataSource()); } final String dataSourceName = ((TableDataSource) analysis.getBaseDataSource()).getName(); final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest(); if (analysis.isQuery() && !toolChest.canPerformSubquery(((QueryDataSource) analysis.getDataSource()).getQuery())) { throw new ISE("Cannot handle subquery: %s", analysis.getDataSource()); } final Function<Segment, Segment> segmentMapFn = Joinables.createSegmentMapFn( analysis.getPreJoinableClauses(), joinableFactory, new AtomicLong(), QueryContexts.getEnableJoinFilterPushDown(query) ); final QueryRunner<T> baseRunner = new FinalizeResultsQueryRunner<>( toolChest.postMergeQueryDecoration( toolChest.mergeResults( toolChest.preMergeQueryDecoration( makeTableRunner(toolChest, factory, getSegmentsForTable(dataSourceName, specs), segmentMapFn) ) ) ), toolChest ); return (theQuery, responseContext) -> { if (scheduler != null) { Set<SegmentServerSelector> segments = new HashSet<>(); specs.forEach(spec -> segments.add(new SegmentServerSelector(null, spec))); return scheduler.run( scheduler.laneQuery(theQuery, segments), new LazySequence<>( () -> baseRunner.run( theQuery.withQuery(Queries.withSpecificSegments( theQuery.getQuery(), ImmutableList.copyOf(specs) )), responseContext ) ) ); } else { return baseRunner.run( theQuery.withQuery(Queries.withSpecificSegments(theQuery.getQuery(), ImmutableList.copyOf(specs))), responseContext ); } }; }

Target:
public <T> QueryRunner<T> getQueryRunnerForSegments(final Query<T> query, final Iterable<SegmentDescriptor> specs) { final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query); if (factory == null) { throw new ISE("Unknown query type[%s].", query.getClass()); } final DataSourceAnalysis analysis = DataSourceAnalysis.forDataSource(query.getDataSource()); if (!analysis.isConcreteTableBased()) { throw new ISE("Cannot handle datasource: %s", query.getDataSource()); } final String dataSourceName = ((TableDataSource) analysis.getBaseDataSource()).getName(); final QueryToolChest<T, Query<T>> toolChest = factory.getToolchest(); if (analysis.isQuery() && !toolChest.canPerformSubquery(((QueryDataSource) analysis.getDataSource()).getQuery())) { throw new ISE("Cannot handle subquery: %s", analysis.getDataSource()); } final Function<Segment, Segment> segmentMapFn = Joinables.createSegmentMapFn( analysis.getPreJoinableClauses(), joinableFactory, new AtomicLong(), QueryContexts.getEnableJoinFilterPushDown(query), QueryContexts.getEnableJoinFilterRewrite(query) ); final QueryRunner<T> baseRunner = new FinalizeResultsQueryRunner<>( toolChest.postMergeQueryDecoration( toolChest.mergeResults( toolChest.preMergeQueryDecoration( makeTableRunner(toolChest, factory, getSegmentsForTable(dataSourceName, specs), segmentMapFn) ) ) ), toolChest ); return (theQuery, responseContext) -> { if (scheduler != null) { Set<SegmentServerSelector> segments = new HashSet<>(); specs.forEach(spec -> segments.add(new SegmentServerSelector(null, spec))); return scheduler.run( scheduler.laneQuery(theQuery, segments), new LazySequence<>( () -> baseRunner.run( theQuery.withQuery(Queries.withSpecificSegments( theQuery.getQuery(), ImmutableList.copyOf(specs) )), responseContext ) ) ); } else { return baseRunner.run( theQuery.withQuery(Queries.withSpecificSegments(theQuery.getQuery(), ImmutableList.copyOf(specs))), responseContext ); } }; }