slinkydeveloper commented on a change in pull request #17811:
URL: https://github.com/apache/flink/pull/17811#discussion_r754861749



##########
File path: 
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/sink/ConstraintEnforcer.java
##########
@@ -188,14 +201,13 @@ public void processElement(StreamRecord<RowData> element) 
throws Exception {
         for (int i = 0; i < charFieldIndices.length; i++) {
             final int fieldIdx = charFieldIndices[i];
             final int precision = charFieldPrecisions[i];
-            final String stringValue = rowData.getString(fieldIdx).toString();
+            final BinaryStringData stringData = (BinaryStringData) 
rowData.getString(fieldIdx);
 
-            if (stringValue.length() > precision) {
+            if (stringData.getJavaObject().length() > precision) {

Review comment:
       I think invoking `stringData.getJavaObject()` is not safe if you don't 
invoke `stringData.ensureMaterialized()` first, looking at the rest of the code 
in `BinaryStringData`.
   
   Perhaps to get the string length you need either `getSizeInBytes()` or 
`numChars()`? `BinaryStringDataUtil#substringSQL` uses the latter.




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