findingrish commented on code in PR #16529:
URL: https://github.com/apache/druid/pull/16529#discussion_r1636624505
##########
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].",
Review Comment:
nit: The exception message in the if/else block seem to differ by `for
dimension [%s]`. Instead of duplicating the message does it make sense to have
a single template?
--
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]