{"record":{"id":"a977fb63eb219a78","repo":"apache/druid","slug":"cannot-convert-object-to-long","errorCode":null,"errorMessage":"Cannot convert object to long","messagePattern":"Cannot convert object to long","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/UnnestColumnValueSelectorCursor.java","lineNumber":172,"sourceCode":"              return 0;\n            }\n            if (value instanceof Number) {\n              return ((Number) value).floatValue();\n            }\n            throw new UOE(\"Cannot convert object to float\");\n          }\n\n          @Override\n          public long getLong()\n          {\n            Object value = getObject();\n            if (value == null) {\n              return 0;\n            }\n            if (value instanceof Number) {\n              return ((Number) value).longValue();\n            }\n            throw new UOE(\"Cannot convert object to long\");\n          }\n\n          @Override\n          public void inspectRuntimeShape(RuntimeShapeInspector inspector)\n          {\n            columnValueSelector.inspectRuntimeShape(inspector);\n          }\n\n          @Override\n          public boolean isNull()\n          {\n            return getObject() == null;\n          }\n\n          @Nullable\n          @Override\n          public Object getObject()\n          {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/UnnestColumnValueSelectorCursor.java#L154-L190","documentation":"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.","triggerScenarios":"getLong() invoked on the unnest cursor while iterating a column whose elements are objects (e.g. strings, nested structures, complex/metric payloads).","commonSituations":"LONG aggregations (COUNT-style or longSum) over an unnested column holding strings; mixed-type array columns where some elements are objects.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"Object v = selector.getObject();\nif (v instanceof Number) { long l = ((Number) v).longValue(); }","typeGuard":"static boolean isLongSafe(Object o) { return o == null || o instanceof Number; }","tryCatchPattern":"try { long l = selector.getLong(); } catch (UOE e) { /* fallback: parse or skip */ }","preventionTips":["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"],"tags":["druid","unnest","type-mismatch"],"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"}