You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/11/28 12:51:31 UTC

[GitHub] [spark] ayushi-agarwal commented on a change in pull request #30334: [SPARK-33411][SQL] Cardinality estimation of union, sort and range operator

ayushi-agarwal commented on a change in pull request #30334:
URL: https://github.com/apache/spark/pull/30334#discussion_r532036824



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala
##########
@@ -545,7 +545,33 @@ case class Range(
   }
 
   override def computeStats(): Statistics = {
-    Statistics(sizeInBytes = LongType.defaultSize * numElements)
+    val minVal = if (step > 0) {
+      start
+    } else {
+      start + (numElements - 1) * step
+    }
+
+    val maxVal = if (step > 0) {
+      start + (numElements - 1) * step
+    } else {
+      start
+    }
+
+    Statistics(
+      sizeInBytes = LongType.defaultSize * numElements,
+      rowCount = Some(numElements),
+      attributeStats = AttributeMap(
+        output.map(
+          a =>
+            (
+              a,
+              ColumnStat(
+                distinctCount = Some(numElements),
+                max = Some(maxVal),
+                min = Some(minVal),
+                nullCount = Some(0),
+                avgLen = Some(LongType.defaultSize),
+                maxLen = Some(LongType.defaultSize))))))

Review comment:
       Formatted

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
##########
@@ -531,7 +531,7 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
 
       // Cache the view then analyze it
       sql("CACHE TABLE tempView")
-      assert(getStatAttrNames("tempView") !== Set("id"))
+      assert(getStatAttrNames("tempView") === Set("id"))

Review comment:
       Updated

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/StatisticsCollectionSuite.scala
##########
@@ -553,7 +553,7 @@ class StatisticsCollectionSuite extends StatisticsCollectionTestBase with Shared
 
       // Cache the view then analyze it
       sql(s"CACHE TABLE $globalTempDB.gTempView")
-      assert(getStatAttrNames(s"$globalTempDB.gTempView") !== Set("id"))
+      assert(getStatAttrNames(s"$globalTempDB.gTempView") === Set("id"))

Review comment:
       Done




----------------------------------------------------------------
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:
users@infra.apache.org



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