{"record":{"id":"e7ebbe89e6596dfb","repo":"apache/druid","slug":"method-not-supported-this-method-is-not-expected","errorCode":null,"errorMessage":"Method not supported. This method is not expected to be called!","messagePattern":"Method not supported\\. This method is not expected to be called!","errorType":"error_code","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/union/UnionQuery.java","lineNumber":123,"sourceCode":"    return getClass().getSimpleName();\n  }\n\n  @Override\n  public QueryRunner<Object> getRunner(QuerySegmentWalker walker)\n  {\n    throw DruidException.defensive(\"Use QueryToolChest to get a Runner\");\n  }\n\n  @Override\n  public List<Interval> getIntervals()\n  {\n    return Collections.emptyList();\n  }\n\n  @Override\n  public Duration getDuration()\n  {\n    throw methodNotSupported();\n  }\n\n  @Override\n  public Granularity getGranularity()\n  {\n    return Granularities.ALL;\n  }\n\n  @Override\n  public DateTimeZone getTimezone()\n  {\n    throw methodNotSupported();\n  }\n\n  @Override\n  public Map<String, Object> getContext()\n  {\n    return context;","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/union/UnionQuery.java#L105-L141","documentation":"UnionQuery represents a union of queries without a single scan duration; the Query interface's getDuration() is meaningless for it, so the implementation unconditionally throws methodNotSupported(). It is a defensive guard: any caller attempting to read a duration from a union query is using the API incorrectly.","triggerScenarios":"Calling getDuration() on a Query object that is actually a UnionQuery — e.g. generic code that inspects any Query's duration, or equals/hashCode paths in collections that touch duration-deriving state.","commonSituations":"Tooling or custom code iterating over Query trees and calling Query interface methods uniformly; debugging/serializing union queries; third-party code assuming all queries are scan/base queries.","solutions":["Check instanceof UnionQuery (or use a visitor) before calling getDuration()","Treat union queries via their constituent queries to obtain durations","Avoid placing UnionQuery in structures whose equals/hashCode path invokes getDuration()"],"exampleFix":"// before\nDuration d = query.getDuration();\n// after\nfinal Duration d = query instanceof UnionQuery ? null : query.getDuration();","handlingStrategy":"type-guard","validationCode":"if (query instanceof UnionQuery) {\n  throw new IllegalStateException(\"UnionQuery has no duration\");\n}","typeGuard":"static boolean hasDuration(Query<?> q) {\n  return !(q instanceof UnionQuery);\n}","tryCatchPattern":"try {\n  Duration d = query.getDuration();\n} catch (UnsupportedOperationException e) {\n  // union query: handle sub-queries instead\n}","preventionTips":["Use query visitors instead of blanket Query interface calls","Check for UnionQuery before inspecting durations","Avoid putting UnionQuery into hash-based collections if equals touches unsupported methods"],"tags":["druid","query","unsupported-method"],"backgroundTag":"operation-not-supported","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"}