You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/11/27 19:37:29 UTC

[GitHub] [flink] matriv commented on a change in pull request #17919: [FLINK-24419][table-planner] Trim to precision when casting to BINARY/VARBINARY

matriv commented on a change in pull request #17919:
URL: https://github.com/apache/flink/pull/17919#discussion_r757813069



##########
File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/StringToBinaryCastRule.java
##########
@@ -45,6 +52,25 @@ public String generateExpression(
             String inputTerm,
             LogicalType inputLogicalType,
             LogicalType targetLogicalType) {
-        return methodCall(inputTerm, "toBytes");
+        int inputLength = Integer.MAX_VALUE;

Review comment:
       You can use `int inputLength = LogicalTypeChecks.getLength(inputLogicalType)` directly without `instanceof`.

##########
File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/StringToBinaryCastRule.java
##########
@@ -45,6 +52,25 @@ public String generateExpression(
             String inputTerm,
             LogicalType inputLogicalType,
             LogicalType targetLogicalType) {
-        return methodCall(inputTerm, "toBytes");
+        int inputLength = Integer.MAX_VALUE;
+        if (inputLogicalType instanceof CharType) {
+            inputLength = ((CharType) inputLogicalType).getLength();
+        } else if (inputLogicalType instanceof VarCharType) {
+            inputLength = ((VarCharType) inputLogicalType).getLength();
+        }
+
+        int targetLength = Integer.MAX_VALUE;

Review comment:
       same here




-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org