apache/druid · error · IllegalStateException
Cannot translate sqlTypeName[%s] to Druid type for field[%s]
Error message
Cannot translate sqlTypeName[%s] to Druid type for field[%s]
What it means
ArrayOfDoublesSketchSqlAggregator.toDruidAggregation validates the input column's relational type before building the native aggregator. If Calcites.getColumnTypeForRelDataType cannot map the column's SQL type name to a Druid type, it throws this ISE. It means the sketch aggregation was applied to a column with a type the Druid SQL type system cannot translate.
Source
Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregator.java:122
plannerContext,
inputAccessor.getInputRowSignature(),
columnRexNode
);
if (columnArg == null) {
return null;
}
if (columnArg.isDirectColumnAccess() &&
inputAccessor.getInputRowSignature()
.getColumnType(columnArg.getDirectColumn())
.map(type -> type.is(ValueType.COMPLEX))
.orElse(false)) {
fieldName = columnArg.getDirectColumn();
} 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(),
name
);
}
final DimensionSpec dimensionSpec;
if (columnArg.isDirectColumnAccess()) {
dimensionSpec = columnArg.getSimpleExtraction().toDimensionSpec(null, inputType);
} else {
String virtualColumnName = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(
columnArg,
dataType
);
dimensionSpec = new DefaultDimensionSpec(virtualColumnName, null, inputType);
}
fieldName = dimensionSpec.getDimension();View on GitHub (pinned to 9b90983fd2)
Solutions
- Verify the input column is a plain numeric or array-of-doubles-sketch typed column; fix the query to aggregate on a supported column
- Inspect the SQL type of the expression (EXPLAIN PLAN) and add an explicit CAST to a supported type (BIGINT/DOUBLE)
- Ensure the datasketches extension is loaded and versions match on all nodes
Example fix
// before SELECT APPROX_QUANTILE_DS(nested_col, 0.5) FROM t // after SELECT APPROX_QUANTILE_DS(CAST(nested_col AS DOUBLE), 0.5) FROM t
Defensive patterns
Strategy: validation
Validate before calling
// Validate the column type before aggregating EXPLAIN PLAN FOR SELECT SKETCH_ESTIMATE(col) FROM t; -- confirm col's type maps to a Druid type
Try / catch
try {
runSql(query);
} catch (ISE e) {
if (e.getMessage().contains("Cannot translate sqlTypeName")) {
// retry with explicit CAST on the input column
} else throw e;
} Prevention
- Aggregate only on typed numeric or sketch columns
- Use EXPLAIN PLAN to verify inferred column types
- Add explicit CASTs for expressions with unclear types
- Keep the datasketches extension loaded on all nodes
When it happens
Trigger: Applying SKETCH_ESTIMATE / ArrayOfDoubles sketch SQL aggregators to an expression or column whose RelDataType has a SqlTypeName with no Druid mapping (e.g. complex/unsupported types, NULL-typed expressions from bad casts).
Common situations: Aggregating over a nested/complex column that isn't typed as expected, a CAST producing an unmappable type, or extension version mismatches leaving the type registry incomplete.
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
- requires a ThetaSketch as the argument
- Cannot translate sqlTypeName[%s] to Druid type for field[%s]
- Cannot translate sqlTypeName[%s] to Druid type for field[%s]
- Not implemented
- Not implemented
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/76708bd6a82d19f6.
Report an issue: GitHub.