Github user ron8hu commented on a diff in the pull request: https://github.com/apache/spark/pull/16696#discussion_r99474494 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/statsEstimation/StatsEstimationSuite.scala --- @@ -18,12 +18,41 @@ package org.apache.spark.sql.catalyst.statsEstimation import org.apache.spark.sql.catalyst.CatalystConf -import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeMap, AttributeReference} -import org.apache.spark.sql.catalyst.plans.logical.{ColumnStat, LogicalPlan, Statistics} +import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeMap, AttributeReference, Literal} +import org.apache.spark.sql.catalyst.plans.logical._ import org.apache.spark.sql.types.IntegerType -class StatsConfSuite extends StatsEstimationTestBase { +class StatsEstimationSuite extends StatsEstimationTestBase { + val (ar, colStat) = (attr("key"), ColumnStat(distinctCount = 10, min = Some(1), max = Some(10), + nullCount = 0, avgLen = 4, maxLen = 4)) + + val plan = StatsTestPlan( + outputList = Seq(ar), + attributeStats = AttributeMap(Seq(ar -> colStat)), + rowCount = 10, + size = Some(10 * (8 + 4))) + + test("limit estimation") { + val localLimit = LocalLimit(Literal(2), plan) + val globalLimit = GlobalLimit(Literal(2), plan) + // LocalLimit and GlobalLimit share the same stats estimation logic. + val expected = Statistics(sizeInBytes = 24, rowCount = Some(2)) + checkStats(localLimit, expected) + checkStats(globalLimit, expected) + } + + test("sample estimation") { + val sample = Sample(0.0, 0.5, withReplacement = false, (math.random * 1000).toLong, plan)() + checkStats(sample, expected = Statistics(sizeInBytes = 60, rowCount = Some(5))) + + // Test if Sample's child doesn't have rowCount in stats + val stats2 = Statistics(sizeInBytes = 120) --- End diff -- For limit estimation test cases, we may add a test with limit number greater than a child node's row count. This test can show if we properly select the smaller value between limit number child node's row count.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org