This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-ballista.git


The following commit(s) were added to refs/heads/master by this push:
     new c2e53f7b Improve formatting of job status in UI (#286)
c2e53f7b is described below

commit c2e53f7be086148b2613e32698a3890566b8a116
Author: Andy Grove <[email protected]>
AuthorDate: Tue Sep 27 08:50:29 2022 -0600

    Improve formatting of job status in UI (#286)
---
 ballista/rust/scheduler/src/api/handlers.rs | 48 ++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/ballista/rust/scheduler/src/api/handlers.rs 
b/ballista/rust/scheduler/src/api/handlers.rs
index 6854636e..dee1e88b 100644
--- a/ballista/rust/scheduler/src/api/handlers.rs
+++ b/ballista/rust/scheduler/src/api/handlers.rs
@@ -11,6 +11,7 @@
 // limitations under the License.
 
 use crate::scheduler_server::SchedulerServer;
+use ballista_core::serde::protobuf::job_status::Status;
 use ballista_core::serde::AsExecutionPlan;
 use ballista_core::BALLISTA_VERSION;
 use datafusion_proto::logical_plan::AsLogicalPlan;
@@ -84,13 +85,46 @@ pub(crate) async fn get_jobs<T: AsLogicalPlan, U: 
AsExecutionPlan>(
 
     let jobs: Vec<JobResponse> = jobs
         .iter()
-        .map(|job| JobResponse {
-            job_id: job.job_id.to_string(),
-            job_status: format!("{:?}", job.status),
-            num_stages: job.num_stages,
-            completed_stages: job.completed_stages,
-            percent_complete: ((job.completed_stages as f32 / job.num_stages 
as f32)
-                * 100_f32) as u8,
+        .map(|job| {
+            let status = &job.status;
+            let job_status = match &status.status {
+                Some(Status::Queued(_)) => "Queued".to_string(),
+                Some(Status::Running(_)) => "Running".to_string(),
+                Some(Status::Failed(error)) => format!("Failed: {}", 
error.error),
+                Some(Status::Completed(completed)) => {
+                    let num_rows = completed
+                        .partition_location
+                        .iter()
+                        .map(|p| {
+                            p.partition_stats.as_ref().map(|s| 
s.num_rows).unwrap_or(0)
+                        })
+                        .sum::<i64>();
+                    let num_rows_term = if num_rows == 1 { "row" } else { 
"rows" };
+                    let num_partitions = completed.partition_location.len();
+                    let num_partitions_term = if num_partitions == 1 {
+                        "partition"
+                    } else {
+                        "partitions"
+                    };
+                    format!(
+                        "Completed. Produced {} {} containing {} {}.",
+                        num_partitions, num_partitions_term, num_rows, 
num_rows_term,
+                    )
+                }
+                _ => "Invalid State".to_string(),
+            };
+
+            // calculate progress based on completed stages for now, but we 
could use completed
+            // tasks in the future to make this more accurate
+            let percent_complete =
+                ((job.completed_stages as f32 / job.num_stages as f32) * 
100_f32) as u8;
+            JobResponse {
+                job_id: job.job_id.to_string(),
+                job_status,
+                num_stages: job.num_stages,
+                completed_stages: job.completed_stages,
+                percent_complete,
+            }
         })
         .collect();
 

Reply via email to