-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API #35939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
603cfe9
SPARK-38617 show Spark rule and phase timings in SQL UI and REST API
yliou 160aca2
SPARK-38617 rename added REST fields
yliou 1901cf8
SPARK-38617 rename SqlCompilerResourceSuite and save String names for…
yliou 3e0a4d3
SPARK-38617 lower SQLConf default and minor cleanup
yliou 2a513a8
SPARK-38617 Minor refactoring and rewording of API class names
yliou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlCompilerResource.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.status.api.v1.sql | ||
|
|
||
| import javax.ws.rs._ | ||
| import javax.ws.rs.core.MediaType | ||
| import scala.collection.mutable.ListBuffer | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.sql.catalyst.QueryPlanningTracker | ||
| import org.apache.spark.sql.execution.ui.{SQLAppStatusStore, SQLExecutionUIData} | ||
| import org.apache.spark.status.api.v1.{BaseAppResource, NotFoundException} | ||
|
|
||
|
|
||
|
|
||
| @Produces(Array(MediaType.APPLICATION_JSON)) | ||
| private[v1] class SqlCompilerResource extends BaseAppResource with Logging { | ||
|
|
||
| @GET | ||
| def compilerStat( | ||
| @DefaultValue("0") @QueryParam("offset") offset: Int, | ||
| @DefaultValue("20") @QueryParam("length") length: Int): Seq[CompileData] = { | ||
| withUI { ui => | ||
| val sqlStore = new SQLAppStatusStore(ui.store.store) | ||
| sqlStore.executionsList(offset, length).map { exec => | ||
| val compileStats = sqlStore.getCompilerStats(exec.executionId) | ||
| prepareCompileData(exec, compileStats) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @GET | ||
| @Path("{executionId:\\d+}") | ||
| def compilerStat( | ||
| @PathParam("executionId") execId: Long): CompileData = { | ||
| withUI { ui => | ||
| val sqlStore = new SQLAppStatusStore(ui.store.store) | ||
| val compileStats = sqlStore.getCompilerStats(execId) | ||
| sqlStore | ||
| .execution(execId) | ||
| .map(prepareCompileData(_, compileStats)) | ||
| .getOrElse(throw new NotFoundException("unknown query execution id: " + execId)) | ||
| } | ||
| } | ||
|
|
||
| private def prepareCompileData( | ||
| exec: SQLExecutionUIData, | ||
| compileStats: String): CompileData = { | ||
|
|
||
| val phaseString = compileStats.split(QueryPlanningTracker.ruleHeader) | ||
| val phaseListStr = phaseString.head.split(QueryPlanningTracker.phaseHeader)(1). | ||
| split("\\r?\\n") | ||
| val phaseTimes = new ListBuffer[Phase]() | ||
| for(i <- 1 until phaseListStr.length by 2) { | ||
| val phaseStr = phaseListStr(i).split(":")(1).trim | ||
| val time = phaseListStr(i + 1).split(":")(1).trim | ||
| phaseTimes += Phase(phaseStr, time.toLong) | ||
| } | ||
|
|
||
| val rulesListStr = phaseString(1).trim().split("\\r?\\n") | ||
| val rules = new ListBuffer[Rule]() | ||
| for (i <- 0 until rulesListStr.length by 4) { | ||
| val name = rulesListStr(i).split(":")(1).trim | ||
| val time = rulesListStr(i + 1).split(":")(1).trim | ||
| val invocation = rulesListStr(i + 2).split(": ")(1).trim | ||
| val effective = rulesListStr(i + 3).split(": ")(1).trim | ||
| rules += Rule(name, time.toDouble, invocation.toLong, effective.toLong) | ||
| } | ||
|
|
||
| new CompileData( | ||
| exec.executionId, | ||
| phaseTimes.toSeq, | ||
| rules.toSeq) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should
offsetandlengthbe validated to be positive ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be needed. I added SqlCompilerResource.scala based on SqlResource.scala