tpalfy commented on a change in pull request #4104: NIFI-7159
URL: https://github.com/apache/nifi/pull/4104#discussion_r389097315
 
 

 ##########
 File path: 
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
 ##########
 @@ -34,6 +34,7 @@
 import java.io.InputStream;
 import java.io.Reader;
 import java.lang.reflect.Array;
+import java.math.BigDecimal;
 
 Review comment:
   Currently
   ```java
   DataTypeUtils.findMostSuitableType(
           new BigDecimal("11.110"),
           Arrays.asList(RecordFieldType.DECIMAL.getDecimalDataType(5, 3)),
           Function.identity()
   );
   ```
   correctly returns `Optional.of(RecordFieldType.DECIMAL.getDecimalDataType(5, 
3));`, but
   ```java
   DataTypeUtils.findMostSuitableType(
           new BigDecimal("1.110"),
           Arrays.asList(RecordFieldType.DECIMAL.getDecimalDataType(5, 3)),
           Function.identity()
   );
   ```
   ("1.110" instead of "11.111") returns `Optional.empty();`
   
   This is because the inferred type DECIMAL(4,3) is not equal to the provided 
DECIMAL(5,3) so the `getWiderType` method is called which doesn't handle cases 
where the two types are the same in general, only differ in their details.
   
   Probably the `public static Optional<DataType> getWiderType(final DataType 
thisDataType, final DataType otherDataType)` should handle two different 
DECIMAL types by returning another DECIMAL that is the superset of the two in 
terms of scale and precision.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to