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


##########
python/pyspark/sql/profiler.py:
##########
@@ -202,8 +206,20 @@ 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":
+            # The root id groups all micro-batches of a streaming query 
together. It is not
+            # set when the UDF does not run in a SQL query, e.g. under 
`df.rdd`.
+            root_id = tc.getLocalProperty("spark.sql.execution.root.id")
+            return f"sampling_query_{root_id if root_id is not None else 
'unknown'}"
+        elif self._aggregation == "stage":
+            return f"sampling_stage_{tc.stageId()}"

Review Comment:
   Fixed in #60259 (SPARK-61293): one module-level lock is shared by 
`_ProfileResultsParamV2.addInPlace` and the classic collector's reads and 
clears, with a deterministic regression test.



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