gaogaotiantian commented on code in PR #60150:
URL: https://github.com/apache/spark/pull/60150#discussion_r4544719738


##########
python/pyspark/sql/profiler.py:
##########
@@ -202,8 +206,23 @@ def _get_ident_from_frame(self, frame: FrameType) -> str:
         return f"{code.co_qualname} ({code.co_filename}:{code.co_firstlineno})"
 
     def _get_task_key(self) -> str:
+        # The "sampling_" prefix keeps these keys apart from the other 
profilers' keys,
+        # which are UDF result ids (int) or worker module names.
         tc = self._task_context
-        return 
f"{tc.stageId()}_{tc.partitionId()}.{tc.attemptNumber()}_{tc.taskAttemptId()}"
+        if self._aggregation == "query":
+            # Each micro-batch of a streaming query is its own SQL execution, 
so prefer the
+            # streaming query id to group all of them together. Neither id is 
set when the
+            # UDF does not run in a SQL query, e.g. under `df.rdd`.
+            query_id = tc.getLocalProperty("sql.streaming.queryId") or 
tc.getLocalProperty(
+                "spark.sql.execution.root.id"
+            )
+            return f"sampling_query_{query_id if query_id is not None else 
'unknown'}"
+        elif self._aggregation == "stage":
+            return f"sampling_stage_{tc.stageId()}"
+        else:

Review Comment:
   Done in 706910db277: `"task"` is now an explicit branch, and any other value 
raises `PySparkValueError` (`VALUE_NOT_ALLOWED`), the same way the other checks 
in this file do.
   



-- 
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