Spenserrrr commented on code in PR #59892:
URL: https://github.com/apache/spark/pull/59892#discussion_r4548189166


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/PythonSQLMetrics.scala:
##########
@@ -21,14 +21,16 @@ import org.apache.spark.sql.execution.SparkPlan
 import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
 
 trait PythonSQLMetrics { self: SparkPlan =>
+  // Register all phase metrics; Python decides whether to collect them.
+  // A zero pythonNumTimingReports means detailed timing data is unavailable.
   protected val pythonMetrics: Map[String, SQLMetric] = {
     sizeMetricsDesc.map { case (k, v) =>
       k -> SQLMetrics.createSizeMetric(sparkContext, v)
     } ++ timingMetricsDesc.map { case (k, v) =>
       k -> SQLMetrics.createTimingMetric(sparkContext, v)
     } ++ otherMetricsDesc.map { case (k, v) =>
       k -> SQLMetrics.createMetric(sparkContext, v)
-    } ++ additionalMetrics
+    } ++ additionalMetrics ++ createPythonPhaseMetrics()

Review Comment:
   Moved phase registration into PythonPhaseMetrics. Ordinary state-store 
operators keep their existing metrics and get no phase fields. Python operators 
share the schema, with collection still gated in Python.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/PythonSQLMetrics.scala:
##########
@@ -21,14 +21,16 @@ import org.apache.spark.sql.execution.SparkPlan
 import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
 
 trait PythonSQLMetrics { self: SparkPlan =>
+  // Register all phase metrics; Python decides whether to collect them.

Review Comment:
   Updated the comment to describe the opt-in phase trait. Pickle-specific 
fields still stay in their own trait.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/python/ArrowEvalPythonExec.scala:
##########
@@ -90,20 +89,8 @@ case class ArrowEvalPythonExec(
     throw SparkException.internalError(s"Unexpected eval type $evalType")
   }
 
-  override protected def additionalMetrics: Map[String, SQLMetric] = {
-    if (evalType == PythonEvalType.SQL_ARROW_BATCHED_UDF &&
-        !conf.legacyPandasConversionUDF && 
conf.pythonUDFDetailedTimingEnabled) {
-      createPythonPhaseMetrics()
-    } else {
-      Map.empty
-    }
-  }
-
-  // SQL metrics are fixed with the plan; use that decision if the session 
setting changes later.
   private def pythonRunnerConfMap: Map[String, String] =
-    ArrowPythonRunner.getPythonRunnerConfMap(conf).updated(
-      SQLConf.PYTHON_UDF_DETAILED_TIMING_ENABLED.key,
-      pythonMetrics.contains("pythonNumTimingReports").toString)
+    ArrowPythonRunner.getPythonRunnerConfMap(conf)

Review Comment:
   Yes, execution-time behavior is intentional. Scala forwards the setting 
unchanged, and the phase schema is registered independently. Added this 
behavior change to the PR description.



##########
python/pyspark/eval_handlers/_base.py:
##########
@@ -170,6 +175,11 @@ def __init__(
         self._udf_descs: list[Any] = udf_descs
         self._runner_conf = runner_conf
         self._eval_conf = eval_conf
+        self._detailed_timing_enabled = (
+            self._supports_detailed_timing
+            and runner_conf.detailed_timing_enabled
+            and os.environ.get("SPARK_PIPELINED_UDF") != "1"

Review Comment:
   Added RunnerConf.is_pipelined and use it in both the worker and the handler 
base.



##########
python/pyspark/eval_handlers/_pandas.py:
##########
@@ -243,49 +246,112 @@ def __init__(
         )
 
     def run(self, split_index: int, data: "Iterator[pa.RecordBatch]") -> 
"Iterator[pa.RecordBatch]":
+        metrics = WorkerMetrics()
+        phase_timers = self._create_phase_timers()
+        if phase_timers is not None:
+            # If the UDF never pulls from its lazy input iterator, the 
serializer's load_stream()
+            # may never start, leaving the read timer unregistered. Register a 
zero for that case.
+            metrics.measure("pythonDataReadTime")

Review Comment:
   Removed the explicit zero registration.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to