From 4ab6c6b9e2d2ffd428bf78def46f31f3bbd7e6c0 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Mon, 25 Sep 2023 00:43:57 +0800 Subject: [PATCH] [SPARK-45291][SQL][REST] Use unknown query execution id instead of no such app when id is invalid --- .../org/apache/spark/status/api/v1/sql/SqlResource.scala | 3 +-- .../api/v1/sql/SqlResourceWithActualMetricsSuite.scala | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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 3c96f612da6bb..fa5bea5f9bbe3 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 @@ -56,10 +56,9 @@ private[v1] class SqlResource extends BaseAppResource { planDescription: Boolean): ExecutionData = { withUI { ui => val sqlStore = new SQLAppStatusStore(ui.store.store) - val graph = sqlStore.planGraph(execId) sqlStore .execution(execId) - .map(prepareExecutionData(_, graph, details, planDescription)) + .map(prepareExecutionData(_, sqlStore.planGraph(execId), details, planDescription)) .getOrElse(throw new NotFoundException("unknown query execution id: " + execId)) } } diff --git a/sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlResourceWithActualMetricsSuite.scala b/sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlResourceWithActualMetricsSuite.scala index 658f79fc28942..c63c748953f1a 100644 --- a/sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlResourceWithActualMetricsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlResourceWithActualMetricsSuite.scala @@ -19,6 +19,7 @@ package org.apache.spark.status.api.v1.sql import java.net.URL import java.text.SimpleDateFormat +import javax.servlet.http.HttpServletResponse import org.json4s.DefaultFormats import org.json4s.jackson.JsonMethods @@ -148,4 +149,12 @@ class SqlResourceWithActualMetricsSuite } } + test("SPARK-45291: Use unknown query execution id instead of no such app when id is invalid") { + val url = new URL(spark.sparkContext.ui.get.webUrl + + s"/api/v1/applications/${spark.sparkContext.applicationId}/sql/${Long.MaxValue}") + val (code, resultOpt, error) = getContentAndCode(url) + assert(code === HttpServletResponse.SC_NOT_FOUND) + assert(resultOpt.isEmpty) + assert(error.get === s"unknown query execution id: ${Long.MaxValue}") + } }