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
When planning an SQL aggregation over an HLL sketch, HllSketchBaseSqlAggregator translates the input column's RelDataType (SQL type) into a Druid ColumnType. If the SQL type has no Druid equivalent (Calcites.getColumnTypeForRelDataType returns null), an IllegalStateException is thrown naming the sqlTypeName and field. This happens for SQL types the sketch aggregator cannot consume as pre-aggregated input.
Source
Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java:140
.orElse(false)) {
aggregatorFactory = new HllSketchMergeAggregatorFactory(
aggregatorName,
columnArg.getDirectColumn(),
logK,
tgtHllType,
// For HllSketchMergeAggregatorFactory, stringEncoding is only advisory to aid in detection of mismatched
// merges. It does not affect the results of the aggregator. At this point in the code, we do not know what
// the input encoding of the original sketches was, so we set it to the default.
HllSketchAggregatorFactory.DEFAULT_STRING_ENCODING,
finalizeSketch || SketchQueryContext.isFinalizeOuterSketches(plannerContext),
ROUND
);
} 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
);
}
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);
}
View on GitHub (pinned to 9b90983fd2)
Solutions
- Ensure the sketch input column is of a supported Druid type (string base64 sketch or numeric) and re-index segments with wrong types
- Use HLLSketchBuild/other SQL helpers with the correct argument (e.g. DC or COUNT(DISTINCT) on a supported column)
- If a custom type, convert/cast the expression to a supported type in SQL before aggregating
Example fix
// before SELECT APPROX_COUNT_DISTINCT_DS_HLL(weird_col) FROM t; -- weird_col typed OTHER // after SELECT APPROX_COUNT_DISTINCT_DS_HLL(CAST(weird_col AS VARCHAR)) FROM t;
Defensive patterns
Strategy: validation
Validate before calling
ColumnType t = Calcites.getColumnTypeForRelDataType(relDataType); if (t == null) { throw new IllegalArgumentException("unsupported SQL type for sketch field: " + relDataType.getSqlTypeName()); } Try / catch
try { agg = aggregator.toDruidAggregation(name, metricFactory, temporaryTable, input); } catch (IllegalStateException e) { throw new IllegalStateException("Check input column type for sketch aggregation: " + e.getMessage(), e); } Prevention
- Aggregate only over string-typed base64 sketch columns or numeric columns
- Inspect segment schema (OTHER/NULL types) before writing sketch SQL
- Cast unsupported expressions to VARCHAR/numeric in SQL first
When it happens
Trigger: Running a sketch aggregation whose first argument is a column of an unmappable SQL type (e.g. NULL, OTHER, complex/custom types) rather than a string-typed base64 sketch or a numeric column to count-distinguish.
Common situations: Sketch aggregation over a column typed as OTHER/complex in the segment metadata; passing a literal or expression with an unsupported RelDataType; schema drift where a column changed to an unsupported type.
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
- Invalid input [%s] of type [%s] for [%s] aggregator [%s]
- Unsupported type %s
- Object is not of a type[%s] that can be deserialized to sket
- Object is not of a type that can be deserialized to a quanti
- Object is not of a type that can be deserialized to a KllFlo
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/c9bc5581ce11ece6.
Report an issue: GitHub.