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


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CharVarCharTrimPadCastRule.java:
##########
@@ -209,23 +204,21 @@ static CastRuleUtils.CodeWriter padAndTrimStringIfNeeded(
                     thenWriter ->
                             thenWriter.assignStmt(
                                     resultStringTerm,
-                                    methodCall(
-                                            builderTerm,
-                                            "substring",
-                                            0,
-                                            staticCall(
-                                                    Math.class,
-                                                    "min",
-                                                    methodCall(builderTerm, 
"length"),
-                                                    length))),
-                    elseWriter ->

Review Comment:
   also jmh bench for improved version for this class (case `CAST(x AS 
CHAR(n))`)
   shows that it is 2x-7x times faster
   
   jmh output
   | Benchmark | (padLength) | Mode | Cnt | Score | Error | Units |
   |---|---|---|---|---|---|---|
   | new | 1 | avgt | 15 | 24.039 | ± 17.378 | ns/op |
   | new | 4 | avgt | 15 | 73.989 | ± 12.087 | ns/op |
   | new| 16 | avgt | 15 | 34.851 | ± 10.194 | ns/op |
   | new | 64 | avgt | 15 | 96.965 | ± 67.150 | ns/op |
   | new | 256 | avgt | 15 | 110.959 | ± 62.354 | ns/op |
   | old | 1 | avgt | 15 | 71.781 | ± 52.715 | ns/op |
   | old | 4 | avgt | 15 | 94.321 | ± 5.488 | ns/op |
   | old | 16 | avgt | 15 | 259.897 | ± 274.663 | ns/op |
   | old | 64 | avgt | 15 | 260.414 | ± 58.708 | ns/op |
   | old | 256 | avgt | 15 | 734.311 | ± 127.998 | ns/op |



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