TSFenwick commented on code in PR #16529:
URL: https://github.com/apache/druid/pull/16529#discussion_r1635740274


##########
processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java:
##########
@@ -358,58 +414,111 @@ public static Float convertObjectToFloat(@Nullable 
Object valObj)
   @Nullable
   public static Float convertObjectToFloat(@Nullable Object valObj, boolean 
reportParseExceptions)
   {
-    if (valObj == null) {
-      return null;
-    }
+    return convertObjectToFloat(valObj, reportParseExceptions, null);
+  }
 
-    if (valObj instanceof Float) {
-      return (Float) valObj;
-    } else if (valObj instanceof Number) {
-      return ((Number) valObj).floatValue();
-    } else if (valObj instanceof String) {
-      Float ret = Floats.tryParse((String) valObj);
-      if (reportParseExceptions && ret == null) {
-        throw new ParseException((String) valObj, "could not convert value 
[%s] to float", valObj);
+  @Nullable
+  public static Float convertObjectToFloat(@Nullable Object valObj, @Nullable 
String fieldName)
+  {
+    return convertObjectToFloat(valObj, false, fieldName);
+  }
+
+  @Nullable
+  public static Float convertObjectToFloat(@Nullable Object valObj, boolean 
reportParseExceptions, @Nullable String fieldName)
+  {
+    {
+      if (valObj == null) {
+        return null;
+      }
+
+      if (valObj instanceof Float) {
+        return (Float) valObj;
+      } else if (valObj instanceof Number) {
+        return ((Number) valObj).floatValue();
+      } else if (valObj instanceof String) {
+        Float ret = Floats.tryParse((String) valObj);
+        if (reportParseExceptions && ret == null) {
+          final String message;
+          if (fieldName != null) {
+            message = StringUtils.nonStrictFormat(
+                "Could not convert value [%s] to float for dimension [%s].",
+                valObj,
+                fieldName
+            );
+          } else {
+            message = StringUtils.nonStrictFormat(
+                "Could not convert value [%s] to float.",
+                valObj
+            );
+          }
+          throw new ParseException((String) valObj, message);
+        }
+        return ret;
+      } else if (valObj instanceof List) {
+        final String message;
+        if (fieldName != null) {
+          message = StringUtils.nonStrictFormat(
+              "Could not ingest value [%s] as float for dimension [%s]. A 
float column cannot have multiple values in the same row.",
+              valObj,
+              fieldName
+          );
+        } else {
+          message = StringUtils.nonStrictFormat(
+              "Could not ingest value [%s] as float. A float column cannot 
have multiple values in the same row.",
+              valObj
+          );
+        }
+        throw new ParseException(
+            valObj.getClass().toString(),
+            message
+        );
+      } else {
+        final String message;
+        if (fieldName != null) {
+          message = StringUtils.nonStrictFormat(
+              "Could not convert value [%s] to float for dimension [%s]. 
Invalid type: [%s]",
+              valObj,
+              fieldName,
+              valObj.getClass()
+          );
+        } else {
+          message = StringUtils.nonStrictFormat(
+              "Could not convert value [%s] to float. Invalid type: [%s]",
+              valObj,
+              valObj.getClass()
+          );
+        }
+        throw new ParseException(
+            valObj.getClass().toString(),
+            message
+        );
       }
-      return ret;
-    } else if (valObj instanceof List) {
-      throw new ParseException(
-          valObj.getClass().toString(),
-          "Could not ingest value %s as float. A float column cannot have 
multiple values in the same row.",
-          valObj
-      );
-    } else {
-      throw new ParseException(
-          valObj.getClass().toString(),
-          "Could not convert value [%s] to float. Invalid type: [%s]",
-          valObj,
-          valObj.getClass()
-      );
     }
   }
 
   @Nullable
   public static Object convertObjectToType(
       @Nullable final Object obj,
       final TypeSignature<ValueType> type,
-      final boolean reportParseExceptions
+      final boolean reportParseExceptions,
+      @Nullable final String fieldName
   )
   {
     Preconditions.checkNotNull(type, "type");
 
     switch (type.getType()) {
       case LONG:
-        return convertObjectToLong(obj, reportParseExceptions);
+        return convertObjectToLong(obj, reportParseExceptions, fieldName);
       case FLOAT:
-        return convertObjectToFloat(obj, reportParseExceptions);
+        return convertObjectToFloat(obj, reportParseExceptions, fieldName);
       case DOUBLE:
-        return convertObjectToDouble(obj, reportParseExceptions);
+        return convertObjectToDouble(obj, reportParseExceptions, fieldName);
       case STRING:
         return convertObjectToString(obj);
       case ARRAY:
         return coerceToObjectArrayWithElementCoercionFunction(
             obj,
-            x -> DimensionHandlerUtils.convertObjectToType(x, 
type.getElementType())
+            x -> DimensionHandlerUtils.convertObjectToType(x, 
type.getElementType(), false, fieldName)

Review Comment:
   yeah. I set it to `false` to preserve how it was working before. but it 
wouldn't hurt to have it pass `reportParseExceptions` instead



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to