{"record":{"id":"cc935bc878b65cc6","repo":"apache/druid","slug":"string-is-not-a-metric-column-type","errorCode":null,"errorMessage":"String is not a metric column type","messagePattern":"String is not a metric column type","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java","lineNumber":793,"sourceCode":"      String metric\n  )\n  {\n    final MetricDesc metricDesc = rowSelector.getMetric(metric);\n    if (metricDesc == null) {\n      return NilColumnValueSelector.instance();\n    }\n    int metricIndex = metricDesc.getIndex();\n    switch (metricDesc.getCapabilities().getType()) {\n      case COMPLEX:\n        return new ObjectMetricColumnSelector(rowSelector, currEntry, metricDesc);\n      case LONG:\n        return new LongMetricColumnSelector(rowSelector, currEntry, metricIndex);\n      case FLOAT:\n        return new FloatMetricColumnSelector(rowSelector, currEntry, metricIndex);\n      case DOUBLE:\n        return new DoubleMetricColumnSelector(rowSelector, currEntry, metricIndex);\n      case STRING:\n        throw new IllegalStateException(\"String is not a metric column type\");\n      default:\n        throw new ISE(\"Unknown metric value type: %s\", metricDesc.getCapabilities().getType());\n    }\n  }\n\n  public Interval getInterval()\n  {\n    DateTime min = DateTimes.utc(minTimestamp);\n    return new Interval(min, isEmpty() ? min : queryGranularity.increment(DateTimes.utc(getMaxTimeMillis())));\n  }\n\n  @Nullable\n  public DateTime getMinTime()\n  {\n    return isEmpty() ? null : DateTimes.utc(getMinTimeMillis());\n  }\n\n  @Nullable","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java#L775-L811","documentation":"IncrementalIndex's metric column selector factory throws IllegalStateException('String is not a metric column type') when a column declared as a metric has STRING capabilities. Metrics must be numeric (long/float/double) or complex; a string-typed metric indicates the schema mislabels a dimension as a metric.","triggerScenarios":"Constructing or querying an IncrementalIndex whose metricsSpec includes a metric of type 'string', or where column capabilities resolve the metric column to STRING.","commonSituations":"ingestion spec metricsSpec listing a dimension (e.g. a string aggregator name) as a metric; schema/rollup mistakes after changing a column from dimension to metric; typos in aggregator type names causing fallback to string type.","solutions":["Remove the string column from metricsSpec or declare it in the dimensionsSpec instead","Use a proper numeric/complex aggregator for metric columns","Check capabilities: assert getType() != ValueType.STRING before treating a column as a metric"],"exampleFix":"// before\n\"metricsSpec\": [{\"type\": \"string\", \"name\": \"country\"}] // invalid\n// after\n\"metricsSpec\": [{\"type\": \"doubleSum\", \"name\": \"revenue\", \"fieldName\": \"revenue\"}]\n// and move \"country\" to dimensionsSpec","handlingStrategy":"validation","validationCode":"if (capabilities.getType() == ValueType.STRING) { throw new IllegalArgumentException(\"Column \" + name + \" is a dimension, not a metric\"); }","typeGuard":null,"tryCatchPattern":"try { selector = index.makeColumnValueSelector(...); } catch (IllegalStateException e) { if (e.getMessage().contains(\"String is not a metric column type\")) { throw new IllegalStateException(\"metricsSpec mislabels a string column as metric\", e); } throw e; }","preventionTips":["Cross-check metricsSpec aggregator names against dimensionsSpec","Ensure column capabilities are derived from the actual schema","Validate ingestion specs before submission (schema linting)"],"tags":["java","ingestion","schema","metrics"],"backgroundTag":"schema-validation-failed","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"}