xupefei commented on code in PR #45701:
URL: https://github.com/apache/spark/pull/45701#discussion_r1572263903
##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/SparkSession.scala:
##########
@@ -813,6 +823,28 @@ class SparkSession private[sql] (
* Set to false to prevent client.releaseSession on close() (testing only)
*/
private[sql] var releaseSessionOnClose = true
+
+ private[sql] def registerObservation(planId: Long, observation:
Observation): Unit = {
+ // makes this class thread-safe:
+ // only the first thread entering this block can set sparkSession
+ // all other threads will see the exception, as it is only allowed to do
this once
+ observation.synchronized {
+ if (observationRegistry.contains(planId)) {
+ throw new IllegalArgumentException("An Observation can be used with a
Dataset only once")
+ }
+ observationRegistry.put(planId, observation)
+ }
+ }
+
+ private[sql] def setMetricsAndUnregisterObservation(
+ planId: Long,
+ metrics: Option[Map[String, Any]]): Unit = {
+ observationRegistry.get(planId).map { observation =>
+ if (observation.setMetricsAndNotify(metrics)) {
+ observationRegistry.remove(planId)
Review Comment:
I looked at the code. It seems it's valid to check for non-empty metrics in
Spark Core:
```scala
private[spark] def onFinish(qe: QueryExecution): Unit = {
...
val row: Option[Row] = qe.observedMetrics.get(name)
val metrics: Option[Map[String, Any]] = row.map(r =>
r.getValuesMap[Any](r.schema.fieldNames.toImmutableArraySeq))
if (setMetricsAndNotify(metrics)) {
unregister()
}
}
```
The option is for a case when the query finishes without metric. Is this
possible?
--
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]