mgaido91 commented on a change in pull request #23803: [SPARK-26894][SQL] 
Handle Alias as well in AggregateEstimation to propagate child stats
URL: https://github.com/apache/spark/pull/23803#discussion_r258371384
 
 

 ##########
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/statsEstimation/AggregateEstimationSuite.scala
 ##########
 @@ -45,6 +45,34 @@ class AggregateEstimationSuite extends 
StatsEstimationTestBase with PlanTest {
   private val nameToColInfo: Map[String, (Attribute, ColumnStat)] =
     columnInfo.map(kv => kv._1.name -> kv)
 
+  test("aggregate with alias") {
+    val tableColumns = Seq("key11", "key12")
+    val groupByColumns = Seq("key11")
+    val attributes = groupByColumns.map(nameToAttr)
+
+    val rowCount = 2
+    val child = StatsTestPlan(
+      outputList = tableColumns.map(nameToAttr),
+      rowCount,
+      // rowCount * (overhead + column size)
+      size = Some(4 * (8 + 4)),
+      attributeStats = AttributeMap(tableColumns.map(nameToColInfo)))
+
+    val testAgg = Aggregate(
+      groupingExpressions = attributes,
+      aggregateExpressions = Seq(Alias(nameToAttr("key12"), "abc")()),
+      child)
+
+    val expectedColStats = Seq("abc" -> nameToColInfo("key12")._2)
+    val expectedAttrStats = toAttributeMap(expectedColStats, testAgg)
+
+    val expectedStats = Statistics(
+      sizeInBytes = getOutputSize(testAgg.output, rowCount, expectedAttrStats),
+      rowCount = Some(rowCount),
+      attributeStats = expectedAttrStats)
+    assert(testAgg.stats == expectedStats)
 
 Review comment:
   since we are actually interested in checking only the `attributeStats`, what 
about `assert(testAgg.stats.attributeStats == expectedAttrStats)`? This way we 
can also skip creating the `Statistics` class above..

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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