{"record":{"id":"a2234f991475c06c","repo":"apache/druid","slug":"got-a-s-which-isn-t-a-s-a2234f","errorCode":null,"errorMessage":"Got a [%s] which isn't a %s","messagePattern":"Got a \\[(.+?)\\] which isn't a (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/search/SearchQueryRunner.java","lineNumber":218,"sourceCode":"    {\n      if (selector != null) {\n        final String dimVal = selector.isNull() ? null : String.valueOf(selector.getDouble());\n        if (searchQuerySpec.accept(dimVal)) {\n          set.addTo(new SearchHit(outputName, dimVal), 1);\n        }\n      }\n    }\n  }\n\n  @Override\n  public Sequence<Result<SearchResultValue>> run(\n      final QueryPlus<Result<SearchResultValue>> queryPlus,\n      ResponseContext responseContext\n  )\n  {\n    Query<Result<SearchResultValue>> input = queryPlus.getQuery();\n    if (!(input instanceof SearchQuery)) {\n      throw new ISE(\"Got a [%s] which isn't a %s\", input.getClass(), SearchQuery.class);\n    }\n\n    final SearchQuery query = (SearchQuery) input;\n    final List<SearchQueryExecutor> plan = strategySelector.strategize(query).getExecutionPlan(query, segment);\n    final Object2IntRBTreeMap<SearchHit> retVal = new Object2IntRBTreeMap<>(query.getSort().getComparator());\n    retVal.defaultReturnValue(0);\n\n    int remain = query.getLimit();\n    for (final SearchQueryExecutor executor : plan) {\n      retVal.putAll(executor.execute(remain));\n      remain -= retVal.size();\n    }\n\n    return makeReturnResult(segment, query.getLimit(), retVal);\n  }\n\n  private static Sequence<Result<SearchResultValue>> makeReturnResult(\n      Segment segment,","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/search/SearchQueryRunner.java#L200-L236","documentation":"SearchQueryRunner.run() requires the query inside QueryPlus to be a SearchQuery; anything else throws ISE('Got a [%s] which isn't a %s'). This is an internal type invariant at the segment runner level, mirroring the toolchest check at SearchQueryQueryToolChest.run(). It indicates the search runner received a misrouted query object.","triggerScenarios":"Custom runner chains passing a non-SearchQuery to SearchQueryRunner; toolchest mapping that binds SearchQueryRunner to the wrong query class; programmatically wrapping queries incorrectly.","commonSituations":"Custom extension runner stacks; reflection-based query construction losing type; test harnesses assembling QueryPlus manually with the wrong query.","solutions":["Route only SearchQuery instances to SearchQueryRunner","Correct custom QueryToolChest/warehouse wiring so query types map to their proper runners","Unwrap or convert the query to SearchQuery before invoking the runner"],"exampleFix":"// before\nsearchRunner.run(QueryPlus.wrap(otherQuery), responseContext);\n// after\nif (otherQuery instanceof SearchQuery) {\n  searchRunner.run(QueryPlus.wrap((Query<Result<SearchResultValue>>) otherQuery), responseContext);\n}","handlingStrategy":"type-guard","validationCode":"if (!(query instanceof SearchQuery)) { throw new IllegalArgumentException(\"SearchQueryRunner requires SearchQuery, got \" + query.getClass()); }","typeGuard":"Optional<SearchQuery> asSearchQuery(Query<?> q) { return q instanceof SearchQuery ? Optional.of((SearchQuery) q) : Optional.empty(); }","tryCatchPattern":"try { return searchRunner.run(queryPlus, ctx); } catch (ISE e) { if (e.getMessage().startsWith(\"Got a [\")) { fixQueryRouting(); } else throw e; }","preventionTips":["Bind SearchQueryRunner only to SearchQuery in runner factories","Avoid reflection-based query construction that erases concrete types","Add assertion tests verifying query type before runner dispatch"],"tags":["search-query","query-runner","type-mismatch","dispatch"],"backgroundTag":"incompatible-source-type","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"}