kristoffSC commented on PR #21393:
URL: https://github.com/apache/flink/pull/21393#issuecomment-1408677439
@tsreaper
Regarding `I'd like to see more examples. Could you please provide examples
and explain`
If we focus only on IF/ELSE statements without `else if` blocks which are
also supported in proposed solution I think that the differences boils down to
one example below.
Having:
```
public void myFun1(int[] a, int[] b) throws RuntimeException {
if (a[0] == 0) {
a[11] = b[0];
a[12] = b[0];
if (a[2] == 0) {
a[21] = 1;
a[22] = 1;
} else {
a[23] = b[2];
a[24] = b[2];
}
a[13] = b[0];
a[14] = b[0];
}
}
```
The original `IfStatementRewritter will not extract:
```
a[11] = b[0];
a[12] = b[0];
```
and
```
a[13] = b[0];
a[14] = b[0];
```
To their's separate methods. They will be extracted together with entire
`TRUE` branch code block. In my proposed solution, the `TRUE` branch will be
extracted plus statements from above will be further extracted to their own
methods like so:
```
void myFun1_0_1(int[] a, int[] b) throws RuntimeException {
a[11] = b[0];
a[12] = b[0];
}
void myFun1_0(int[] a, int[] b) throws RuntimeException {
a[13] = b[0];
a[14] = b[0];
}
```
The test with similar code is implemented in:
`BlockStatementRewriterTest::testIfMultipleSingleLineStatementRewrite`
If you would have 3rd level IF/ELSE after `a[21] = 1; a[22] = 1;` the
story will be the same. My proposition is able to extract such statements for
every level.
And now you may say, that this is not a big deal. Maybe with an example I'm
showing here the gain is hard to spot. However I can tell that for a production
job (SQL Query), that was causing FLINK-27246, I have an extracted method that
has 537 statements similar to those from example below, that I'm not sure if
the original implementation could extract. Plus we have many additional methods
containing 2 statements.
So even if this would be the only extra thing (except supporting `else if`
and `while`) I think that at scale, the gain adds up.
--
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]