{"record":{"id":"9bebf2904c4d7de0","repo":"apache/druid","slug":"comparing-arrays-of-variance-values-is-not-support","errorCode":null,"errorMessage":"Comparing arrays of variance values is not supported","messagePattern":"Comparing arrays of variance values is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchToVariancesPostAggregator.java","lineNumber":81,"sourceCode":"      for (int i = 0; i < values.length; i++) {\n        stats[i].addValue(values[i]);\n      }\n    }\n    final double[] variances = new double[sketch.getNumValues()];\n    Arrays.setAll(variances, i -> stats[i].getVariance());\n    return variances;\n  }\n\n  @Override\n  public ColumnType getType(ColumnInspector signature)\n  {\n    return ColumnType.DOUBLE_ARRAY;\n  }\n\n  @Override\n  public Comparator<double[]> getComparator()\n  {\n    throw new IAE(\"Comparing arrays of variance values is not supported\");\n  }\n\n  @Override\n  public byte[] getCacheKey()\n  {\n    return new CacheKeyBuilder(AggregatorUtil.ARRAY_OF_DOUBLES_SKETCH_TO_VARIANCES_CACHE_TYPE_ID)\n        .appendCacheable(getField())\n        .build();\n  }\n\n}\n","sourceCodeStart":63,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchToVariancesPostAggregator.java#L63-L93","documentation":"ArrayOfDoublesSketchToVariancesPostAggregator outputs a double[] of per-column variances. Variance arrays have no defined comparison, so getComparator() throws IAE unconditionally to block sorting on this output.","triggerScenarios":"Calling getComparator(), e.g. referencing this post-aggregator in an orderBy spec or generic code that obtains comparators for all post-aggregators.","commonSituations":"Users ranking rows by variance vectors; query builders that attach sort clauses to all post-aggregators.","solutions":["Sort on an individual variance value exposed via a numeric post-aggregator or expression","Remove ordering clauses on this post-aggregator","Rank in application code with a custom comparator"],"exampleFix":"// before\n.addOrderBy(new OrderByColumnSpec(\"variances\"))\n// after\n.addOrderBy(new OrderByColumnSpec(\"varianceOfFirst\")) // numeric expression","handlingStrategy":"try-catch","validationCode":"if (orderByColumns.stream().anyMatch(c -> \"variances\".equals(c.getDimension()))) {\n  throw new IllegalArgumentException(\"Cannot order by variances array output\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return queryClient.run(query);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"variance values\")) {\n    return runQueryWithAlternateOrdering(query, \"varianceOfFirst\");\n  }\n  throw e;\n}","preventionTips":["Project individual variances as scalars when sorting is needed","Exclude DOUBLE_ARRAY post-aggregators from orderBy specs","Validate output types of all post-aggregators referenced by sort clauses"],"tags":["druid","datasketches","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}