Copilot commented on code in PR #4482:
URL: https://github.com/apache/flink-cdc/pull/4482#discussion_r3629085632


##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/JaninoCompiler.java:
##########
@@ -804,6 +904,263 @@ private static String 
generateInvokeExpression(UserDefinedFunctionDescriptor udf
         }
     }
 
+    private static class GeneratedExpressionGenerator {
+        private final Context context;
+        private int termId;
+
+        private GeneratedExpressionGenerator(Context context) {
+            this.context = context;
+        }
+
+        private GeneratedExpression translate(SqlNode sqlNode, Class<?> 
resultClass) {
+            if (sqlNode instanceof SqlBasicCall) {
+                return translateSqlBasicCall((SqlBasicCall) sqlNode, 
resultClass);
+            }
+            if (sqlNode instanceof SqlCase) {
+                return translateSqlCase((SqlCase) sqlNode, resultClass);
+            }
+            Java.Rvalue rvalue = translateSqlNodeToJaninoRvalue(context, 
sqlNode);
+            return GeneratedExpression.fromExpression(
+                    rvalue == null ? "" : rvalue.toString(), resultClass);

Review Comment:
   Creating a `GeneratedExpression` with an empty `resultTerm` when 
`translateSqlNodeToJaninoRvalue(...)` returns null can produce syntactically 
invalid scripts later (e.g., `return ;`), and the failure will surface far away 
from the root cause. Prefer failing fast here (e.g., throw `ParseException` 
with the offending `SqlNode`) instead of emitting an empty result term.



##########
flink-cdc-runtime/src/main/java/org/apache/flink/cdc/runtime/parser/TransformParser.java:
##########
@@ -589,6 +598,27 @@ public static String 
translateFilterExpressionToJaninoExpression(
                 where);
     }
 
+    public static GeneratedExpression 
translateFilterExpressionToGeneratedExpression(
+            String filterExpression,
+            List<Column> columns,
+            List<UserDefinedFunctionDescriptor> udfDescriptors,
+            SupportedMetadataColumn[] supportedMetadataColumns,
+            Map<String, String> columnNameMap) {
+        if (isNullOrWhitespaceOnly(filterExpression)) {
+            return GeneratedExpression.fromExpression("", Boolean.class);
+        }
+        SqlSelect sqlSelect = 
TransformParser.parseFilterExpression(filterExpression);
+        if (!sqlSelect.hasWhere()) {
+            return GeneratedExpression.fromExpression("", Boolean.class);
+        }

Review Comment:
   Returning an empty-result `GeneratedExpression` for empty filters / missing 
WHERE can conflict with `TransformExpressionKey.getFullScript()` validation 
(which rejects empty result terms) and may break compilation paths that still 
attempt to compile the filter. If the intended semantics are 'no filter means 
pass-through', consider returning a non-empty constant script term (e.g., 
`Boolean.TRUE`) or handling the no-op case by skipping key creation/compilation 
entirely so the rest of the pipeline never sees an empty result term.



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