ChengJie1053 commented on code in PR #27055:
URL: https://github.com/apache/flink/pull/27055#discussion_r2756965748


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/RemoveUnreachableCoalesceArgumentsRule.java:
##########
@@ -121,6 +130,57 @@ private int getFirstNonNullableArgumentIndex(RexCall call) 
{
             }
             return -1;
         }
+
+        private RexNode convertToCaseWhen(RexCall call) {
+            List<RexNode> operands = call.operands;
+
+            if (operands.size() == 1) {
+                return operands.get(0);
+            }
+
+            RexBuilder rexBuilder = this.rexBuilder;
+            ImmutableList.Builder<RexNode> caseArgs = ImmutableList.builder();
+
+            for (int i = 0; i < operands.size() - 1; i++) {
+                RexNode operand = operands.get(i);
+                RexNode isNotNullCheck =
+                        rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, 
operand);
+                caseArgs.add(isNotNullCheck);
+                caseArgs.add(operand);
+            }
+
+            caseArgs.add(operands.get(operands.size() - 1));
+
+            return rexBuilder.makeCall(SqlStdOperatorTable.CASE, 
caseArgs.build());
+        }
+
+        private boolean containsFunctionCalls(RexCall call) {
+            for (RexNode operand : call.operands) {
+                if (isFunctionCall(operand)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        private boolean isFunctionCall(RexNode node) {
+            return node instanceof RexCall
+                    && !isSimpleCast((RexCall) node)
+                    && !isFieldReference(node)
+                    && !isLiteral(node);

Review Comment:
   Thank you for the detailed review and suggestions! I'll address all of them: 
reorder the operands.size() == 1 check before the containsFunctionCalls block, 
use SqlKind for the CAST check instead of name, improve 
isFieldReference/isLiteral to account for RexVariable and similar cases, and 
refactor containsFunctionCalls as you suggested. I'll push the updates soon. 
Thanks again!



-- 
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]

Reply via email to