{"record":{"id":"dc0f6243db84a26b","repo":"apache/druid","slug":"unable-to-parse-value-s-for-field-s","errorCode":null,"errorMessage":"Unable to parse value[%s] for field[%s]","messagePattern":"Unable to parse value\\[(.+?)\\] for field\\[(.+?)\\]","errorType":"exception","errorClass":"org.apache.druid.java.util.common.parsers.ParseException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/data/input/Rows.java","lineNumber":153,"sourceCode":"        metricValueString = trimLeadingPlusOfLongString(metricValueString);\n\n        Number v = null;\n\n        // Try parsing as Long first, since it's significantly faster than Double parsing, and also there are various\n        // integer numbers that can be represented as Long but cannot be represented as Double.\n        if (outputType == null || outputType == ValueType.LONG) {\n          v = Longs.tryParse(metricValueString);\n        }\n\n        if (v == null) {\n          v = Double.valueOf(metricValueString);\n        }\n\n        asNumber = v;\n      }\n      catch (Exception e) {\n        if (throwParseExceptions) {\n          throw new ParseException(\n              String.valueOf(inputValue),\n              e,\n              \"Unable to parse value[%s] for field[%s]\",\n              inputValue,\n              name\n          );\n        } else {\n          return null;\n        }\n      }\n    } else {\n      if (throwParseExceptions) {\n        throw new ParseException(\n            String.valueOf(inputValue),\n            \"Unknown type[%s] for field[%s]\",\n            inputValue.getClass(),\n            name\n        );","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/data/input/Rows.java#L135-L171","documentation":"When the field value is a String, objectToNumber strips commas and a leading '+', then tries Longs.tryParse followed by Double.valueOf. If both fail, the string is not a valid number. With throwParseExceptions=true it throws a Druid ParseException naming the offending value and field; otherwise it silently returns null. This lets ingestion/queries fail fast (or skip) on non-numeric string data.","triggerScenarios":"Passing a String like \"abc\", \"12.3.4\", empty string after trim, or a value with thousands separators beyond Druid's comma handling into Rows.objectToNumber with throwParseExceptions=true and the string neither parseable as Long nor Double.","commonSituations":"CSV/TSV ingestion with a malformed metric column; user-supplied query filters or virtual columns referencing a string dimension as if numeric; locale-formatted numbers such as \"1.234,56\" or values containing currency symbols; JSON ingestion where a field is quoted but expected numeric.","solutions":["Fix the input data so the string is a plain numeric literal (e.g. \"12.3\" not \"12.3.4\").","Set throwParseExceptions=false so unparseable values become null instead of failing the row.","Remove thousands separators and currency/locale formatting upstream before ingestion.","Change the column's type spec to STRING if the data is genuinely non-numeric."],"exampleFix":"// before\nNumber n = Rows.objectToNumber(\"revenue\", \"1,234.5a\", true);\n// after\nNumber n = Rows.objectToNumber(\"revenue\", \"1234.5\", true);","handlingStrategy":"validation","validationCode":"boolean isNumericString(String s) {\n  String t = s == null ? \"\" : s.replace(\",\", \"\").trim();\n  return com.google.common.primitives.Longs.tryParse(t) != null || parseDoubleSafe(t) != null;\n}","typeGuard":"Number asNumberIfPossible(Object v) {\n  return v instanceof Number ? (Number) v\n      : (v instanceof String && isNumericString((String) v)) ? Rows.objectToNumber(\"f\", v, false) : null;\n}","tryCatchPattern":"try {\n  return Rows.objectToNumber(field, value, true);\n} catch (ParseException e) {\n  log.warn(\"Non-numeric value for field %s: %s\", field, value);\n  return null; // or route to a dead-letter path\n}","preventionTips":["Validate/sanitize string fields upstream before treating them as numeric metrics.","Strip currency symbols and locale-specific decimal separators during parsing.","Use throwParseExceptions=false when partial data is acceptable and log skipped values.","Declare the column type as STRING in the spec when the data is not reliably numeric."],"tags":["java","parse-exception","number-format","druid-rows"],"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"}