shenzhu commented on pull request #17919: URL: https://github.com/apache/flink/pull/17919#issuecomment-982304022
> Hi @shenzhu I left a couple more comments, but overall the approach is not 100% correct, because it applies the trimming only when casting from string types. It should also apply it when casting between binary types themselves, i.e. a byte array with 10 bytes and type `BINARY(10)`, casted to let's say a `BINARY(5)` (or `VARBINARY(5)`) should be trimmed to 5 bytes. So this logic should be applied in for all supported casts to BINARY/VARBINARY. Hey @matriv , thanks for your review! I checked the codebase and found currently we support casting from `STRING/BINARY/VARBINARY/RAW` to `BINARY/VARBINARY`. For these supported casts, `STRING` to `BINARY/VARBINARY` is supported by [StringToBinaryCastRule](https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/StringToBinaryCastRule.java), and the rest is supported via old casting rules in `ScalarOperatorGens`([BINARY|VARBINARY](https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala#L885) and [RAW](https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/ScalarOperatorGens.scala#L1092)). If I understand it correctly, we have two options for this task: 1. Create `BinaryToBinaryCastRule` class and `RawToBinaryCastRule` class to follow the new casting rules 2. Update the casting logic in `ScalaOperatorGens` for `BINARY/VARBINARY` and `RAW` to add truncation logic I'm a little prefer Option 1 because seems that's the direction the community is trying to move forward(?), what do you think about this? Thanks for your help! -- 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org