{"record":{"id":"8881cfbdc8aaf5c2","repo":"apache/druid","slug":"unable-to-get-first-event-timestamp-using-result-f","errorCode":null,"errorMessage":"Unable to get first event timestamp using result format of [%s]","messagePattern":"Unable to get first event timestamp using result format of \\[(.+?)\\]","errorType":"exception","errorClass":"UnsupportedOperationException (UOE)","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/scan/ScanResultValue.java","lineNumber":114,"sourceCode":"\n\n  public long getFirstEventTimestamp(ScanQuery.ResultFormat resultFormat)\n  {\n    if (resultFormat.equals(ScanQuery.ResultFormat.RESULT_FORMAT_LIST)) {\n      Object timestampObj = ((Map<String, Object>) ((List<Object>) this.getEvents()).get(0)).get(ColumnHolder.TIME_COLUMN_NAME);\n      if (timestampObj == null) {\n        throw new ISE(\"Unable to compare timestamp for rows without a time column\");\n      }\n      return DimensionHandlerUtils.convertObjectToLong(timestampObj);\n    } else if (resultFormat.equals(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST)) {\n      int timeColumnIndex = this.getColumns().indexOf(ColumnHolder.TIME_COLUMN_NAME);\n      if (timeColumnIndex == -1) {\n        throw new ISE(\"Unable to compare timestamp for rows without a time column\");\n      }\n      List<Object> firstEvent = (List<Object>) ((List<Object>) this.getEvents()).get(0);\n      return DimensionHandlerUtils.convertObjectToLong(firstEvent.get(timeColumnIndex));\n    }\n    throw new UOE(\"Unable to get first event timestamp using result format of [%s]\", resultFormat.toString());\n  }\n\n  public List<ScanResultValue> toSingleEventScanResultValues()\n  {\n    List<ScanResultValue> singleEventScanResultValues = new ArrayList<>();\n    List<Object> events = (List<Object>) this.getEvents();\n    for (Object event : events) {\n      singleEventScanResultValues.add(new ScanResultValue(segmentId, columns, Collections.singletonList(event), rowSignature));\n    }\n    return singleEventScanResultValues;\n  }\n\n  @Override\n  public boolean equals(Object o)\n  {\n    if (this == o) {\n      return true;\n    }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/scan/ScanResultValue.java#L96-L132","documentation":"getFirstEventTimestamp only supports RESULT_FORMAT_LIST and RESULT_FORMAT_COMPACTED_LIST. Any other result format has no defined way to extract a first-event timestamp, so it throws an UnsupportedOperationException identifying the unsupported format.","triggerScenarios":"Calling getFirstEventTimestamp (directly, or via stableLimitingSort/comparison) on a ScanResultValue whose resultFormat is neither list nor compacted-list — e.g. RESULT_FORMAT_VALUE_VECTOR results fed into the time-ordering path.","commonSituations":"Custom/extension result formats used with time-ordered scans; misconfigured queries whose resultFormat was changed after construction.","solutions":["Use list or compacted-list result formats when time-ordering scan results.","Convert the result value to a supported format before calling getFirstEventTimestamp in custom code.","If a new result format is needed, extend getFirstEventTimestamp (or upstream it) rather than passing it through."],"exampleFix":"// before\nif (sv.getResultFormat() == RESULT_FORMAT_VALUE_VECTOR) { sv.getFirstEventTimestamp(format); }\n// after\nif (sv.getResultFormat() == RESULT_FORMAT_COMPACTED_LIST || sv.getResultFormat() == RESULT_FORMAT_LIST) {\n  long ts = sv.getFirstEventTimestamp(sv.getResultFormat());\n}","handlingStrategy":"type-guard","validationCode":"if (format != ResultFormat.RESULT_FORMAT_LIST && format != ResultFormat.RESULT_FORMAT_COMPACTED_LIST) {\n  throw new IllegalArgumentException(\"timestamp extraction requires list/compacted-list format\");\n}","typeGuard":"boolean timestampExtractable(ScanQuery.ResultFormat f) {\n  return f == ResultFormat.RESULT_FORMAT_LIST || f == ResultFormat.RESULT_FORMAT_COMPACTED_LIST;\n}","tryCatchPattern":"try {\n  long ts = sv.getFirstEventTimestamp(format);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage().contains(\"Unable to get first event timestamp\")) { /* convert format or skip ordering */ }\n  else throw e;\n}","preventionTips":["Use list or compacted-list formats for time-ordered scans.","Don't feed vector/value formats into time-comparison code.","Extend getFirstEventTimestamp upstream for new formats instead of working around it."],"tags":["druid","scan-query","unsupported-operation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}