From c3aace7d2fc6778158c319e85bc755017f1fde05 Mon Sep 17 00:00:00 2001 From: Yimin Date: Tue, 22 Mar 2022 18:24:12 +0800 Subject: [PATCH] [SPARK-38579][SQL][WEBUI] Requesting Restful API can cause NullPointerException ### What changes were proposed in this pull request? Added null check for `exec.metricValues`. ### Why are the changes needed? When requesting Restful API {baseURL}/api/v1/applications/$appId/sql/$executionId which is introduced by this PR https://github.com/apache/spark/pull/28208, it can cause NullPointerException. The root cause is, when calling method doUpdate() of `LiveExecutionData`, `metricsValues` can be null. Then, when statement `printableMetrics(graph.allNodes, exec.metricValues)` is executed, it will throw NullPointerException. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Tested manually. Closes #35884 from yym1995/fix-npe. Lead-authored-by: Yimin Co-authored-by: Yimin Yang <26797163+yym1995@users.noreply.github.com> Signed-off-by: Yuming Wang (cherry picked from commit 99992a4e050a00564049be6938f5734876c17518) Signed-off-by: Yuming Wang --- .../org/apache/spark/status/api/v1/sql/SqlResource.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlResource.scala b/sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlResource.scala index c7599f864dd97..4dd96e5ae252b 100644 --- a/sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlResource.scala +++ b/sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlResource.scala @@ -94,7 +94,11 @@ private[v1] class SqlResource extends BaseAppResource { val duration = exec.completionTime.getOrElse(new Date()).getTime - exec.submissionTime val planDetails = if (planDescription) exec.physicalPlanDescription else "" - val nodes = if (details) printableMetrics(graph.allNodes, exec.metricValues) else Seq.empty + val nodes = if (details) { + printableMetrics(graph.allNodes, Option(exec.metricValues).getOrElse(Map.empty)) + } else { + Seq.empty + } val edges = if (details) graph.edges else Seq.empty new ExecutionData(