{"record":{"id":"de5be1539ce9e2db","repo":"apache/druid","slug":"invalid-operation-for-averagerfactorywrapper","errorCode":null,"errorMessage":"Invalid operation for AveragerFactoryWrapper.","messagePattern":"Invalid operation for AveragerFactoryWrapper\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java","lineNumber":69,"sourceCode":"  /**\n   * Simple constructor\n   *\n   * @param af\n   * @param prefix\n   */\n  public AveragerFactoryWrapper(AveragerFactory<T, R> af, String prefix)\n  {\n    this.af = af;\n    this.prefix = prefix;\n  }\n\n  /**\n   * Not implemented. Throws UnsupportedOperationException.\n   */\n  @Override\n  public Aggregator factorize(ColumnSelectorFactory metricFactory) throws UnsupportedOperationException\n  {\n    throw new UnsupportedOperationException(\"Invalid operation for AveragerFactoryWrapper.\");\n  }\n\n  /**\n   * Not implemented. Throws UnsupportedOperationException.\n   */\n  @Override\n  public BufferAggregator factorizeBuffered(ColumnSelectorFactory metricFactory)\n  {\n    throw new UnsupportedOperationException(\"Invalid operation for AveragerFactoryWrapper.\");\n  }\n\n  /* (non-Javadoc)\n   * @see org.apache.druid.query.aggregation.AggregatorFactory#getComparator()\n   */\n  @Override\n  public Comparator<?> getComparator()\n  {\n    return af.getComparator();","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java#L51-L87","documentation":"AveragerFactoryWrapper.factorize is deliberately unimplemented: this wrapper adapts an AveragerFactory for the moving-average query engine and must never produce a standard (non-windowed) Aggregator. The moving-average machinery uses getAveragerFactory/averagers instead of Druid's normal factorize path, so any call here means the factory leaked into the standard aggregation pipeline.","triggerScenarios":"An 'averager' aggregator spec from a movingAverage query is used outside the moving-average engine, e.g. placed in a regular groupBy/topN aggregations list, causing Druid to call factorize on it.","commonSituations":"Config mistake: putting moving-average averager specs into a normal query's aggregations; reusing movingAverage query JSON in a groupBy; a query engine path that ignores movingAverage-specific handling.","solutions":["Only use 'averager' specs inside the 'aggregations' of a movingAverage query, not in groupBy/topN/timesSeries aggregations","If a standard aggregation is needed, replace the averager with a native Druid aggregator (e.g. doubleSum) plus post-aggregators","Verify the query type is 'movingAverage' and the averager specs sit under its aggregations field"],"exampleFix":"// before\n{\"queryType\":\"groupBy\", \"aggregations\":[{\"type\":\"averager\", ...}]}\n// after\n{\"queryType\":\"movingAverage\", \"aggregations\":[{\"type\":\"averager\", ...}]}","handlingStrategy":"validation","validationCode":"// Validate query JSON before submission\nfunction assertAveragerOnlyInMovingAverage(query) {\n  if (query.queryType !== 'movingAverage' &&\n      (query.aggregations || []).some(a => a.type === 'averager')) {\n    throw new Error('averager specs are only valid in movingAverage queries');\n  }\n}","typeGuard":null,"tryCatchPattern":"try { runQuery(q); } catch (UnsupportedOperationException e) { if (e.getMessage().contains(\"AveragerFactoryWrapper\")) { /* switch to movingAverage query type */ } else { throw e; } }","preventionTips":["Only use 'averager' specs in movingAverage queries","Never copy moving-average aggregations into groupBy/topN specs","Use standard aggregators for non-moving-average queries"],"tags":["druid","moving-average","aggregator"],"backgroundTag":"method-not-implemented","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"}