{"record":{"id":"c9bc5581ce11ece6","repo":"apache/druid","slug":"cannot-translate-sqltypename-s-to-druid-type-for-c9bc55","errorCode":null,"errorMessage":"Cannot translate sqlTypeName[%s] to Druid type for field[%s]","messagePattern":"Cannot translate sqlTypeName\\[(.+?)\\] to Druid type for field\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java","lineNumber":140,"sourceCode":"                        .orElse(false)) {\n      aggregatorFactory = new HllSketchMergeAggregatorFactory(\n          aggregatorName,\n          columnArg.getDirectColumn(),\n          logK,\n          tgtHllType,\n\n          // For HllSketchMergeAggregatorFactory, stringEncoding is only advisory to aid in detection of mismatched\n          // merges. It does not affect the results of the aggregator. At this point in the code, we do not know what\n          // the input encoding of the original sketches was, so we set it to the default.\n          HllSketchAggregatorFactory.DEFAULT_STRING_ENCODING,\n          finalizeSketch || SketchQueryContext.isFinalizeOuterSketches(plannerContext),\n          ROUND\n      );\n    } else {\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\n        );\n      }\n\n      final DimensionSpec dimensionSpec;\n\n      if (columnArg.isDirectColumnAccess()) {\n        dimensionSpec = columnArg.getSimpleExtraction().toDimensionSpec(null, inputType);\n      } else {\n        String virtualColumnName = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(\n            columnArg,\n            dataType\n        );\n        dimensionSpec = new DefaultDimensionSpec(virtualColumnName, null, inputType);\n      }\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nSELECT APPROX_COUNT_DISTINCT_DS_HLL(weird_col) FROM t; -- weird_col typed OTHER\n// after\nSELECT APPROX_COUNT_DISTINCT_DS_HLL(CAST(weird_col AS VARCHAR)) FROM t;","handlingStrategy":"validation","validationCode":"ColumnType t = Calcites.getColumnTypeForRelDataType(relDataType); if (t == null) { throw new IllegalArgumentException(\"unsupported SQL type for sketch field: \" + relDataType.getSqlTypeName()); }","typeGuard":null,"tryCatchPattern":"try { agg = aggregator.toDruidAggregation(name, metricFactory, temporaryTable, input); } catch (IllegalStateException e) { throw new IllegalStateException(\"Check input column type for sketch aggregation: \" + e.getMessage(), e); }","preventionTips":["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"],"tags":["sql","type-mismatch","datasketches","type-translation"],"backgroundTag":"type-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}