Skip to content

Commit 3f3d30d

Browse files
committed
check if expectedColStats.size == filterStats.attributeStats.size
1 parent 881096c commit 3f3d30d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/FilterEstimation.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ case class FilterEstimation(plan: Filter, catalystConf: CatalystConf) extends Lo
662662
// If null values exists, we set it to partial overlap.
663663
(((maxLeft < minRight) || (maxRight < minLeft)) && allNotNull,
664664
(minLeft == minRight) && (maxLeft == maxRight) && allNotNull
665+
&& (colStatLeft.distinctCount == colStatRight.distinctCount)
665666
)
666667
}
667668

@@ -754,18 +755,16 @@ case class FilterEstimation(plan: Filter, catalystConf: CatalystConf) extends Lo
754755
// ^ filtered
755756
// |
756757
// newMaxLeft
757-
758-
759758
if (minLeft < minRight) {
760-
newMinLeft = colStatRight.min
761-
} else {
762-
newMinRight = colStatLeft.min
763-
}
764-
if (maxLeft < maxRight) {
765-
newMaxRight = colStatLeft.max
766-
} else {
767-
newMaxLeft = colStatRight.max
768-
}
759+
newMinLeft = colStatRight.min
760+
} else {
761+
newMinRight = colStatLeft.min
762+
}
763+
if (maxLeft < maxRight) {
764+
newMaxRight = colStatLeft.max
765+
} else {
766+
newMaxLeft = colStatRight.max
767+
}
769768
}
770769

771770
val newStatsLeft = colStatLeft.copy(distinctCount = newNdvLeft, min = newMinLeft,

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/statsEstimation/FilterEstimationSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ class FilterEstimationSuite extends StatsEstimationTestBase {
609609
if (rowCountValue != 0) {
610610
// Need to check attributeStats one by one because we may have multiple output columns.
611611
// Due to update operation, the output columns may be in different order.
612+
assert(expectedColStats.size == filterStats.attributeStats.size)
612613
expectedColStats.foreach { kv =>
613614
val filterColumnStat = filterStats.attributeStats.get(kv._1).get
614615
assert(filterColumnStat == kv._2)

0 commit comments

Comments
 (0)