gatorsmile commented on a change in pull request #24286: [SPARK-27351][SQL] 
Wrong outputRows estimation after AggregateEstimation with only null value 
column
URL: https://github.com/apache/spark/pull/24286#discussion_r277223008
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/AggregateEstimation.scala
 ##########
 @@ -39,8 +39,16 @@ object AggregateEstimation {
       // Multiply distinct counts of group-by columns. This is an upper bound, 
which assumes
       // the data contains all combinations of distinct values of group-by 
columns.
       var outputRows: BigInt = agg.groupingExpressions.foldLeft(BigInt(1))(
-        (res, expr) => res *
-          
childStats.attributeStats(expr.asInstanceOf[Attribute]).distinctCount.get)
+        (res, expr) => {
+          val columnStat = 
childStats.attributeStats(expr.asInstanceOf[Attribute])
+          val distinctCount = columnStat.distinctCount.get
+          val distinctValue: BigInt = if (distinctCount == 0 && 
columnStat.nullCount.get > 0) {
+            1
+          } else {
+            distinctCount
 
 Review comment:
   If the nullCount is not empty, the value should be `distinctCount + 1`, 
right? 
   
   @pengbo @dongjoon-hyun 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to