luoyuxia commented on code in PR #21663:
URL: https://github.com/apache/flink/pull/21663#discussion_r1098146682
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/NumericOrDefaultReturnTypeInference.java:
##########
@@ -56,11 +55,7 @@ public RelDataType inferReturnType(SqlOperatorBinding
opBinding) {
List<RelDataType> types = new ArrayList<>();
for (int i = startTypeIdx; i < nOperands; i++) {
RelDataType type = opBinding.getOperandType(i);
- if (SqlTypeUtil.isNumeric(type)) {
- types.add(type);
- } else {
- return opBinding.getOperandType(defaultTypeIdx);
- }
+ types.add(type);
Review Comment:
Do we really need to skip check for all type?
In the fail case, if(b, 'xx', s), where the second operand is `char(2)`, the
third operand is `string`, the it wll mistake the return type is char(2)`, and
then in the if code gen, it'll cast all operands to `char(2)`.
Maybe we check
`if (SqlTypeUtil.isNumeric(type) || SqlTypeUtil.isCharacter(type))` in here?
WDYT?
##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/batch/sql/CalcITCase.scala:
##########
@@ -1837,6 +1837,11 @@ class CalcITCase extends BatchTestBase {
Seq(row('a'), row('b'), row('a')))
}
+ @Test
+ def testIfWithFixCharAndVarchar(): Unit = {
+ checkResult("SELECT IF(b > 10, 'ua', c) FROM Table3", data3.map(r =>
row(r.getField(2))))
Review Comment:
Change to
```suggestion
checkResult("SELECT IF(b > 4, 'ua', c) FROM Table3", data3.map(r =>
row(r.getField(2))))
```
to cover the negative case.
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/type/NumericOrDefaultReturnTypeInference.java:
##########
@@ -56,11 +55,7 @@ public RelDataType inferReturnType(SqlOperatorBinding
opBinding) {
List<RelDataType> types = new ArrayList<>();
for (int i = startTypeIdx; i < nOperands; i++) {
RelDataType type = opBinding.getOperandType(i);
- if (SqlTypeUtil.isNumeric(type)) {
- types.add(type);
- } else {
- return opBinding.getOperandType(defaultTypeIdx);
- }
+ types.add(type);
Review Comment:
It's just my personal opinion, the reason behind that is the class
`NumericOrDefaultReturnTypeInference` is designed for
- if the operands are Numeric, consider each Numeric and find the
leastRestrictive
- Otherwise, it will return the sencond as the return type.
If we skip all checks, the usage of the class
`NumericOrDefaultReturnTypeInference` changes.
Then we'll need to modify the class name and java doc.
--
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]