{"record":{"id":"8bfc404df3390bb9","repo":"apache/druid","slug":"cannot-accept-both-splitpoints-and-numbins","errorCode":null,"errorMessage":"Cannot accept both 'splitPoints' and 'numBins'","messagePattern":"Cannot accept both 'splitPoints' and 'numBins'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToHistogramPostAggregator.java","lineNumber":62,"sourceCode":"\n  private final String name;\n  private final PostAggregator field;\n  private final double[] splitPoints;\n  private final Integer numBins;\n\n  @JsonCreator\n  public KllDoublesSketchToHistogramPostAggregator(\n      @JsonProperty(\"name\") final String name,\n      @JsonProperty(\"field\") final PostAggregator field,\n      @JsonProperty(\"splitPoints\") @Nullable final double[] splitPoints,\n      @JsonProperty(\"numBins\") @Nullable final Integer numBins)\n  {\n    this.name = Preconditions.checkNotNull(name, \"name is null\");\n    this.field = Preconditions.checkNotNull(field, \"field is null\");\n    this.splitPoints = splitPoints;\n    this.numBins = numBins;\n    if (splitPoints != null && numBins != null) {\n      throw new IAE(\"Cannot accept both 'splitPoints' and 'numBins'\");\n    }\n  }\n\n  @Override\n  public Object compute(final Map<String, Object> combinedAggregators)\n  {\n    final KllDoublesSketch sketch = (KllDoublesSketch) field.compute(combinedAggregators);\n    final int numBins = this.splitPoints != null ? this.splitPoints.length + 1 :\n        (this.numBins != null ? this.numBins.intValue() : DEFAULT_NUM_BINS);\n    if (numBins < 2) {\n      throw new IAE(\"at least 2 bins expected\");\n    }\n    if (sketch.isEmpty()) {\n      final double[] histogram = new double[numBins];\n      Arrays.fill(histogram, Double.NaN);\n      return histogram;\n    }\n    final double[] splitPoints;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToHistogramPostAggregator.java#L44-L80","documentation":"The KllDoublesSketchToHistogramPostAggregator constructor validates that 'splitPoints' (explicit bin edges) and 'numBins' (auto-generated bin count) are mutually exclusive. Supplying both is ambiguous, so it throws IllegalArgumentException at construction time. Exactly one (or neither, defaulting bins) must be provided.","triggerScenarios":"Constructing KllDoublesSketchToHistogramPostAggregator(name, field, splitPoints, numBins) with both arguments non-null — e.g. a JSON spec containing both \"splitPoints\": [...] and \"numBins\": 10.","commonSituations":"Copy-pasting a spec and adding numBins while forgetting to remove splitPoints; programmatic spec builders that set defaults for both fields; template-driven query generation.","solutions":["Remove either 'splitPoints' or 'numBins' from the post-aggregator spec, keeping only one","If you need explicit edges, delete numBins; if you want even bins, delete splitPoints","In spec-builder code, only emit the second field when the first is null"],"exampleFix":"// before\n{\"type\":\"kllDoublesSketchToHistogram\",\"name\":\"h\",\"field\":f,\"splitPoints\":[1.0,2.0],\"numBins\":10}\n// after\n{\"type\":\"kllDoublesSketchToHistogram\",\"name\":\"h\",\"field\":f,\"splitPoints\":[1.0,2.0]}","handlingStrategy":"validation","validationCode":"Map<String,Object> spec = readSpec();\nif (spec.containsKey(\"splitPoints\") && spec.containsKey(\"numBins\")) {\n  throw new IllegalArgumentException(\"Provide only one of splitPoints and numBins\");\n}","typeGuard":null,"tryCatchPattern":"try { new KllDoublesSketchToHistogramPostAggregator(name, field, sp, nb); } catch (IllegalArgumentException e) { log.error(\"Histogram spec invalid: {}\", e.getMessage()); }","preventionTips":["Validate post-aggregator JSON specs before query submission","Only emit one of splitPoints/numBins from spec builders","Document mutual exclusivity in generated specs"],"tags":["druid","datasketches","kll","post-aggregator","validation"],"backgroundTag":"mutually-exclusive-options","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"}