apache/druid · error · UnsupportedOperationException

Cannot convert object to double

Error message

Cannot convert object to double

What it means

During UNNEST processing, the UnnestColumnValueSelectorCursor's primitive double accessor encounters a non-numeric, non-null object from the underlying column and throws UOE. The cursor only knows how to coerce Numbers (and null to 0); arbitrary objects (e.g. strings, complex objects) have no defined double conversion here.

Source

Thrown at processing/src/main/java/org/apache/druid/segment/UnnestColumnValueSelectorCursor.java:146

      @Override
      public ColumnValueSelector makeColumnValueSelector(String columnName)
      {
        if (!outputName.equals(columnName)) {
          return baseColumnSelectorFactory.makeColumnValueSelector(columnName);
        }
        return new ColumnValueSelector()
        {
          @Override
          public double getDouble()
          {
            Object value = getObject();
            if (value == null) {
              return 0;
            }
            if (value instanceof Number) {
              return ((Number) value).doubleValue();
            }
            throw new UOE("Cannot convert object to double");
          }

          @Override
          public float getFloat()
          {
            Object value = getObject();
            if (value == null) {
              return 0;
            }
            if (value instanceof Number) {
              return ((Number) value).floatValue();
            }
            throw new UOE("Cannot convert object to float");
          }

          @Override
          public long getLong()
          {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Ensure the unnest input column contains numeric values (fix ingestion typing or cast values upstream)
  2. Cast/coerce values to numbers before unnesting (e.g. try_cast expressions, JSON value extraction with a numeric type)
  3. Check the column's reported ValueType in the segment metadata; reingest or re-index with the correct type

Example fix

// before
// unnest on column with string values, then SUM over it
// after
// add a virtual column: CAST(JSON_VALUE(col, '$.v') AS DOUBLE) and unnest/aggregate that
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = valueSelector.getObject();
if (v instanceof Number) { double d = ((Number) v).doubleValue(); }

Type guard

static boolean isNumeric(Object o) { return o == null || o instanceof Number; }

Try / catch

try { double d = selector.getDouble(); } catch (UOE e) { /* treat as null/coerce via string parse */ }

Prevention

When it happens

Trigger: Unnesting a column whose values are objects that are neither null nor Number, then reading doubles via getDouble() (e.g. a numeric-typed query expecting double output over a column containing strings or complex values).

Common situations: Unnest input column mis-typed in schema (string values where numbers expected); using UNNEST on a nested-data/array column whose element objects are not numeric; expression output typed as complex fed into numeric aggregation.

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/8049ed0bab151ab7. Report an issue: GitHub.