{"record":{"id":"88d0ab43290c9722","repo":"apache/druid","slug":"invalidinput","errorCode":"invalidInput","errorMessage":"Aggregation [%s] does not support type [%s], column [%s]","messagePattern":"Aggregation \\[(.+?)\\] does not support type \\[(.+?)\\], column \\[(.+?)\\]","errorType":"error_code","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/druid-exact-count-bitmap/src/main/java/org/apache/druid/query/aggregation/exact/count/bitmap64/sql/Bitmap64ExactCountSqlAggregator.java","lineNumber":143,"sourceCode":"                          .orElse(false);\n  }\n\n  /**\n   * Rejects SQL queries pertaining to using non-numeric columns that can be implicitly cast to numeric values (e.g. String).\n   * There is a second layer of protection at {@link Bitmap64ExactCountBuildAggregatorFactory#validateNumericColumn},\n   * which checks the column types when given a query in Druid Native.\n   *\n   * <p>\n   * This function aims to keep the Exception type consistent with the rest of Druid.\n   * </p>\n   */\n  private void rejectImplicitCastsToNumericType(RexNode columnRexNode, String columnName)\n  {\n    if (columnRexNode.isA(SqlKind.CAST)) {\n      final RelDataType operandType = ((RexCall) columnRexNode).operands.get(0).getType();\n      final ColumnType operandDruidType = Calcites.getColumnTypeForRelDataType(operandType);\n      if (operandDruidType == null || !operandDruidType.isNumeric()) {\n        throw SimpleSqlAggregator.badTypeException(columnName, NAME, ColumnType.STRING);\n      }\n    }\n  }\n\n  private AggregatorFactory createBuildAggregatorFactory(\n      final RexNode columnRexNode,\n      final DruidExpression columnArg,\n      final VirtualColumnRegistry virtualColumnRegistry,\n      final String aggregatorName\n  )\n  {\n    final RelDataType dataType = columnRexNode.getType();\n    final ColumnType inputType = Calcites.getColumnTypeForRelDataType(dataType);\n    if (inputType == null) {\n      throw new ISE(\n          \"Cannot translate sqlTypeName[%s] to Druid type for field[%s]\",\n          dataType.getSqlTypeName(),\n          aggregatorName","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/druid-exact-count-bitmap/src/main/java/org/apache/druid/query/aggregation/exact/count/bitmap64/sql/Bitmap64ExactCountSqlAggregator.java#L125-L161","documentation":"Bitmap64ExactCountSqlAggregator's rejectImplicitCastsToNumericType rejects SQL aggregations where the bitmap64_exact_count column argument is wrapped in an implicit CAST to a numeric type; the bitmap aggregator operates on STRING (bitmap-encoded) columns. The message \"Aggregation [bitmap64_exact_count] does not support type [..], column [..]\" is a SimpleSqlAggregator.badTypeException (a DruidException with invalidInput code).","triggerScenarios":"Writing SQL like SELECT bitmap64_exact_count(CAST(col AS BIGINT)) or applying the aggregator to a numeric column, where Calcite inserts a CAST to a numeric type; the helper sees the CAST operand is not STRING.","commonSituations":"Column declared as numeric in the schema but expected to be bitmap-encoded string; accidental SQL that casts the argument; mixing up bitmap64_exact_count with regular numeric COUNT aggregators.","solutions":["Remove the CAST and aggregate the raw STRING column: SELECT bitmap64_exact_count(col) ...","Ensure the underlying column is a STRING bitmap-encoded column, not numeric.","Use a standard numeric aggregator (e.g. COUNT DISTINCT, HLL) if the column truly is numeric."],"exampleFix":"// before\nSELECT bitmap64_exact_count(CAST(user_id AS BIGINT)) FROM t;\n// after\nSELECT bitmap64_exact_count(user_id) FROM t;","handlingStrategy":"validation","validationCode":"// Ensure the argument is a plain STRING column, no CAST\nRelDataType t = columnRexNode.getType();\nif (columnRexNode.isA(SqlKind.CAST) || SqlTypeName.CHAR_TYPES.contains(t.getSqlTypeName()) == false) {\n  throw new IllegalStateException(\"bitmap64_exact_count requires an uncast STRING column\");\n}","typeGuard":null,"tryCatchPattern":"try { return client.query(sql); }\ncatch (DruidException e) { if (e.getErrorCode().equals(\"invalidInput\") && e.getMessage().contains(\"does not support type\")) { throw new IllegalArgumentException(\"Remove CAST around bitmap64_exact_count argument\"); } throw e; }","preventionTips":["Aggregate only bitmap-encoded STRING columns with bitmap64_exact_count.","Avoid implicit casts in SQL by matching column types in the schema.","Use HLL sketches or COUNT DISTINCT for numeric distinct-count needs."],"tags":["sql","aggregation","type-mismatch","bitmap"],"backgroundTag":"dtype-mismatch","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"}