drcrallen commented on a change in pull request #5913: Move Caching Cluster 
Client to java streams and allow parallel intermediate merges
URL: https://github.com/apache/incubator-druid/pull/5913#discussion_r213764213
 
 

 ##########
 File path: 
processing/src/main/java/io/druid/query/ChainedExecutionQueryRunner.java
 ##########
 @@ -70,87 +74,115 @@ public ChainedExecutionQueryRunner(
       QueryRunner<T>... queryables
   )
   {
-    this(exec, queryWatcher, Arrays.asList(queryables));
+    this(exec, queryWatcher, Arrays.stream(queryables));
   }
 
   public ChainedExecutionQueryRunner(
       ExecutorService exec,
       QueryWatcher queryWatcher,
       Iterable<QueryRunner<T>> queryables
   )
+  {
+    this(exec, queryWatcher, StreamSupport.stream(queryables.spliterator(), 
false));
+  }
+
+  public ChainedExecutionQueryRunner(
+      ExecutorService exec,
+      QueryWatcher queryWatcher,
+      Stream<QueryRunner<T>> queryables
+  )
   {
     // listeningDecorator will leave PrioritizedExecutorService unchanged,
     // since it already implements ListeningExecutorService
     this.exec = MoreExecutors.listeningDecorator(exec);
-    this.queryables = Iterables.unmodifiableIterable(queryables);
     this.queryWatcher = queryWatcher;
+    this.queryables = queryables;
   }
 
   @Override
   public Sequence<T> run(final QueryPlus<T> queryPlus, final Map<String, 
Object> responseContext)
   {
-    Query<T> query = queryPlus.getQuery();
+    final Query<T> query = queryPlus.getQuery();
     final int priority = QueryContexts.getPriority(query);
-    final Ordering ordering = query.getResultOrdering();
+    final Ordering<T> ordering = query.getResultOrdering();
     final QueryPlus<T> threadSafeQueryPlus = 
queryPlus.withoutThreadUnsafeState();
-    return new BaseSequence<T, Iterator<T>>(
+    return new BaseSequence<>(
         new BaseSequence.IteratorMaker<T, Iterator<T>>()
         {
           @Override
           public Iterator<T> make()
           {
             // Make it a List<> to materialize all of the values (so that it 
will submit everything to the executor)
-            ListenableFuture<List<Iterable<T>>> futures = Futures.allAsList(
-                Lists.newArrayList(
-                    Iterables.transform(
-                        queryables,
-                        input -> {
-                          if (input == null) {
-                            throw new ISE("Null queryRunner! Looks to be some 
segment unmapping action happening");
+            final ListenableFuture<List<Iterable<T>>> futures = 
GuavaUtils.allFuturesAsList(
+                queryables.peek(
+                    queryRunner -> {
+                      if (queryRunner == null) {
+                        throw new ISE("Null queryRunner! Looks to be some 
segment unmapping action happening");
+                      }
+                    }
+                ).map(
+                    queryRunner -> new 
AbstractPrioritizedCallable<Iterable<T>>(priority)
+                    {
+                      @Override
+                      public Iterable<T> call()
+                      {
+                        try {
+                          Sequence<T> result = 
queryRunner.run(threadSafeQueryPlus, responseContext);
+                          if (result == null) {
+                            throw new ISE("Got a null result! Segments are 
missing!");
+                          }
+
+                          List<T> retVal = result.toList();
+                          if (retVal == null) {
+                            throw new ISE("Got a null list of results! WTF?!");
                           }
 
-                          return exec.submit(
-                              new 
AbstractPrioritizedCallable<Iterable<T>>(priority)
-                              {
-                                @Override
-                                public Iterable<T> call()
-                                {
-                                  try {
-                                    Sequence<T> result = 
input.run(threadSafeQueryPlus, responseContext);
-                                    if (result == null) {
-                                      throw new ISE("Got a null result! 
Segments are missing!");
-                                    }
-
-                                    List<T> retVal = result.toList();
-                                    if (retVal == null) {
-                                      throw new ISE("Got a null list of 
results! WTF?!");
-                                    }
-
-                                    return retVal;
-                                  }
-                                  catch (QueryInterruptedException e) {
-                                    throw Throwables.propagate(e);
-                                  }
-                                  catch (Exception e) {
-                                    log.error(e, "Exception with one of the 
sequences!");
-                                    throw Throwables.propagate(e);
-                                  }
-                                }
-                              }
-                          );
+                          return retVal;
                         }
-                    )
-                )
+                        catch (QueryInterruptedException e) {
+                          throw Throwables.propagate(e);
+                        }
+                        catch (Exception e) {
+                          log.error(e, "Exception with one of the sequences!");
+                          throw Throwables.propagate(e);
+                        }
+                      }
+                    }
+                ).map(exec::submit)
             );
 
             queryWatcher.registerQuery(query, futures);
 
             try {
+              final DateTime deadline;
+              if (QueryContexts.hasTimeout(query)) {
+                deadline = DateTimes.nowUtc().plusMillis((int) 
QueryContexts.getTimeout(query));
+              } else {
+                deadline = DateTimes.utc(JodaUtils.MAX_INSTANT);
 
 Review comment:
   Changed to be more in line with other query runner timeout calculations. The 
refactoring to put the managed blocker in a central place made it a lot cleaner 
to do this change.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to