twalthr commented on code in PR #29828:
URL: https://github.com/apache/flink/pull/29828#discussion_r4523115449


##########
flink-table/flink-table-code-splitter/src/main/java/org/apache/flink/table/codesplit/FunctionSplitter.java:
##########
@@ -225,44 +227,70 @@ public Void 
visitFormalParameter(JavaParser.FormalParameterContext ctx) {
                         blockContext.start, String.format("\n%s = false;", 
hasReturnedVarName));
             }
 
-            for (String methodBody : mergedCodeBlocks) {
-                long counter = CodeSplitUtil.getCounter().getAndIncrement();
-
-                // void f_splitXX(int x, String y)
-                String splitMethodDef =
-                        returnType
-                                + " "
-                                + functionName
-                                + "_split"
-                                + counter
-                                + parameters
-                                + methodQualifier;
-
-                String newSplitMethod = splitMethodDef + " {\n" + methodBody + 
"\n}\n";
-
-                String newSplitMethodCall =
-                        functionName
-                                + "_split"
-                                + counter
-                                + "("
-                                + String.join(", ", declarations)
-                                + ");\n";
-                if (hasReturnedVarName != null && 
newSplitMethod.contains(hasReturnedVarName)) {
-                    newSplitMethodCall +=
-                            String.format("if (%s) { return; }\n", 
hasReturnedVarName);
+            List<String> blocks = mergedCodeBlocks;
+            Set<String> singleCalls = new HashSet<>();
+            while (true) {
+                newSplitMethodCalls.clear();
+                for (String methodBody : blocks) {
+                    if (singleCalls.contains(methodBody.trim())) {

Review Comment:
   ```suggestion
                       if (singleCalls.contains(methodBody)) {
   ```
   all this code is generated and equality should be possible even without a 
trim()



##########
flink-table/flink-table-code-splitter/src/main/java/org/apache/flink/table/codesplit/FunctionSplitter.java:
##########
@@ -225,44 +227,70 @@ public Void 
visitFormalParameter(JavaParser.FormalParameterContext ctx) {
                         blockContext.start, String.format("\n%s = false;", 
hasReturnedVarName));
             }
 
-            for (String methodBody : mergedCodeBlocks) {
-                long counter = CodeSplitUtil.getCounter().getAndIncrement();
-
-                // void f_splitXX(int x, String y)
-                String splitMethodDef =
-                        returnType
-                                + " "
-                                + functionName
-                                + "_split"
-                                + counter
-                                + parameters
-                                + methodQualifier;
-
-                String newSplitMethod = splitMethodDef + " {\n" + methodBody + 
"\n}\n";
-
-                String newSplitMethodCall =
-                        functionName
-                                + "_split"
-                                + counter
-                                + "("
-                                + String.join(", ", declarations)
-                                + ");\n";
-                if (hasReturnedVarName != null && 
newSplitMethod.contains(hasReturnedVarName)) {
-                    newSplitMethodCall +=
-                            String.format("if (%s) { return; }\n", 
hasReturnedVarName);
+            List<String> blocks = mergedCodeBlocks;
+            Set<String> singleCalls = new HashSet<>();
+            while (true) {
+                newSplitMethodCalls.clear();
+                for (String methodBody : blocks) {
+                    if (singleCalls.contains(methodBody.trim())) {

Review Comment:
   would it make sense to just run a replace on all newlines duplicates which 
replaces them with a single newline? We could do this as the very last step of 
splitter.



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