{"record":{"id":"76708bd6a82d19f6","repo":"apache/druid","slug":"cannot-translate-sqltypename-s-to-druid-type-for-76708b","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":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregator.java","lineNumber":122,"sourceCode":"          plannerContext,\n          inputAccessor.getInputRowSignature(),\n          columnRexNode\n      );\n      if (columnArg == null) {\n        return null;\n      }\n\n      if (columnArg.isDirectColumnAccess() &&\n          inputAccessor.getInputRowSignature()\n              .getColumnType(columnArg.getDirectColumn())\n              .map(type -> type.is(ValueType.COMPLEX))\n              .orElse(false)) {\n        fieldName = columnArg.getDirectColumn();\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              name\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        fieldName = dimensionSpec.getDimension();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregator.java#L104-L140","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nSELECT APPROX_QUANTILE_DS(nested_col, 0.5) FROM t\n// after\nSELECT APPROX_QUANTILE_DS(CAST(nested_col AS DOUBLE), 0.5) FROM t","handlingStrategy":"validation","validationCode":"// Validate the column type before aggregating\nEXPLAIN PLAN FOR SELECT SKETCH_ESTIMATE(col) FROM t; -- confirm col's type maps to a Druid type","typeGuard":null,"tryCatchPattern":"try {\n  runSql(query);\n} catch (ISE e) {\n  if (e.getMessage().contains(\"Cannot translate sqlTypeName\")) {\n    // retry with explicit CAST on the input column\n  } else throw e;\n}","preventionTips":["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"],"tags":["java","sql","type-mapping","datasketches"],"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"}