Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.server;
 
 
 
 import java.net.URI;
 import java.util.List;
 
 import static com.facebook.presto.OutputBuffers.INITIAL_EMPTY_OUTPUT_BUFFERS;
 import static com.facebook.presto.tuple.TupleInfo.SINGLE_VARBINARY;
 import static com.google.common.collect.Iterables.filter;
 import static com.google.common.collect.Iterables.transform;
 
 public class MockQueryManager
         implements QueryManager
 {
     public static final List<TupleInfoTUPLE_INFOS = ImmutableList.of();
 
     private final MockTaskManager mockTaskManager;
     private final LocationFactory locationFactory;
     private final AtomicInteger nextQueryId = new AtomicInteger();
     private final ConcurrentMap<QueryIdSimpleQueryqueries = new ConcurrentHashMap<>();
 
     @Inject
     public MockQueryManager(MockTaskManager mockTaskManagerLocationFactory locationFactory)
     {
         Preconditions.checkNotNull(mockTaskManager"mockTaskManager is null");
         Preconditions.checkNotNull(locationFactory"locationFactory is null");
         this. = mockTaskManager;
         this. = locationFactory;
     }
 
     @Override
     public List<QueryInfogetAllQueryInfo()
     {
         return ImmutableList.copyOf(filter(transform(.values(), new Function<SimpleQueryQueryInfo>()
         {
             @Override
             public QueryInfo apply(SimpleQuery queryWorker)
             {
                 try {
                     return queryWorker.getQueryInfo();
                 }
                 catch (RuntimeException ignored) {
                     return null;
                 }
             }
         }), Predicates.notNull()));
     }
 
     @Override
     public Duration waitForStateChange(QueryId queryIdQueryState currentStateDuration maxWait)
             throws InterruptedException
     {
         return maxWait;
     }
 
     @Override
    public QueryInfo getQueryInfo(QueryId queryId)
    {
        Preconditions.checkNotNull(queryId"queryId is null");
        SimpleQuery query = .get(queryId);
        if (query == null) {
            throw new NoSuchElementException();
        }
        return query.getQueryInfo();
    }
    @Override
    public QueryInfo createQuery(Session sessionString query)
    {
        Preconditions.checkNotNull(query"query is null");
        TaskId outputTaskId = new TaskId(String.valueOf(.getAndIncrement()), "0""0");
        .updateTask(session,
                outputTaskId,
                null,
                ImmutableList.<TaskSource>of(),
        SimpleQuery simpleQuery = new SimpleQuery(outputTaskId.createQueryLocation(outputTaskId.getQueryId()), );
        .put(outputTaskId.getQueryId(), simpleQuery);
        return simpleQuery.getQueryInfo();
    }
    @Override
    public void cancelQuery(QueryId queryId)
    {
        .remove(queryId);
    }
    @Override
    public void cancelStage(StageId stageId)
    {
        // mock queries don't have stages
    }
    private static class SimpleQuery
    {
        private final TaskId outputTaskId;
        private final URI self;
        private final MockTaskManager mockTaskManager;
        private final LocationFactory locationFactory;
        private SimpleQuery(TaskId outputTaskIdURI selfMockTaskManager mockTaskManagerLocationFactory locationFactory)
        {
            this. = outputTaskId;
            this. = self;
            this. = mockTaskManager;
            this. = locationFactory;
        }
        private QueryInfo getQueryInfo()
        {
            TaskInfo outputTask = .getTaskInfo(false);
            QueryState state;
            switch (outputTask.getState()) {
                case :
                case :
                    state = .;
                    break;
                case :
                    state = .;
                    break;
                case :
                    state = .;
                    break;
                case :
                    state = .;
                    break;
                default:
                    throw new IllegalStateException("Unknown task state " + outputTask.getState());
            }
            return new QueryInfo(.getQueryId(),
                    new Session("user""test""test_catalog""test_schema"nullnull),
                    state,
                    ,
                    ImmutableList.of("out"),
                    "query",
                    new QueryStats(),
                    new StageInfo(.getStageId(),
                            .,
                            .createStageLocation(.getStageId()),
                            null,
                            ,
                            new StageStats(),
                            ImmutableList.<TaskInfo>of(outputTask),
                            ImmutableList.<StageInfo>of(),
                            ImmutableList.<ExecutionFailureInfo>of()),
                    null,
                    null,
                    null);
        }
    }
New to GrepCode? Check out our FAQ X