clintropolis commented on code in PR #16529:
URL: https://github.com/apache/druid/pull/16529#discussion_r1635726630
##########
processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java:
##########
@@ -608,7 +608,7 @@ IncrementalIndexRowResult toIncrementalIndexRow(InputRow
row)
Object dimsKey = null;
try {
final EncodedKeyComponent<?> encodedKeyComponent
- =
indexer.processRowValsToUnsortedEncodedKeyComponent(row.getRaw(dimension),
true);
+ =
indexer.processRowValsToUnsortedEncodedKeyComponent(row.getRaw(dimension),
true, dimension);
Review Comment:
cool, that seems better.
thinking a bit more on it i think having a way to decorate an existing
`ParseException` with a column name might actually have been a little cleaner
and even less disruptive since we are already catching them in a place with the
column name,
https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java#L616
without being dependent on dimension indexer implementation, but this way
seems ok too
##########
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:
this should probably pass `reportParseExceptions` instead of `false`?
##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -155,7 +155,7 @@ public EncodedKeyComponent<int[]>
processRowValsToUnsortedEncodedKeyComponent(@N
/**
* Estimates size of the given key component.
* <p>
- * Deprecated method. Use {@link
#processRowValsToUnsortedEncodedKeyComponent(Object, boolean)}
+ * Deprecated method. Use {@link
#processRowValsToUnsortedEncodedKeyComponent(Object, boolean, String)}
Review Comment:
this needs reverted i think
--
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]