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


##########
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);
+        }
+
+        private boolean isSimpleCast(RexCall call) {
+            return call.getOperator().getName().equalsIgnoreCase("CAST");
+        }
+
+        private boolean isFieldReference(RexNode node) {
+            return node instanceof RexInputRef;
+        }
+
+        private boolean isLiteral(RexNode node) {
+            return node instanceof RexLiteral;
+        }
     }

Review Comment:
   These 2 misses a number of different things like correlation vars and others
   
   probably better to check for 
   ```java
   instanceof RexVariable
   ```



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