KnightChess commented on code in PR #11637:
URL: https://github.com/apache/hudi/pull/11637#discussion_r1684104219


##########
hudi-common/src/main/java/org/apache/hudi/avro/MercifulJsonConverter.java:
##########
@@ -301,6 +306,14 @@ private static JsonToAvroFieldProcessor 
generateFixedTypeHandler() {
     return new JsonToAvroFieldProcessor() {
       @Override
       public Pair<Boolean, Object> convert(Object value, String name, Schema 
schema, boolean shouldSanitize, String invalidCharMask) {
+        // the value can be Number
+        if (value instanceof Number) {

Review Comment:
   got it.



##########
hudi-common/src/main/java/org/apache/hudi/avro/MercifulJsonConverter.java:
##########
@@ -301,6 +306,14 @@ private static JsonToAvroFieldProcessor 
generateFixedTypeHandler() {
     return new JsonToAvroFieldProcessor() {
       @Override
       public Pair<Boolean, Object> convert(Object value, String name, Schema 
schema, boolean shouldSanitize, String invalidCharMask) {
+        // the value can be Number
+        if (value instanceof Number) {
+          LogicalTypes.Decimal decimalType = (LogicalTypes.Decimal) 
schema.getLogicalType();
+          BigDecimal bigDecimal = new 
java.math.BigDecimal(value.toString()).setScale(decimalType.getScale(), 
RoundingMode.HALF_UP);
+          GenericFixed genericFixed = DECIMAL_CONVERSION.toFixed(bigDecimal, 
schema, schema.getLogicalType());
+          return Pair.of(true, new GenericData.Fixed(schema, 
genericFixed.bytes()));
+        }
+
         // The ObjectMapper use List to represent FixedType
         // eg: "decimal_val": [0, 0, 14, -63, -52] will convert to 
ArrayList<Integer>
         List<Integer> converval = (List<Integer>) value;

Review Comment:
   in ut, you directly specified the list, is should be meaningless, List 
should use Array Type. I don't know why here value can be List type? I am not 
sure, does `mapper.readValue(json, Map.class)` will create List type expect 
`Json Array`.



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