lsyldliu commented on code in PR #25099:
URL: https://github.com/apache/flink/pull/25099#discussion_r1680934801


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/IfNullTypeStrategy.java:
##########
@@ -35,10 +43,20 @@ public Optional<DataType> inferType(CallContext 
callContext) {
         final List<DataType> argumentDataTypes = 
callContext.getArgumentDataTypes();
         final DataType inputDataType = argumentDataTypes.get(0);
         final DataType nullReplacementDataType = argumentDataTypes.get(1);
+
         if (!inputDataType.getLogicalType().isNullable()) {
             return Optional.of(inputDataType);
         }
 
-        return Optional.of(nullReplacementDataType);
+        return LogicalTypeMerging.findCommonType(

Review Comment:
   We can optimize the code as follow:
   ```
           return LogicalTypeMerging.findCommonType(
                           Arrays.asList(
                                   inputDataType.getLogicalType(),
                                   nullReplacementDataType.getLogicalType()))
                   .map(t -> 
t.copy(nullReplacementDataType.getLogicalType().isNullable()))
                   .map(TypeConversions::fromLogicalToDataType);
   ```



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