{"record":{"id":"9e2a6025a14ac184","repo":"apache/druid","slug":"could-not-convert-value-s-to-long-for-dimension","errorCode":null,"errorMessage":"Could not convert value [%s] to long for dimension [%s]. Invalid type: [%s]","messagePattern":"Could not convert value \\[(.+?)\\] to long for dimension \\[(.+?)\\]\\. Invalid type: \\[(.+?)\\]","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java","lineNumber":443,"sourceCode":"      );\n    } else {\n      final String message;\n      if (objectKey != null) {\n        message = StringUtils.nonStrictFormat(\n            \"Could not convert value [%s] to long for dimension [%s]. Invalid type: [%s]\",\n            valObj,\n            objectKey,\n            valObj.getClass()\n        );\n      } else {\n        message = StringUtils.nonStrictFormat(\n            valObj.getClass().toString(),\n            \"Could not convert value [%s] to long. Invalid type: [%s]\",\n            valObj,\n            valObj.getClass()\n        );\n      }\n      throw new ParseException(\n          valObj.getClass().toString(),\n          message\n      );\n    }\n  }\n\n  @Nullable\n  public static Long convertObjectToLong(@Nullable Object valObj)\n  {\n    return convertObjectToLong(valObj, false);\n  }\n\n  @Nullable\n  public static Long convertObjectToLong(@Nullable Object valObj, boolean reportParseExceptions)\n  {\n    return convertObjectToLong(valObj, reportParseExceptions, null);\n  }\n","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java#L425-L461","documentation":"convertObjectToLong throws this ParseException when the value's Java type is not one it can convert to long (not Number, not String, not List — e.g. a Map, boolean, or nested object). The message includes the value's actual class so the offending type is visible.","triggerScenarios":"A long column receives a value of an unhandled runtime type — e.g. a JSON object (Map) or boolean — so the final else branch in convertObjectToLong fires; also reached via convertObjectToType.","commonSituations":"JSON input with nested objects mapped to a long column; schema drift where a field changes from number to object/array upstream; auto type detection picking long for a heterogeneous field.","solutions":["Fix upstream data so the field is always a number or numeric string for long columns.","Add an ingest-time transform to extract the numeric field from the nested object before conversion.","Change the column's declared type to string (or use nested column support) if the value is genuinely structured.","Validate input schema with a JSON schema / sample-data check in the ingestion spec wizard before publishing."],"exampleFix":"// before: long column receives {\"amount\": 5}\n// after: transform extracts the nested number\n\"transforms\": [{\"type\": \"expression\", \"name\": \"amount\", \"expression\": \"CAST(json_value(payload, '$.amount') AS LONG)\"}]","handlingStrategy":"type-guard","validationCode":"boolean convertibleToLong(Object v) {\n  return v == null || v instanceof Number || v instanceof String;\n}","typeGuard":"Long asLong(Object v) {\n  if (v instanceof Number) return ((Number) v).longValue();\n  if (v instanceof String) { try { return Long.parseLong((String) v); } catch (NumberFormatException e) { return null; } }\n  return null;\n}","tryCatchPattern":"try {\n  return DimensionHandlerUtils.convertObjectToLong(value, fieldName, objectKey);\n} catch (ParseException e) {\n  log.warn(\"Invalid type [%s] for long field [%s], dropping\", value.getClass(), fieldName);\n  return null;\n}","preventionTips":["Check value.getClass() against supported types before conversion","Flatten nested JSON objects before mapping to numeric columns","Schema-validate upstream payloads (e.g. JSON schema)","Guard against schema drift with producer-side contracts"],"tags":["ingestion","type-conversion","invalid-type"],"backgroundTag":"type-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}