cloud-fan commented on code in PR #47516:
URL: https://github.com/apache/spark/pull/47516#discussion_r1699302256


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/metric/SQLMetrics.scala:
##########
@@ -96,9 +96,12 @@ class SQLMetric(
 
   def +=(v: Long): Unit = add(v)
 
-  // _value may be uninitialized, in many cases being -1. We should not expose 
it to the user
-  // and instead return 0.
-  override def value: Long = if (isZero) 0 else _value
+  // We use -1 as initial value of the SIZE and TIMIMG accumulators (0 is a 
valid metric value).
+  // We need to return it as it is so that the SQL UI can filter out the 
invalid accumulator
+  // values in `SQLMetrics.stringValue` when calculating min, max, etc.
+  // However, users accessing the values in the physical plan programmatically 
still gets -1. They
+  // may use `SQLMetric.isZero` before consuming this value.
+  override def value: Long = _value

Review Comment:
   `-1` is an internal initial value, and we can't expose it to users. People 
can get the physical plan and directly access the `SQLMetrics` instances to get 
the values. 



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