WangGuangxin commented on a change in pull request #26726: 
[SPARK-30088][SQL]Adaptive execution should convert SortMergeJoin to 
BroadcastJoin when plan generates empty result
URL: https://github.com/apache/spark/pull/26726#discussion_r353065731
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/QueryStageExec.scala
 ##########
 @@ -79,7 +79,9 @@ abstract class QueryStageExec extends LeafExecNode {
    */
   def computeStats(): Option[Statistics] = resultOption.map { _ =>
     // Metrics `dataSize` are available in both `ShuffleExchangeExec` and 
`BroadcastExchangeExec`.
-    Statistics(sizeInBytes = plan.metrics("dataSize").value)
+    // The `dataSize` metric may be a negative number when this spark plan 
generates empty result,
+    // since SQLMetric use -1 as initial value.
+    Statistics(sizeInBytes = Math.max(plan.metrics("dataSize").value, 0))
 
 Review comment:
   OK, I'll take over it

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to