raminqaf commented on code in PR #28814:
URL: https://github.com/apache/flink/pull/28814#discussion_r3643972762
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/RawToBinaryCastRule.java:
##########
Review Comment:
Can we add some tests in `CastRulesTest`?
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/StringToBinaryCastRule.java:
##########
@@ -86,24 +85,17 @@ protected String generateCodeBlockInternal(
.toString();
} else {
final int targetLength =
LogicalTypeChecks.getLength(targetLogicalType);
+ final boolean couldPad = couldPad(targetLogicalType, targetLength);
Review Comment:
I think we can move the computation of couldPad lower in the condition
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/casting/StringToBinaryCastRule.java:
##########
@@ -86,24 +85,17 @@ protected String generateCodeBlockInternal(
.toString();
} else {
final int targetLength =
LogicalTypeChecks.getLength(targetLogicalType);
+ final boolean couldPad = couldPad(targetLogicalType, targetLength);
final String byteArrayTerm =
CodeGenUtils.newName(context.getCodeGeneratorContext(),
"byteArrayTerm");
return new CastRuleUtils.CodeWriter()
.declStmt(byte[].class, byteArrayTerm,
methodCall(inputTerm, "toBytes"))
.ifStmt(
- arrayLength(byteArrayTerm) + " <= " + targetLength,
- thenWriter -> {
- if (couldPad(targetLogicalType, targetLength))
{
- trimOrPadByteArray(
- returnVariable,
- targetLength,
- byteArrayTerm,
- thenWriter);
- } else {
- thenWriter.assignStmt(returnVariable,
byteArrayTerm);
- }
- },
+ arrayLength(byteArrayTerm)
+ + (couldPad ? " == " : " <= ")
Review Comment:
Should we find a common class for this logic?
```java
couldPad ? " == " : " <= "
```
--
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]