cyanzheng2926 commented on code in PR #6553:
URL: https://github.com/apache/hive/pull/6553#discussion_r3464655229
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java:
##########
@@ -160,6 +159,33 @@ public Double visitCall(RexCall call) {
break;
}
+ case IS_NULL: {
+ if (childRel instanceof HiveTableScan) {
+ HiveTableScan hiveTableScan = (HiveTableScan) childRel;
+ if (hasMissingColumnStats(call, hiveTableScan)) {
+ selectivity = DEFAULT_COMPARISON_SELECTIVITY;
+ break;
+ }
+ double noOfNulls = getMaxNulls(call, hiveTableScan);
+ if (childCardinality >= noOfNulls) {
Review Comment:
Done
##########
ql/src/test/org/apache/hadoop/hive/ql/optimizer/calcite/stats/TestFilterSelectivityEstimator.java:
##########
@@ -1116,6 +1116,32 @@ public void testBetweenWithCastToDecimal7s1() {
checkBetweenSelectivity(0, universe, total, cast, 100f, 0f);
}
+ @Test
+ public void testComputeIsNullSelectivityWithStats() {
+ stats.setNumNulls(3);
+
doReturn(Collections.singletonList(stats)).when(tableMock).getColStat(Collections.singletonList(0));
+ RexNode filter = REX_BUILDER.makeCall(SqlStdOperatorTable.IS_NULL,
inputRef0);
+ checkSelectivity(3f / VALUES.length, filter); // 3 / 13
+ }
+
+ @Test
+ public void testComputeIsNullSelectivityMissingStats() {
+
doReturn(Collections.emptyList()).when(tableMock).getColStat(Collections.singletonList(0));
+ RexNode filter = REX_BUILDER.makeCall(SqlStdOperatorTable.IS_NULL,
inputRef0);
+ checkSelectivity(1f / 3f, filter); // DEFAULT_COMPARISON_SELECTIVITY
+ }
+
+ @Test
+ public void testComputeIsNullSelectivityEstimatedStatsFallback() {
+ ColStatistics estimated = new ColStatistics();
+ estimated.setIsEstimated(true);
+ estimated.setNumNulls(0);
+
doReturn(Collections.singletonList(estimated)).when(tableMock).getColStat(Collections.singletonList(0));
+ RexNode filter = REX_BUILDER.makeCall(SqlStdOperatorTable.IS_NULL,
inputRef0);
+ // estimated stats should be treated as missing and fallback to
DEFAULT_COMPARISON_SELECTIVITY
+ checkSelectivity(1f / 3f, filter);
+ }
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]