You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/22 18:26:21 UTC

[GitHub] [spark] yliou opened a new pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

yliou opened a new pull request #35939:
URL: https://github.com/apache/spark/pull/35939


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   The changes proposed are to add a clickable field on SQL UI to show timing of spark phases and rule timing information from QueryPlanningTracker along with a separate REST endpoint to show the timing statistics. Adds a SQLConf to control the number of rules that show up on the UI and the REST endpoint call (default value is 50).
   UI Change: <img width="526" alt="Screen Shot 2022-03-21 at 11 59 16 AM" src="https://user-images.githubusercontent.com/16739760/159543084-fd215952-e423-407c-8b3c-59f156f14699.png">
   New REST API endpoint output: [SPARK38617.txt](https://github.com/apache/spark/files/8326833/SPARK38617.txt)
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   Currently user is unable to see Spark phase timing information or which Spark rules take the most time for a specific query execution on the UI. This PR adds that information.
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes on the UI
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   Tested locally and added a class to test the new endpoint.
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1076930612


   > #35856 has tried the similar things although at present it miss the details of the compile time for each phase. And its scope also includes the AQE, I think is good to go.
   
   What does good to go mean here as I don't see an approval at #35856? From what I see the changes at #35856 are different and complimentary with this PR as that PR adds information regarding AQE plan description changes and this PR has timing of spark phases and rule timing information.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r833733430



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/QueryPlanningTracker.scala
##########
@@ -160,4 +162,23 @@ class QueryPlanningTracker {
     }
   }
 
+  override def toString(): String = {

Review comment:
       Renamed method to compileStatsString




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r833623186



##########
File path: sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlCompileResourceSuite.scala
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 java.net.URL
+import java.text.SimpleDateFormat
+
+import org.json4s.DefaultFormats
+import org.json4s.jackson.JsonMethods
+import org.scalatest.PrivateMethodTester
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.history.HistoryServerSuite.getContentAndCode
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.catalyst.plans.SQLHelper
+import org.apache.spark.sql.execution.metric.SQLMetricsTestUtils
+import org.apache.spark.sql.internal.SQLConf.ADAPTIVE_EXECUTION_ENABLED
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * Sql Resource Public API Unit Tests running query and extracting the metrics.
+ */
+class SqlCompileResourceSuite
+  extends SharedSparkSession with SQLMetricsTestUtils with SQLHelper with PrivateMethodTester {
+
+  import testImplicits._
+  implicit val formats = new DefaultFormats {
+    override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
+  }
+  override def sparkConf: SparkConf = {
+    super.sparkConf.set("spark.ui.enabled", "true")
+  }
+
+  test("Check Compile Stat Rest Api Endpoints") {
+    // Materalize result DataFrame
+    withSQLConf(ADAPTIVE_EXECUTION_ENABLED.key -> "true") {
+      val count = getDF().count()
+      assert(count == 2, s"Expected Query Count is 2 but received: $count")
+    }
+
+    // Spark apps launched by local-mode seems not having `attemptId` as default
+    // so UT is just added for existing endpoints.
+    val executionId = callCompilerStatRestEndpointAndVerifyResult()
+    callCompilerStatRestEndpointByExecutionIdAndVerifyResult(executionId)
+  }
+
+  private def callCompilerStatRestEndpointAndVerifyResult(): Long = {
+    val url = new URL(spark.sparkContext.ui.get.webUrl
+      + s"/api/v1/applications/${spark.sparkContext.applicationId}/compiler")
+    val jsonResult = verifyAndGetCompileStatRestResult(url)
+    val compilerStats = JsonMethods.parse(jsonResult).extract[Seq[CompileData]]
+    assert(compilerStats.size > 0,
+      s"Expected Query Result Size is higher than 0 but received: ${compilerStats.size}")
+    val compilerStatData = compilerStats.head
+    verifyCompilerStatRestContent(compilerStatData)
+    compilerStatData.id
+  }
+
+  private def callCompilerStatRestEndpointByExecutionIdAndVerifyResult(executionId: Long): Unit = {
+    val url = new URL(spark.sparkContext.ui.get.webUrl
+      + s"/api/v1/applications/${spark.sparkContext.applicationId}/compiler/${executionId}")
+    val jsonResult = verifyAndGetCompileStatRestResult(url)
+    val compilerStatData = JsonMethods.parse(jsonResult).extract[CompileData]
+    verifyCompilerStatRestContent(compilerStatData)
+  }
+
+  private def verifyCompilerStatRestContent(compileStats: CompileData): Unit = {
+    assert(compileStats.appID != "", "Should have valid application ID")
+    assert(compileStats.id > -1,
+      s"Expected execution ID is valid, found ${compileStats.id}")
+    assert(compileStats.ruleInfo.length == 50,
+      s"Expected number of Spark rules is 50, found ${compileStats.ruleInfo.length}")
+    assert(compileStats.phaseInfo.length == 3,
+      s"Expected number of phase info is: 3 found ${compileStats.phaseInfo.length}")
+  }
+
+  private def verifyAndGetCompileStatRestResult(url: URL): String = {
+    val (code, resultOpt, error) = getContentAndCode(url)
+    assert(code == 200, s"Expected Http Response Code is 200 but received: $code for url: $url")
+    assert(resultOpt.nonEmpty, s"Rest result should not be empty for url: $url")
+    assert(error.isEmpty, s"Error message should be empty for url: $url")
+    resultOpt.get
+  }
+
+  private def getDF(): DataFrame = {
+    val person: DataFrame =
+      spark.sparkContext.parallelize(
+        Person(0, "mike", 30) ::
+          Person(1, "jim", 20) :: Nil).toDF()
+
+    val salary: DataFrame =
+      spark.sparkContext.parallelize(
+        Salary(0, 2000.0) ::
+          Salary(1, 1000.0) :: Nil).toDF()
+
+    val salaryDF = salary.withColumnRenamed("personId", "id")
+    val ds = person.join(salaryDF, "id")
+      .groupBy("name", "age", "salary").avg("age", "salary")
+      .filter(_.getAs[Int]("age") <= 30)

Review comment:
       Yes




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] martin-g commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
martin-g commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r832563681



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLAppStatusStore.scala
##########
@@ -79,6 +80,14 @@ class SQLAppStatusStore(
   def planGraph(executionId: Long): SparkPlanGraph = {
     store.read(classOf[SparkPlanGraphWrapper], executionId).toSparkPlanGraph()
   }
+
+  def getCompilerStats(executionId: Long): QueryPlanningTracker = {
+    try {
+      store.read(classOf[CompilerStats], executionId).queryStats
+    } catch {
+      case _: NoSuchElementException => new QueryPlanningTracker()

Review comment:
       In what cases this exception might be thrown ? I guess when `#read()` cannot find it.
   It is weird that it does not return an `Option` or `Either`.
   Also `planGraph()` and `executionsList()` above do not try to recover. 
   `def execution(executionId: Long)` does the same as here.
   IMO this class needs some love.

##########
File path: sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlCompilerResource.scala
##########
@@ -0,0 +1,82 @@
+/*
+ * 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 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.sql.internal.SQLConf
+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)
+      val appid = ui.store.environmentInfo().sparkProperties.toMap.getOrElse("spark.app.id", "")
+      sqlStore.executionsList(offset, length).map { exec =>

Review comment:
       should `offset` and `length` be validated to be positive ?

##########
File path: sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlCompileResourceSuite.scala
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 java.net.URL
+import java.text.SimpleDateFormat
+
+import org.json4s.DefaultFormats
+import org.json4s.jackson.JsonMethods
+import org.scalatest.PrivateMethodTester
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.history.HistoryServerSuite.getContentAndCode
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.catalyst.plans.SQLHelper
+import org.apache.spark.sql.execution.metric.SQLMetricsTestUtils
+import org.apache.spark.sql.internal.SQLConf.ADAPTIVE_EXECUTION_ENABLED
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * Sql Resource Public API Unit Tests running query and extracting the metrics.
+ */
+class SqlCompileResourceSuite
+  extends SharedSparkSession with SQLMetricsTestUtils with SQLHelper with PrivateMethodTester {
+
+  import testImplicits._
+  implicit val formats = new DefaultFormats {
+    override def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
+  }
+  override def sparkConf: SparkConf = {
+    super.sparkConf.set("spark.ui.enabled", "true")
+  }
+
+  test("Check Compile Stat Rest Api Endpoints") {
+    // Materalize result DataFrame
+    withSQLConf(ADAPTIVE_EXECUTION_ENABLED.key -> "true") {
+      val count = getDF().count()
+      assert(count == 2, s"Expected Query Count is 2 but received: $count")
+    }
+
+    // Spark apps launched by local-mode seems not having `attemptId` as default
+    // so UT is just added for existing endpoints.
+    val executionId = callCompilerStatRestEndpointAndVerifyResult()
+    callCompilerStatRestEndpointByExecutionIdAndVerifyResult(executionId)
+  }
+
+  private def callCompilerStatRestEndpointAndVerifyResult(): Long = {
+    val url = new URL(spark.sparkContext.ui.get.webUrl
+      + s"/api/v1/applications/${spark.sparkContext.applicationId}/compiler")
+    val jsonResult = verifyAndGetCompileStatRestResult(url)
+    val compilerStats = JsonMethods.parse(jsonResult).extract[Seq[CompileData]]
+    assert(compilerStats.size > 0,
+      s"Expected Query Result Size is higher than 0 but received: ${compilerStats.size}")
+    val compilerStatData = compilerStats.head
+    verifyCompilerStatRestContent(compilerStatData)
+    compilerStatData.id
+  }
+
+  private def callCompilerStatRestEndpointByExecutionIdAndVerifyResult(executionId: Long): Unit = {
+    val url = new URL(spark.sparkContext.ui.get.webUrl
+      + s"/api/v1/applications/${spark.sparkContext.applicationId}/compiler/${executionId}")
+    val jsonResult = verifyAndGetCompileStatRestResult(url)
+    val compilerStatData = JsonMethods.parse(jsonResult).extract[CompileData]
+    verifyCompilerStatRestContent(compilerStatData)
+  }
+
+  private def verifyCompilerStatRestContent(compileStats: CompileData): Unit = {
+    assert(compileStats.appID != "", "Should have valid application ID")
+    assert(compileStats.id > -1,
+      s"Expected execution ID is valid, found ${compileStats.id}")
+    assert(compileStats.ruleInfo.length == 50,
+      s"Expected number of Spark rules is 50, found ${compileStats.ruleInfo.length}")
+    assert(compileStats.phaseInfo.length == 3,
+      s"Expected number of phase info is: 3 found ${compileStats.phaseInfo.length}")
+  }
+
+  private def verifyAndGetCompileStatRestResult(url: URL): String = {
+    val (code, resultOpt, error) = getContentAndCode(url)
+    assert(code == 200, s"Expected Http Response Code is 200 but received: $code for url: $url")
+    assert(resultOpt.nonEmpty, s"Rest result should not be empty for url: $url")
+    assert(error.isEmpty, s"Error message should be empty for url: $url")
+    resultOpt.get
+  }
+
+  private def getDF(): DataFrame = {
+    val person: DataFrame =
+      spark.sparkContext.parallelize(
+        Person(0, "mike", 30) ::
+          Person(1, "jim", 20) :: Nil).toDF()
+
+    val salary: DataFrame =
+      spark.sparkContext.parallelize(
+        Salary(0, 2000.0) ::
+          Salary(1, 1000.0) :: Nil).toDF()
+
+    val salaryDF = salary.withColumnRenamed("personId", "id")
+    val ds = person.join(salaryDF, "id")
+      .groupBy("name", "age", "salary").avg("age", "salary")
+      .filter(_.getAs[Int]("age") <= 30)

Review comment:
       the filtering filters nothing with the provided two persons. Is this intentional ?

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/QueryPlanningTracker.scala
##########
@@ -160,4 +162,23 @@ class QueryPlanningTracker {
     }
   }
 
+  override def toString(): String = {

Review comment:
       IMO it would be better to use a new method instead of overwriting `#toString()`.
   `toString` might be called implicitly somewhere and cause performance issue. I have seen this in the wild few times.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1075822811


   https://github.com/apache/spark/pull/35856 has tried the similar things although at present it miss the details of the compile time for each phase. And its scope also includes the AQE, I think is good to go.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r833694559



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/ui/SQLAppStatusStore.scala
##########
@@ -79,6 +80,14 @@ class SQLAppStatusStore(
   def planGraph(executionId: Long): SparkPlanGraph = {
     store.read(classOf[SparkPlanGraphWrapper], executionId).toSparkPlanGraph()
   }
+
+  def getCompilerStats(executionId: Long): QueryPlanningTracker = {
+    try {
+      store.read(classOf[CompilerStats], executionId).queryStats
+    } catch {
+      case _: NoSuchElementException => new QueryPlanningTracker()

Review comment:
       I added this try catch statement as a precaution after adding the if statement on SQLAppStatusListener.scala:393. Some unit tests were failing without the if statement. I can remove the try catch statement if desired.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] ulysses-you commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1076983958


   @yliou  I agree both can help for troubleshooting. And I have mentioned the difference, `it miss the details of the compile time for each phase`. That PR introduces a disk-based store so I'm thinking if can re-use the same code path. IMO it would be better to go with that PR first at least.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sigmod edited a comment on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
sigmod edited a comment on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1077345065


   Can we use a more meaningful JSON field names? E.g.,
   `value` -> `timeMs`
   `name` -> `phase`
   
    ```
   {
       “phase” : “optimization”,
       “timeMs” : “373"
     }, {
       “phase” : “analysis”,
       “timeMs” : “12"
     } ],
     “ruleInfo” : [ {
       “ruleName” : “org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation”,
       “timeMs” : “32.659566”,
       “numInvocations” : 5,
       “numEffectiveInvocations” : 3
     }, 
     ....
   ]
   
   ```
   
   Also, can `timeMs` be a number instead of a string?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sigmod edited a comment on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
sigmod edited a comment on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1077345065


   Can we use a more meaning JSON field names? E.g.,
   `value` -> `timeMs`
   `name` -> `phase`
   
    ```
   {
       “phase” : “optimization”,
       “timeMs” : “373"
     }, {
       “phase” : “analysis”,
       “timeMs” : “12"
     } ],
     “ruleInfo” : [ {
       “ruleName” : “org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation”,
       “timeMs” : “32.659566”,
       “numInvocations” : 5,
       “numEffectiveInvocations” : 3
     }, 
     ....
   ]
   
   ```
   
   Also, can `timeMs` be a number instead of a string?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] jchen5 commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
jchen5 commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r834372302



##########
File path: sql/core/src/test/scala/org/apache/spark/status/api/v1/sql/SqlCompileResourceSuite.scala
##########
@@ -0,0 +1,119 @@
+/*
+ * 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 java.net.URL
+import java.text.SimpleDateFormat
+
+import org.json4s.DefaultFormats
+import org.json4s.jackson.JsonMethods
+import org.scalatest.PrivateMethodTester
+
+import org.apache.spark.SparkConf
+import org.apache.spark.deploy.history.HistoryServerSuite.getContentAndCode
+import org.apache.spark.sql.DataFrame
+import org.apache.spark.sql.catalyst.plans.SQLHelper
+import org.apache.spark.sql.execution.metric.SQLMetricsTestUtils
+import org.apache.spark.sql.internal.SQLConf.ADAPTIVE_EXECUTION_ENABLED
+import org.apache.spark.sql.test.SharedSparkSession
+
+/**
+ * Sql Resource Public API Unit Tests running query and extracting the metrics.
+ */
+class SqlCompileResourceSuite

Review comment:
       The class name mismatches: SqlCompilerResource vs SqlCompileResourceSuite (the r in compiler, typo?)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1076836718


   > [SPARK38617.txt](https://github.com/apache/spark/files/8326833/SPARK38617.txt) is in rich text format. It would be easier to review if it was plain text.
   
   Attached new file with plain text format.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sigmod commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
sigmod commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1076950577


   cc @jchen5


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sigmod edited a comment on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
sigmod edited a comment on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1077345065


   Can we use a more meaning JSON field names? E.g.,
   `value` -> `timeMs`
   `name` -> `phase`
   
    ```
   {
       “phase” : “optimization”,
       “timeMs” : “373"
     }, {
       “phase” : “analysis”,
       “timeMs” : “12"
     } ],
     “ruleInfo” : [ {
       “ruleName” : “org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation”,
       “timeMs” : “32.659566”,
       “numInvocations” : 5,
       “numEffectiveInvocations” : 3
     }, 
     ....
   ]
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] martin-g commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
martin-g commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1075556413


   [SPARK38617.txt](https://github.com/apache/spark/files/8326833/SPARK38617.txt) is in rich text format. It would be easier to review if it was plain text.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] mridulm commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
mridulm commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1077008699


   +CC @shardulm94, @thejdeep


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] sigmod commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
sigmod commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1077345065


   Can we use a more meaning JSON field names? E.g.,
   `value` -> `timeMs`
   `name` -> `phase`
   
    ```
   {
       “name” : “optimization”,
       “value” : “373"
     }, {
       “name” : “analysis”,
       “value” : “12"
     } ],
     “ruleInfo” : [ {
       “ruleName” : “org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation”,
       “value” : “32.659566”,
       “numInvocations” : 5,
       “numEffectiveInvocations” : 3
     }, 
     ....
   ]
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] linhongliu-db commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
linhongliu-db commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1080107483


   @ulysses-you @yliou adding debug information is always good. But I'm worried about two issues:
   1. we should be careful when adding information to live UI's in-memory KV store. sooner or later, it will bring headaches
   2. we should be careful when adding new REST API endpoints. since two PRs both for troubleshooting, maybe we can use the same endpoint.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1078296130


   @ulysses-you got it. I think it is possible to re-use the same code path but not sure how that'd work with ExecutionPage.scala to get the info on the UI.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1078470309


   > Can we use a more meaningful JSON field names? E.g., `value` -> `timeMs` `name` -> `phase`
   > 
   > ```
   > {
   >    “phase” : “optimization”,
   >    “timeMs” : “373"
   >  }, {
   >    “phase” : “analysis”,
   >    “timeMs” : “12"
   >  } ],
   >  “ruleInfo” : [ {
   >    “ruleName” : “org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation”,
   >    “timeMs” : “32.659566”,
   >    “numInvocations” : 5,
   >    “numEffectiveInvocations” : 3
   >  }, 
   >  ....
   > ]
   > ```
   > 
   > Also, can `timeMs` be a number instead of a string?
   
   Updated Json field names and changed `timeMs` to be a number


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou edited a comment on pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou edited a comment on pull request #35939:
URL: https://github.com/apache/spark/pull/35939#issuecomment-1076930612


   > #35856 has tried the similar things although at present it miss the details of the compile time for each phase. And its scope also includes the AQE, I think is good to go.
   
   What does good to go mean here as I don't see an approval at #35856? From what I see the changes at #35856 are different and complimentary with this PR as that PR adds information regarding AQE plan description changes and this PR has timing of spark phases and rule timing information. The changes in both PRs will help for troubleshooting.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] yliou commented on a change in pull request #35939: [SPARK-38617][SQL][WEBUI] Show Spark rule and phase timings in SQL UI and REST API

Posted by GitBox <gi...@apache.org>.
yliou commented on a change in pull request #35939:
URL: https://github.com/apache/spark/pull/35939#discussion_r833624430



##########
File path: sql/core/src/main/scala/org/apache/spark/status/api/v1/sql/SqlCompilerResource.scala
##########
@@ -0,0 +1,82 @@
+/*
+ * 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 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.sql.internal.SQLConf
+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)
+      val appid = ui.store.environmentInfo().sparkProperties.toMap.getOrElse("spark.app.id", "")
+      sqlStore.executionsList(offset, length).map { exec =>

Review comment:
       It shouldn't be needed. I added SqlCompilerResource.scala based on SqlResource.scala




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org