{"record":{"id":"118f66a6cf4d19a5","repo":"apache/druid","slug":"invalid-input-s-of-type-s-for-s-aggregato","errorCode":null,"errorMessage":"Invalid input [%s] of type [%s] for [%s] aggregator [%s]","messagePattern":"Invalid input \\[(.+?)\\] of type \\[(.+?)\\] for \\[(.+?)\\] aggregator \\[(.+?)\\]","errorType":"exception","errorClass":"ISE","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchBuildAggregatorFactory.java","lineNumber":155,"sourceCode":"  @Override\n  public AggregatorFactory withName(String newName)\n  {\n    return new HllSketchBuildAggregatorFactory(\n        newName,\n        getFieldName(),\n        getLgK(),\n        getTgtHllType(),\n        getStringEncoding(),\n        isShouldFinalize(),\n        isRound()\n    );\n  }\n\n  private void validateInputs(@Nullable ColumnCapabilities capabilities)\n  {\n    if (capabilities != null) {\n      if (capabilities.is(ValueType.COMPLEX)) {\n        throw new ISE(\n            \"Invalid input [%s] of type [%s] for [%s] aggregator [%s]\",\n            getFieldName(),\n            capabilities.asTypeString(),\n            HllSketchModule.BUILD_TYPE_NAME,\n            getName()\n        );\n      }\n    }\n  }\n\n  private HllSketchUpdater formulateSketchUpdater(ColumnSelectorFactory columnSelectorFactory)\n  {\n    final ColumnCapabilities capabilities = columnSelectorFactory.getColumnCapabilities(getFieldName());\n    validateInputs(capabilities);\n\n    HllSketchUpdater updater = null;\n    if (capabilities != null &&\n        StringEncoding.UTF8.equals(getStringEncoding()) && ValueType.STRING.equals(capabilities.getType())) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchBuildAggregatorFactory.java#L137-L173","documentation":"HllSketchBuildAggregatorFactory.validateInputs throws IllegalStateException when the input column's capabilities report ValueType.COMPLEX, i.e. the field already contains serialized HLL sketches. Building a new sketch from an already-sketch column is invalid; use the merge-type aggregator (HllSketchMergeFactory) for that. It is invoked while factorizing vectorized/SQL aggregators.","triggerScenarios":"Configuring an HLLSketchBuild aggregator whose fieldName points to a COMPLEX column (e.g. an HLLSketch-typed column produced by ingestion or another sketch), during query factorizeVector or formulateSketchUpdater.","commonSituations":"Mistakenly using 'HLLSketchBuild' on a column ingested as sketch (should be 'HLLSketchMerge'); copying a query spec that had sketch output columns and feeding them back as build inputs; schema drift after switching ingestion to store sketches.","solutions":["Switch the aggregator type from HLLSketchBuild to HLLSketchMerge when the input column already holds sketches.","Point the build aggregator at the raw string/numeric column that should be sketched.","Fix ingestion spec so the source column stored is raw data, not a serialized sketch, if raw building is intended.","In SQL use APPROX_COUNT_DISTINCT_DS_HLL on raw values and DS_HLL(...) on sketch columns appropriately."],"exampleFix":"// before\n{\"type\": \"HLLSketchBuild\", \"name\": \"s\", \"fieldName\": \"sketch_col\"}\n// after\n{\"type\": \"HLLSketchMerge\", \"name\": \"s\", \"fieldName\": \"sketch_col\"}","handlingStrategy":"validation","validationCode":"ColumnCapabilities caps = columnCapabilities(fieldName); if (caps != null && caps.is(ValueType.COMPLEX) && factory.getType().equals(\"HLLSketchBuild\")) { throw new IllegalArgumentException(\"use HLLSketchMerge for sketch columns\"); }","typeGuard":"boolean isComplexColumn = caps != null && caps.is(ValueType.COMPLEX);","tryCatchPattern":"try { factory.factorize(...) } catch (ISE e) { /* switch to HLLSketchMerge */ }","preventionTips":["Match aggregator type to column type: build for raw, merge for sketch columns","Inspect column schema (segment metadata) before composing queries","In SQL prefer DS_HLL()/APPROX_COUNT_DISTINCT_DS_HLL which pick correct modes"],"tags":["datasketches","hll","invalid-input","aggregation","type-mismatch"],"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-14T05:17:10.506Z"}