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.connector.system;
 
 
 
 import java.util.List;
 
 import static com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static com.google.common.collect.Iterables.transform;
 
 public class TaskSystemTable
         implements SystemTable
 {
     public static final SchemaTableName TASK_TABLE_NAME = new SchemaTableName("sys""task");
 
             .column("node_id")
 
             .column("task_id")
             .column("stage_id")
             .column("query_id")
             .column("state")
 
             .column("splits")
             .column("queued_splits")
             .column("running_splits")
             .column("completed_splits")
 
             .column("split_scheduled_time_ms")
             .column("split_cpu_time_ms")
             .column("split_user_time_ms")
             .column("split_blocked_time_ms")
 
             .column("raw_input_bytes")
             .column("raw_input_rows")
 
             .column("processed_input_bytes")
             .column("processed_input_rows")
 
             .column("output_bytes")
             .column("output_rows")
 
             .column("created")
             .column("start")
             .column("last_heartbeat")
             .column("end")
             .build();
 
     private final TaskManager taskManager;
     private final String nodeId;
 
     @Inject
     public TaskSystemTable(TaskManager taskManagerNodeInfo nodeInfo)
     {
         this. = taskManager;
         this. = nodeInfo.getNodeId();
     }
 
     @Override
     public boolean isDistributed()
     {
         return true;
     }
 
     @Override
     {
         return ;
    }
    @Override
    public List<TypegetColumnTypes()
    {
        return ImmutableList.copyOf(transform(.getColumns(), ColumnMetadata::getType));
    }
    @Override
    public RecordCursor cursor()
    {
        Builder table = InMemoryRecordSet.builder();
        for (TaskInfo taskInfo : .getAllTaskInfo()) {
            TaskStats stats = taskInfo.getStats();
            table.addRow(
                    ,
                    taskInfo.getTaskId().toString(),
                    taskInfo.getTaskId().getStageId().toString(),
                    taskInfo.getTaskId().getQueryId().toString(),
                    taskInfo.getState().toString(),
                    (longstats.getTotalDrivers(),
                    (longstats.getQueuedDrivers(),
                    (longstats.getRunningDrivers(),
                    (longstats.getCompletedDrivers(),
                    toMillis(stats.getTotalScheduledTime()),
                    toMillis(stats.getTotalCpuTime()),
                    toMillis(stats.getTotalUserTime()),
                    toMillis(stats.getTotalBlockedTime()),
                    toBytes(stats.getRawInputDataSize()),
                    stats.getRawInputPositions(),
                    toBytes(stats.getProcessedInputDataSize()),
                    stats.getProcessedInputPositions(),
                    toBytes(stats.getOutputDataSize()),
                    stats.getOutputPositions(),
                    toTimeStamp(stats.getCreateTime()),
                    toTimeStamp(stats.getFirstStartTime()),
                    toTimeStamp(taskInfo.getLastHeartbeat()),
                    toTimeStamp(stats.getEndTime()));
        }
        return table.build().cursor();
    }
    private static Long toMillis(Duration duration)
    {
        if (duration == null) {
            return null;
        }
        return duration.toMillis();
    }
    private static Long toBytes(DataSize dataSize)
    {
        if (dataSize == null) {
            return null;
        }
        return dataSize.toBytes();
    }
    private static Long toTimeStamp(DateTime dateTime)
    {
        if (dateTime == null) {
            return null;
        }
        return dateTime.getMillis();
    }
New to GrepCode? Check out our FAQ X