Repository: prestodb/presto
Issue: Number of splits for intermediate stages in CLI shows incorrect values

There two related problems:
1) the number of running intermediate splits goes up and down throughout the execution of the query. This causes the progress bar to move forward and backward, since the chevron section of the bar depends on how many splits are running at a given point in time.
2) in cases where most leaf splits are done and the query is waiting on stragglers, intermediate stages show "0" splits running. This causes overall progress to show a misleading number, since the intermediate splits are being counted towards the total number of splits to be completed.

I believe this may be happening because RUNNING state for intermediate splits no longer counts splits that are BLOCKED. We need to fix the counter so that it reflects both (i.e., splits scheduled on workers, instead of just splits being scheduled on a CPU).

```
46:20 [32.4M rows, 3.01GB] [11.7K rows/s, 1.11MB/s] [========>                                 ] 18%

     STAGES   ROWS  ROWS/s  BYTES  BYTES/s  QUEUED    RUN   DONE
0.........R      0       0     0B       0B       0      0      0
  1.......R      0       0     0B       0B       0      0      0
    2.....R  56.6M   20.3K   7.1G    2.61M       0      0      0
      3...R  32.4M   11.7K  3.01G    1.11M       0      1    489
```

Changed files:
presto-main/src/main/java/com/facebook/presto/server/StatementResource.java, presto-main/src/main/java/com/facebook/presto/operator/PipelineContext.java

diff --git a/presto-main/src/main/java/com/facebook/presto/operator/PipelineContext.java b/presto-main/src/main/java/com/facebook/presto/operator/PipelineContext.java
index a8b39e6688..30f26ecea5 100644
--- a/presto-main/src/main/java/com/facebook/presto/operator/PipelineContext.java
+++ b/presto-main/src/main/java/com/facebook/presto/operator/PipelineContext.java
@@ -455,7 +455,7 @@ public class PipelineContext
                 new Duration(totalCpuTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
                 new Duration(totalUserTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
                 new Duration(totalBlockedTime, NANOSECONDS).convertToMostSuccinctTimeUnit(),
-                fullyBlocked && (runningDrivers > 0 || runningPartitionedDrivers > 0),
+                fullyBlocked,
                 blockedReasons,
 
                 succinctBytes(rawInputDataSize),
diff --git a/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java b/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java
index 3e1e599f6f..684a77b642 100644
--- a/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java
+++ b/presto-main/src/main/java/com/facebook/presto/server/StatementResource.java
@@ -625,7 +625,7 @@ public class StatementResource
                     .setNodes(globalUniqueNodes(outputStage).size())
                     .setTotalSplits(queryStats.getTotalDrivers())
                     .setQueuedSplits(queryStats.getQueuedDrivers())
-                    .setRunningSplits(queryStats.getRunningDrivers())
+                    .setRunningSplits(queryStats.getRunningDrivers() + queryStats.getBlockedDrivers())
                     .setCompletedSplits(queryStats.getCompletedDrivers())
                     .setUserTimeMillis(queryStats.getTotalUserTime().toMillis())
                     .setCpuTimeMillis(queryStats.getTotalCpuTime().toMillis())
@@ -663,7 +663,7 @@ public class StatementResource
                     .setNodes(uniqueNodes.size())
                     .setTotalSplits(stageStats.getTotalDrivers())
                     .setQueuedSplits(stageStats.getQueuedDrivers())
-                    .setRunningSplits(stageStats.getRunningDrivers())
+                    .setRunningSplits(stageStats.getRunningDrivers() + stageStats.getBlockedDrivers())
                     .setCompletedSplits(stageStats.getCompletedDrivers())
                     .setUserTimeMillis(stageStats.getTotalUserTime().toMillis())
                     .setCpuTimeMillis(stageStats.getTotalCpuTime().toMillis())