{"record":{"id":"d6b9f040a917d239","repo":"apache/druid","slug":"could-not-convert-value-s-to-long","errorCode":null,"errorMessage":"Could not convert value [%s] to long.","messagePattern":"Could not convert value \\[(.+?)\\] to long\\.","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java","lineNumber":405,"sourceCode":"    } else if (valObj instanceof Boolean) {\n      return Evals.asLong((Boolean) valObj);\n    } else if (valObj instanceof String) {\n      Long ret = DimensionHandlerUtils.getExactLongFromDecimalString((String) valObj);\n      if (reportParseExceptions && ret == null) {\n        final String message;\n        if (objectKey != null) {\n          message = StringUtils.nonStrictFormat(\n              \"Could not convert value [%s] to long for dimension [%s].\",\n              valObj,\n              objectKey\n          );\n        } else {\n          message = StringUtils.nonStrictFormat(\n              \"Could not convert value [%s] to long.\",\n              valObj\n          );\n        }\n        throw new ParseException((String) valObj, message);\n      }\n      return ret;\n    } else if (valObj instanceof List) {\n      final String message;\n      if (objectKey != null) {\n        message = StringUtils.nonStrictFormat(\n            \"Could not ingest value [%s] as long for dimension [%s]. A long column cannot have multiple values in the same row.\",\n            valObj,\n            objectKey\n        );\n      } else {\n        message = StringUtils.nonStrictFormat(\n            \"Could not ingest value [%s] as long. A long column cannot have multiple values in the same row.\",\n            valObj\n        );\n      }\n      throw new ParseException(\n          valObj.getClass().toString(),","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/DimensionHandlerUtils.java#L387-L423","documentation":"DimensionHandlerUtils.convertObjectToLong converts an ingested field value to a long. When the value is a String that cannot be parsed as a long (Long.parseLong fails), Druid throws a ParseException with this message. It indicates the input data does not match the declared long column type.","triggerScenarios":"Ingesting a row where a dimension/column declared as long receives a string like \"abc\" or \"12.5\" that Long.parseLong cannot parse; convertObjectToLong called on a non-numeric string value.","commonSituations":"Input format mismatch (e.g. CSV field \"1,000\" or \"1.0\" mapped to a long column); ETL producing locale-formatted numbers; schema drift where a column was re-declared as long but data still contains text.","solutions":["Fix the input data so the value is an integer-parseable string (e.g. \"1\" not \"1.0\"), or drop/transform bad values.","Use an ingest-time transform or parse expression (e.g. REGEXP_EXTRACT, CAST) to normalize values before the long conversion.","Change the column type to string or double in the ingestion spec if values genuinely aren't integers.","Handle ParseException in your ingestion error handler / tune maxParseExceptions so the job doesn't halt unexpectedly."],"exampleFix":"// before: ingesting \"1.5\" into a long column\n// after: add a transform to round/parse safely\n\"transforms\": [{\"type\": \"expression\", \"name\": \"myLongCol\", \"expression\": \"CAST(CAST(myCol AS DOUBLE) AS LONG)\"}]","handlingStrategy":"try-catch","validationCode":"boolean isParsableLong(Object v) {\n  if (v == null) return true;\n  if (v instanceof Number) return true;\n  if (v instanceof String) {\n    try { Long.parseLong((String) v); return true; } catch (NumberFormatException e) { return false; }\n  }\n  return false;\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(\"Skipping non-long value [%s] for field [%s]\", value, fieldName);\n  return null; // or route row to a dead-letter channel\n}","preventionTips":["Pre-validate numeric fields against a regex like ^-?\\d+$ before ingest","Use ingest transforms to CAST/normalize values","Sample input data when building the ingestion spec to confirm types","Set maxParseExceptions and monitor rejected rows"],"tags":["ingestion","type-conversion","parse-exception"],"backgroundTag":"invalid-argument-format","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"}