{"record":{"id":"ed48cb746a6d3eb7","repo":"apache/druid","slug":"unable-to-parse-timestamps-with-format-s","errorCode":null,"errorMessage":"Unable to parse timestamps with format [%s]","messagePattern":"Unable to parse timestamps with format \\[(.+?)\\]","errorType":"exception","errorClass":"IAE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java","lineNumber":97,"sourceCode":"        Preconditions.checkArgument(!Strings.isNullOrEmpty(input), \"null timestamp\");\n        return numericFun.apply(Long.parseLong(ParserUtils.stripQuotes(input)));\n      };\n    } else if (\"ruby\".equalsIgnoreCase(format)) {\n      final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);\n      return input -> {\n        Preconditions.checkArgument(!Strings.isNullOrEmpty(input), \"null timestamp\");\n        return numericFun.apply(Double.parseDouble(ParserUtils.stripQuotes(input)));\n      };\n    } else {\n      try {\n        final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format));\n        return input -> {\n          Preconditions.checkArgument(!Strings.isNullOrEmpty(input), \"null timestamp\");\n          return formatter.parse(ParserUtils.stripQuotes(input));\n        };\n      }\n      catch (Exception e) {\n        throw new IAE(e, \"Unable to parse timestamps with format [%s]\", format);\n      }\n    }\n  }\n\n  public static Function<Number, DateTime> createNumericTimestampParser(\n      final String format\n  )\n  {\n    if (\"posix\".equalsIgnoreCase(format)) {\n      return input -> DateTimes.utc(TimeUnit.SECONDS.toMillis(input.longValue()));\n    } else if (\"micro\".equalsIgnoreCase(format)) {\n      return input -> DateTimes.utc(TimeUnit.MICROSECONDS.toMillis(input.longValue()));\n    } else if (\"nano\".equalsIgnoreCase(format)) {\n      return input -> DateTimes.utc(TimeUnit.NANOSECONDS.toMillis(input.longValue()));\n    } else if (\"ruby\".equalsIgnoreCase(format)) {\n      return input -> DateTimes.utc(Double.valueOf(input.doubleValue() * 1000).longValue());\n    } else {\n      return input -> DateTimes.utc(input.longValue());","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/parsers/TimestampParser.java#L79-L115","documentation":"TimestampParser.createTimestampParser builds a DateTimeFormatter from the configured format string; if the Joda-Time pattern is invalid or cannot be constructed, it throws IllegalArgumentException wrapping the cause with 'Unable to parse timestamps with format [<format>]'. This fails fast at parser construction, before any data is seen.","triggerScenarios":"Calling createTimestampParser(String format) with a format string that Joda-Time's DateTimeFormat cannot parse (bad pattern letters, invalid literals).","commonSituations":"Typos in format tokens (e.g. 'YYY' vs 'yyyy', 'hh' vs 'HH'); copying SimpleDateFormat patterns that differ from Joda syntax; formats pasted from other systems like Python strftime; null or empty format handled earlier but invalid syntax reaches here.","solutions":["Correct the format string to valid Joda-Time syntax (e.g. \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\")","Verify each token against the Joda-Time DateTimeFormat documentation","Test the format with DateTimeFormat.forPattern(format) in isolation before wiring it into ingestion","If the data is actually numeric timestamps, use createNumericTimestampParser instead"],"exampleFix":"// before\nTimestampParser.createTimestampParser(\"%Y-%m-%d %H:%M:%S\") // strftime-style: throws\n// after\nTimestampParser.createTimestampParser(\"yyyy-MM-dd HH:mm:ss\")","handlingStrategy":"validation","validationCode":"try {\n  org.joda.time.format.DateTimeFormat.forPattern(format);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Invalid timestamp format: \" + format, e);\n}","typeGuard":"boolean isValidJodaFormat(String format) {\n  try { org.joda.time.format.DateTimeFormat.forPattern(format); return true; }\n  catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n  Function<Number, DateTime> p = TimestampParser.createTimestampParser(format);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Fix timestamp format in config: \" + format, e);\n}","preventionTips":["Use Joda-Time pattern syntax, not SimpleDateFormat or strftime tokens","Verify tokens like yyyy vs YYYY, HH vs hh against Joda docs","Unit-test the format against real timestamp samples before ingestion","Use numeric timestamp parsing when the data is epoch values"],"tags":["timestamp","date-format","joda-time"],"backgroundTag":"invalid-date-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}