zabetak commented on code in PR #3975: URL: https://github.com/apache/calcite/pull/3975#discussion_r1774750880
########## core/src/test/java/org/apache/calcite/test/RelMetadataTest.java: ########## @@ -2593,6 +2593,31 @@ private void checkPredicates(RelOptCluster cluster, RelOptTable empTable, } + /** Test case for + * <a href="https://issues.apache.org/jira/browse/CALCITE-6592">[CALCITE-6592] + * RelMdPredicates pull up wrong predicate from UNION when it's input include NULL VALUE</a>. */ + @Test void testPullUpPredicatesFromUnionWithValues1() { + final String sql = "select cast(null as integer) as a\n" + + "union all\n" + + "select 5 as a"; + final Union rel = (Union) sql(sql).toRel(); + final RelMetadataQuery mq = rel.getCluster().getMetadataQuery(); + RelOptPredicateList inputSet = mq.getPulledUpPredicates(rel); + ImmutableList<RexNode> pulledUpPredicates = inputSet.pulledUpPredicates; + assertThat(pulledUpPredicates, sortsAs("[OR(null, =($0, 5))]")); Review Comment: The result does not look 100% accurate. Shouldn't this rather be `OR(IS NULL($0), =($0, 5))`. What happens if there were more columns involved? ########## core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java: ########## @@ -475,7 +475,7 @@ public RelOptPredicateList getPredicates(Union union, RelMetadataQuery mq) { RexNode disjunctivePredicate = new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY, executor) .simplifyUnknownAs(rexBuilder.makeCall(SqlStdOperatorTable.OR, finalResidualPredicates), - RexUnknownAs.FALSE); Review Comment: Some methods in this class are considering `RexUnknownAs.FALSE` and some others `RexUnknownAs.UNKNOWN` when performing the simplification. Why do we need to simplify differently? -- 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]
