katewang0710 commented on a change in pull request #4133:  add more types 
parsing for string coerceValueIntoField
URL: https://github.com/apache/incubator-pinot/pull/4133#discussion_r285840014
 
 

 ##########
 File path: 
pinot-common/src/main/java/org/apache/pinot/common/config/Deserializer.java
 ##########
 @@ -349,17 +349,26 @@
         } else if (value instanceof String) {
           String stringValue = (String) value;
           try {
-            if (Integer.class.isAssignableFrom(fieldType) || int.class
-                .isAssignableFrom(fieldType)) { // field instanceof int/Integer
+            if (fieldType.isAssignableFrom(Integer.class) || 
fieldType.isAssignableFrom(int.class)){
               destinationValue = Integer.parseInt(stringValue);
-            } else if (Long.class.isAssignableFrom(fieldType)) { // field 
instanceof long/Long
+            } else if (fieldType.isAssignableFrom(Long.class) || 
fieldType.isAssignableFrom(long.class)){
               destinationValue = Long.parseLong(stringValue);
-            } else if (Boolean.class.isAssignableFrom(fieldType) || 
boolean.class.isAssignableFrom(fieldType)) {
+            } else if (fieldType.isAssignableFrom(Boolean.class) || 
fieldType.isAssignableFrom(boolean.class)){
               destinationValue = Boolean.parseBoolean(stringValue);
-            } else if (Enum.class.isAssignableFrom(fieldType)) {
+            } else if (Enum.class.isAssignableFrom(fieldType)){
               destinationValue = 
Enum.valueOf(fieldType.asSubclass(Enum.class), stringValue.toUpperCase());
-            } else {
-              // TODO Add float/double/short/char
+            } else if (fieldType.isAssignableFrom(Float.class) || 
fieldType.isAssignableFrom(float.class)){
+              destinationValue = Float.parseFloat(stringValue);
+            } else if (fieldType.isAssignableFrom(Double.class) || 
fieldType.isAssignableFrom(double.class)){
+              destinationValue = Double.parseDouble(stringValue);
+            } else if (fieldType.isAssignableFrom(Short.class) || 
fieldType.isAssignableFrom(short.class)){
+              destinationValue = Short.parseShort(stringValue);
+            } else if (fieldType.isAssignableFrom(Byte.class) || 
fieldType.isAssignableFrom(byte.class)){
+              destinationValue = stringValue.getBytes()[0];
 
 Review comment:
   Exactly! Thanks

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to