Skip to content

Commit

Permalink
[SPARK-45291][SQL][REST] Use unknown query execution id instead of no…
Browse files Browse the repository at this point in the history
… such app when id is invalid

### What changes were proposed in this pull request?

This PR fixes `/api/v1/applications/{appId}/sql/{executionId}` API when the executionId is invalid.

Before this, we get `no such app: $appId`; after this, we get `unknown query execution id: $executionId`

### Why are the changes needed?

bugfix

### Does this PR introduce _any_ user-facing change?

no, bugfix

### How was this patch tested?

new test
### Was this patch authored or co-authored using generative AI tooling?

no

Closes apache#43073 from yaooqinn/SPARK-45291.

Authored-by: Kent Yao <[email protected]>
Signed-off-by: Kent Yao <[email protected]>
  • Loading branch information
yaooqinn committed Sep 25, 2023
1 parent fb2bee3 commit 5d42215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
}
}

0 comments on commit 5d42215

Please sign in to comment.