godfreyhe commented on a change in pull request #12873: URL: https://github.com/apache/flink/pull/12873#discussion_r454853388
########## File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/FlinkCalcMergeRule.scala ########## @@ -60,9 +61,40 @@ class FlinkCalcMergeRule(relBuilderFactory: RelBuilderFactory) extends RelOptRul return false } - // Don't merge Calcs which contain non-deterministic expr - topProgram.getExprList.forall(RexUtil.isDeterministic) && - bottomCalc.getProgram.getExprList.forall(RexUtil.isDeterministic) + // Each bottomCalc's non-deterministic RexNode should appear at most once in + // topCalc's project fields and condition field. + val bottomProgram = bottomCalc.getProgram + val topProjectRexNodesInputs = topProgram.getProjectList + .map(r => topProgram.expandLocalRef(r)) + .map(r => InputFinder.bits(r).toArray) + + val topFilterRexNodesInputs = if (topProgram.getCondition != null) { + InputFinder.bits(topProgram.expandLocalRef(topProgram.getCondition)) + .toArray Review comment: nit: put them just one line ? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org