apache/druid · error · UnsupportedOperationException
Cannot convert object to long
Error message
Cannot convert object to long
What it means
Runtime type guard in the unnest cursor's column value selector: when the unnested cell value is neither null nor a Number, the selector cannot fulfill a primitive-long read and raises this error. It fires when a query reads an unnested column as LONG while the underlying unnested values are non-numeric (e.g. strings); fix by coercing the values to numbers or using a column accessor matching the actual value type.
Source
Thrown at processing/src/main/java/org/apache/druid/segment/UnnestColumnValueSelectorCursor.java:172
return 0;
}
if (value instanceof Number) {
return ((Number) value).floatValue();
}
throw new UOE("Cannot convert object to float");
}
@Override
public long getLong()
{
Object value = getObject();
if (value == null) {
return 0;
}
if (value instanceof Number) {
return ((Number) value).longValue();
}
throw new UOE("Cannot convert object to long");
}
@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
columnValueSelector.inspectRuntimeShape(inspector);
}
@Override
public boolean isNull()
{
return getObject() == null;
}
@Nullable
@Override
public Object getObject()
{View on GitHub (pinned to 9b90983fd2)
Solutions
- Cast the unnest source values to numbers before the query
- Fix the column's ValueType at ingestion so primitive selectors are used
- Use string/JSON expressions to extract numeric fields instead of long selectors on objects
Defensive patterns
Strategy: type-guard
Validate before calling
Object v = selector.getObject();
if (v instanceof Number) { long l = ((Number) v).longValue(); } Type guard
static boolean isLongSafe(Object o) { return o == null || o instanceof Number; } Try / catch
try { long l = selector.getLong(); } catch (UOE e) { /* fallback: parse or skip */ } Prevention
- Check column type before running long aggregations on unnested data
- Cast numeric strings to LONG at ingestion
- Add schema tests that fail if a numeric column arrives as strings
When it happens
Trigger: getLong() invoked on the unnest cursor while iterating a column whose elements are objects (e.g. strings, nested structures, complex/metric payloads).
Common situations: LONG aggregations (COUNT-style or longSum) over an unnested column holding strings; mixed-type array columns where some elements are objects.
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
- Cannot convert object to double
- Cannot convert object to float
- Cannot deserialize type[%s] to an RoaringBitmap64Counter:
- Expected a number or an instance of MergingDigest, but recei
- Object is not of a type that can be deserialized to a quanti
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/a977fb63eb219a78.
Report an issue: GitHub.