Skip to content

Commit

Permalink
add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-wang committed Nov 29, 2018
1 parent 1c1edcc commit ca164b6
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.Literal.{FalseLiteral, TrueLiteral}
import org.apache.spark.sql.catalyst.plans.LeftOuter
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.plans.logical.statsEstimation.ColumnStatsMap
import org.apache.spark.sql.catalyst.plans.logical.statsEstimation.EstimationUtils._
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -821,6 +822,32 @@ class FilterEstimationSuite extends StatsEstimationTestBase {
expectedRowCount = 3)
}

test("ColumnStatsMap tests") {
val attrNoDistinct = AttributeReference("att_without_distinct", IntegerType)()
val attrNoCount = AttributeReference("att_without_count", BooleanType)()
val attrNoMinMax = AttributeReference("att_without_min_max", DateType)()
val colStatNoDistinct = ColumnStat(distinctCount = None, min = Some(1), max = Some(10),
nullCount = Some(0), avgLen = Some(4), maxLen = Some(4))
val colStatNoCount = ColumnStat(distinctCount = Some(2), min = Some(false), max = Some(true),
nullCount = None, avgLen = Some(1), maxLen = Some(1))
val colStatNoMinMax = ColumnStat(distinctCount = Some(0), min = None, max = None,
nullCount = Some(0), avgLen = None, maxLen = None)
val columnStatsMap = ColumnStatsMap(AttributeMap(Seq(
attrNoDistinct -> colStatNoDistinct,
attrNoCount -> colStatNoCount,
attrNoMinMax -> colStatNoMinMax
)))
assert(!columnStatsMap.hasDistinctCount(attrNoDistinct))
assert(columnStatsMap.hasDistinctCount(attrNoCount))
assert(columnStatsMap.hasDistinctCount(attrNoMinMax))
assert(columnStatsMap.hasCountStats(attrNoDistinct))
assert(!columnStatsMap.hasCountStats(attrNoCount))
assert(columnStatsMap.hasCountStats(attrNoMinMax))
assert(columnStatsMap.hasMinMaxStats(attrNoDistinct))
assert(columnStatsMap.hasMinMaxStats(attrNoCount))
assert(!columnStatsMap.hasMinMaxStats(attrNoMinMax))
}

private def childStatsTestPlan(outList: Seq[Attribute], tableRowCount: BigInt): StatsTestPlan = {
StatsTestPlan(
outputList = outList,
Expand Down

0 comments on commit ca164b6

Please sign in to comment.