apache/druid · error · DruidException

invalidInput

invalidInput

Error message

Aggregation [%s] does not support type [%s], column [%s]

What it means

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).

Solutions

  1. Remove the CAST and aggregate the raw STRING column: SELECT bitmap64_exact_count(col) ...
  2. Ensure the underlying column is a STRING bitmap-encoded column, not numeric.
  3. Use a standard numeric aggregator (e.g. COUNT DISTINCT, HLL) if the column truly is numeric.

Example fix

// before
SELECT bitmap64_exact_count(CAST(user_id AS BIGINT)) FROM t;
// after
SELECT bitmap64_exact_count(user_id) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the argument is a plain STRING column, no CAST
RelDataType t = columnRexNode.getType();
if (columnRexNode.isA(SqlKind.CAST) || SqlTypeName.CHAR_TYPES.contains(t.getSqlTypeName()) == false) {
  throw new IllegalStateException("bitmap64_exact_count requires an uncast STRING column");
}

Try / catch

try { return client.query(sql); }
catch (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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/88d0ab43290c9722. Report an issue: GitHub.

Appendix: source

Thrown at extensions-contrib/druid-exact-count-bitmap/src/main/java/org/apache/druid/query/aggregation/exact/count/bitmap64/sql/Bitmap64ExactCountSqlAggregator.java:143

                          .orElse(false);
  }

  /**
   * Rejects SQL queries pertaining to using non-numeric columns that can be implicitly cast to numeric values (e.g. String).
   * There is a second layer of protection at {@link Bitmap64ExactCountBuildAggregatorFactory#validateNumericColumn},
   * which checks the column types when given a query in Druid Native.
   *
   * <p>
   * This function aims to keep the Exception type consistent with the rest of Druid.
   * </p>
   */
  private void rejectImplicitCastsToNumericType(RexNode columnRexNode, String columnName)
  {
    if (columnRexNode.isA(SqlKind.CAST)) {
      final RelDataType operandType = ((RexCall) columnRexNode).operands.get(0).getType();
      final ColumnType operandDruidType = Calcites.getColumnTypeForRelDataType(operandType);
      if (operandDruidType == null || !operandDruidType.isNumeric()) {
        throw SimpleSqlAggregator.badTypeException(columnName, NAME, ColumnType.STRING);
      }
    }
  }

  private AggregatorFactory createBuildAggregatorFactory(
      final RexNode columnRexNode,
      final DruidExpression columnArg,
      final VirtualColumnRegistry virtualColumnRegistry,
      final String aggregatorName
  )
  {
    final RelDataType dataType = columnRexNode.getType();
    final ColumnType inputType = Calcites.getColumnTypeForRelDataType(dataType);
    if (inputType == null) {
      throw new ISE(
          "Cannot translate sqlTypeName[%s] to Druid type for field[%s]",
          dataType.getSqlTypeName(),
          aggregatorName

View on GitHub (pinned to 9b90983fd2)