apache/druid · error · org.apache.druid.java.util.common.ISE

Cannot translate sqlTypeName

Error message

Cannot translate sqlTypeName[%s] to Druid type for field[%s]

What it means

When building a theta sketch SQL aggregation, the input RexNode is a column reference whose RelDataType must map to a known Druid ColumnType. Calcites.getColumnTypeForRelDataType() returns null for unmapped SQL types, and the planner then throws this ISE because the sketch aggregator cannot be constructed over an unknown input type.

Solutions

  1. Aggregate over a base column with a standard type (string/long/double) rather than a complex expression
  2. Cast the expression to a supported type in SQL, e.g. CAST(col AS VARCHAR)
  3. Check the Druid and Calcite versions for type-mapping coverage; upgrade if the type mapping was added later
  4. Inspect dataType.getSqlTypeName() (already in the message) and consult Calcites.getColumnTypeForRelDataType to see supported types

Example fix

// before
SELECT APPROX_COUNT_DISTINCT_DS_THETA(NESTED_FIELD(col, 'x')) FROM t
// after
SELECT APPROX_COUNT_DISTINCT_DS_THETA(CAST(NESTED_FIELD(col, 'x') AS VARCHAR)) FROM t
Defensive patterns

Strategy: validation

Validate before calling

RelDataType t = expr.getType();
ColumnType inputType = Calcites.getColumnTypeForRelDataType(t);
if (inputType == null) {
  throw new IllegalArgumentException("Cannot aggregate over SQL type " + t.getSqlTypeName());
}

Type guard

boolean hasMappableType(RelDataType t) {
  return Calcites.getColumnTypeForRelDataType(t) != null;
}

Try / catch

try {
  aggregation = sqlAggregator.toDruidAggregation(name, inputRowSignature, relNode);
} catch (IllegalStateException e) {
  // rewrite query with a CAST of the argument to VARCHAR/DOUBLE before aggregating
}

Prevention

When it happens

Trigger: Issuing a SQL query using APPROX_COUNT_DISTINCT_DS_THETA (or other theta aggregators) over a column/expression whose SQL type has no Druid ColumnType counterpart — e.g. exotic types from extensions, multi-valued/complex types outside the supported set, or ANY-typed expressions.

Common situations: Aggregating over a nested/complex expression the planner cannot type; using a UDF or extension-injected type; version mismatches where Calcite produces a SqlTypeName the Druid type mapping doesn't cover.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchBaseSqlAggregator.java:123

                        .map(type -> (
                            SketchModule.THETA_SKETCH_TYPE.equals(type) ||
                            SketchModule.MERGE_TYPE.equals(type) ||
                            SketchModule.BUILD_TYPE.equals(type)
                        ))
                        .orElse(false)) {
      aggregatorFactory = new SketchMergeAggregatorFactory(
          aggregatorName,
          columnArg.getDirectColumn(),
          sketchSize,
          finalizeSketch || SketchQueryContext.isFinalizeOuterSketches(plannerContext),
          null,
          null
      );
    } else {
      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
        );
      }

      if (inputType.is(ValueType.COMPLEX)) {
        if (!isValidComplexInputType(inputType)) {
          plannerContext.setPlanningError(
              "Using APPROX_COUNT_DISTINCT() or enabling approximation with COUNT(DISTINCT) is not supported for"
              + " column type [%s]. You can disable approximation by setting [%s: false] in the query context.",
              columnArg.getDruidType(),
              PlannerConfig.CTX_KEY_USE_APPROXIMATE_COUNT_DISTINCT
          );
          return null;
        }
      }

View on GitHub (pinned to 9b90983fd2)