snuyanzin commented on code in PR #28777:
URL: https://github.com/apache/flink/pull/28777#discussion_r3610478326
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CharVarCharTrimPadCastRule.java:
##########
@@ -236,34 +229,24 @@ static void padStringIfNeeded(
boolean legacyBehaviour,
int length,
String returnTerm,
+ String currentLengthTerm,
CodeGeneratorContext codeGeneratorContext) {
// Pad if needed
if (!legacyBehaviour && couldPad(targetType, length)) {
final String padLength = newName(codeGeneratorContext,
"padLength");
- final String sbPadding = newName(codeGeneratorContext,
"sbPadding");
writer.ifStmt(
- stringShouldPad(returnTerm, length),
+ currentLengthTerm + " < " + length,
thenWriter ->
thenWriter
.declStmt(int.class, padLength)
- .assignStmt(
- padLength,
- length + " - " +
methodCall(returnTerm, "length"))
- .declStmt(StringBuilder.class, sbPadding)
- .assignStmt(sbPadding,
constructorCall(StringBuilder.class))
- .forStmt(
- padLength,
- (idx, loopWriter) ->
- loopWriter.stmt(
- methodCall(
- sbPadding,
"append", "\" \"")),
- codeGeneratorContext)
+ .assignStmt(padLength, length + " - " +
currentLengthTerm)
.assignStmt(
returnTerm,
returnTerm
+ " + "
- + methodCall(sbPadding,
"toString")));
Review Comment:
no need for another `StringBuilder` and for loop as it could be replaced
with jdk's `" ".repeat(...)`
--
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]