matriv commented on a change in pull request #18063:
URL: https://github.com/apache/flink/pull/18063#discussion_r765792595
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/CastRuleUtils.java
##########
@@ -296,6 +318,35 @@ public CodeWriter appendBlock(String codeBlock) {
return this;
}
+ public CodeWriter appendAndTrimStringIfNeeded(
+ boolean legacyBehaviour,
+ int precision,
+ String resultStringTerm,
+ String builderTerm) {
+ CodeWriter writer =
+ declStmt(String.class, resultStringTerm)
+ .assignStmt(resultStringTerm,
methodCall(builderTerm, "toString"));
+
+ // Trim if needed
+ if (!legacyBehaviour && shouldPossiblyTrim(precision)) {
+ writer.ifStmt(
+ lengthExceedsPrecision(builderTerm, precision),
+ thenWriter ->
+ thenWriter.assignStmt(
+ resultStringTerm,
+ methodCall(
+ builderTerm,
+ "substring",
+ 0,
+ staticCall(
+ Math.class,
+ "min",
+
methodCall(builderTerm, "length"),
+ precision))));
+ }
+ return writer;
+ }
Review comment:
True, yes, I'll do that.
--
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]