kristoffSC opened a new pull request, #21860: URL: https://github.com/apache/flink/pull/21860
## What is the purpose of the change Unchanged backport of https://github.com/apache/flink/pull/21393 This PR fix issue reported in https://issues.apache.org/jira/browse/FLINK-27246 that was caused by `JavaCodeSplitter` not rewriting "while" statements that was leading to Java compiler not able to compile code due to to big methods. Proposed change, enhance `JavaCodeSplitter` by replacing `IfStatementRewriter.java` with `BlockStatementRewriter.java`. The new `BlockStatementRewriter.java` can rewrite both IF/ESLE statements and WHILE blocks including nested statements. The `BlockStatementRewriter` works in two steps. First step extracts blocks from IF/ELSE branches and WHILE bodies to separate methods. This step is executed by new class `BlockStatementSplitter`. The second step, groups statements (single lien statements, IF/ELSE and WHILE statements) into groups and extract them to new methods. This step is executed by new class `BlockStatementGrouper `. An example of rewritten code: BEFORE: ``` public class Example { int b; int c; public void myFun(int a) { int counter = 10; while (counter > 0) { int localA = a + 1000; System.out.println(localA); if (a > 0) { b = a * 2; c = b * 2; System.out.println(b); } else { b = a * 3; System.out.println(b); } counter--; } } } ``` AFTER executing BlockStatementRewriter: ``` public class Example { int b; int c; public void myFun(int a) { int counter = 10; while (counter > 0) { myFun_rewriteGroup1(a); counter--; } } void myFun_rewriteGroup1(int a) { myFun_whileBody0_0(a); if (a > 0) { myFun_whileBody0_0_ifBody0(a); } else { myFun_whileBody0_0_ifBody1(a); } } void myFun_whileBody0_0(int a) { int localA = a + 1000; System.out.println(localA); } void myFun_whileBody0_0_ifBody1(int a) { b = a * 3; System.out.println(b); } void myFun_whileBody0_0_ifBody0(int a) { b = a * 2; c = b * 2; System.out.println(b); } } ``` ## Brief change log - Include WHILE blocs in Java cod splitter logic. - Add BlockStatementRewriter, BlockStatementSplitter and BlockStatementGrouper class, - Remove IfStatementRewriter class ## Verifying this change This change is already covered by existing tests, such as - Flink-brach-sql-test - Flink-tcpds-test - Junit test - JavaCodeSplitterTest This change added tests and can be verified as follows: - BlockStatementRewriterTest.java - BlockStatementSplitterTest.java - BlockStatementGrouperTest.java ## Does this pull request potentially affect one of the following parts: - Dependencies (does it add or upgrade a dependency): (no) - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no) - The serializers: (no) - The runtime per-record code paths (performance sensitive): (no) - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no) - The S3 file system connector: (no) ## Documentation - Does this pull request introduce a new feature? (no) -- 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]
