{"record":{"id":"1927c6fda36bce5a","repo":"apache/druid","slug":"this-method-should-not-be-invoked-for-this-granula","errorCode":null,"errorMessage":"This method should not be invoked for this granularity type","messagePattern":"This method should not be invoked for this granularity type","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/granularity/AllGranularity.java","lineNumber":44,"sourceCode":"import org.joda.time.format.DateTimeFormatter;\n\n/**\n * AllGranularty buckets everything into a single bucket\n */\npublic class AllGranularity extends Granularity\n{\n  /**\n   * This constructor is public b/c it is serialized and deserialized\n   * based on type in GranularityModule\n   */\n  public AllGranularity()\n  {\n  }\n\n  @Override\n  public DateTimeFormatter getFormatter(Formatter type)\n  {\n    throw new UnsupportedOperationException(\"This method should not be invoked for this granularity type\");\n  }\n\n  @Override\n  public long increment(long time)\n  {\n    return DateTimes.MAX.getMillis();\n  }\n\n  @Override\n  public DateTime increment(DateTime time)\n  {\n    return DateTimes.MAX;\n  }\n\n  @Override\n  public long bucketStart(long time)\n  {\n    return DateTimes.MIN.getMillis();","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/granularity/AllGranularity.java#L26-L62","documentation":"AllGranularity represents 'all time' as a single infinite bucket, so it has no meaningful path-based DateTimeFormatter. Calling getFormatter() throws UnsupportedOperationException('This method should not be invoked for this granularity type'). It guards against silently producing wrong date parsing/formatting for path-derived timestamps.","triggerScenarios":"Calling AllGranularity.getFormatter(type), typically from code that extracts dates from file paths or segments based on the segment/granularity type without special-casing ALL granularity.","commonSituations":"Batch ingestion from paths (e.g. static/hdfs/Drtfy path parsers) configured with granularity 'all'; generic code that iterates Granularity types and assumes every granularity supports path formatting; misconfigured GranularitySpec using ALL where a bucketed granularity is required.","solutions":["Use a real granularity (e.g. 'day', 'hour') in your ingestion/path spec when path-based date extraction is needed","Branch on granularity instanceof AllGranularity (or GranularityType.ALL) and skip formatter-based parsing","Check your GranularitySpec/segment granularity configuration; ALL is only valid when the whole dataset is one bucket","Upgrade Druid if this comes from an internal component — newer versions may special-case ALL"],"exampleFix":"// before\nDateTimeFormatter fmt = granularity.getFormatter(Formatter.DEFAULT);\n// after\nif (granularity instanceof AllGranularity) {\n  // no path-derived timestamp for ALL granularity; use query interval instead\n} else {\n  DateTimeFormatter fmt = granularity.getFormatter(Formatter.DEFAULT);\n}","handlingStrategy":"type-guard","validationCode":"if (granularity instanceof AllGranularity) {\n  throw new IllegalArgumentException(\"Path-based date extraction requires a bucketed granularity, not ALL\");\n}","typeGuard":"boolean supportsPathFormatting(Granularity g) {\n  return !(g instanceof AllGranularity) && !(g instanceof DurationGranularity);\n}","tryCatchPattern":"try {\n  formatter = granularity.getFormatter(type);\n} catch (UnsupportedOperationException e) {\n  // granularity (e.g. ALL) has no path formatter; use explicit timestamp/interval instead\n}","preventionTips":["Never combine granularity ALL with path-based timestamp extraction in specs","Special-case ALL/Duration granularities in generic Granularity-dispatch code","Validate GranularitySpec granularity type when path parsers are configured","Prefer PeriodGranularity for ingestion requiring path-derived intervals"],"tags":["granularity","unsupported-operation","ingestion"],"backgroundTag":"unsupported-operation","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"}