{"record":{"id":"f6a7f7d0fd1e1bd3","repo":"apache/druid","slug":"cannot-reorder-s-scan-data-right-now","errorCode":null,"errorMessage":"Cannot reorder[%s] scan data right now","messagePattern":"Cannot reorder\\[(.+?)\\] scan data right now","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java","lineNumber":182,"sourceCode":"    if (needsMaterialization()) {\n      final Pair<byte[], RowSignature> thePair = materialize();\n      if (thePair == null) {\n        reset(new EmptyRowsAndColumns());\n      } else {\n        reset(new ColumnBasedFrameRowsAndColumns(Frame.wrap(thePair.lhs), thePair.rhs));\n      }\n    }\n  }\n\n  private boolean needsMaterialization()\n  {\n    return interval != null || filter != null || limit.isPresent() || ordering != null || virtualColumns != null;\n  }\n\n  private Pair<byte[], RowSignature> materialize()\n  {\n    if (ordering != null) {\n      throw new ISE(\"Cannot reorder[%s] scan data right now\", ordering);\n    }\n\n    final CursorFactory as = base.as(CursorFactory.class);\n    if (as == null) {\n      return naiveMaterialize(base);\n    } else {\n      return materializeCursorFactory(as);\n    }\n  }\n\n  private void reset(RowsAndColumns rac)\n  {\n    base = rac;\n    interval = null;\n    filter = null;\n    virtualColumns = null;\n    limit = OffsetLimit.NONE;\n    viewableColumns = null;","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/rowsandcols/LazilyDecoratedRowsAndColumns.java#L164-L200","documentation":"LazilyDecoratedRowsAndColumns.materialize() can apply intervals, filters, limits, and virtual columns lazily, but re-ordering scan data is not implemented. If an ordering decoration is set when materialization happens, Druid throws ISE. This is a not-yet-implemented capability, not a data problem.","triggerScenarios":"A scan-backed RowsAndColumns decorated with a non-null ordering is materialized (via thePair) before the ordering can be honored.","commonSituations":"Query or downstream operator requests ordered scan output through the lazily decorated wrapper; internal pipeline stages requesting ordering that only a full re-sort could satisfy.","solutions":["Remove the ordering requirement from the scan at this pipeline stage","Sort explicitly after materialization instead of relying on scan ordering","Use a cursor/scan path that supports ordering directly rather than the decorated wrapper"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (decoration.getOrdering() != null) {\n  throw new IllegalStateException(\"ordering unsupported on LazilyDecoratedRowsAndColumns; sort explicitly\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  rows = lazilyDecorated.materialize();\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Cannot reorder\")) {\n    rows = sortExplicitly(lazilyDecorated);\n  } else throw e;\n}","preventionTips":["Don't set ordering on scan decorations unless the downstream path supports it","Sort after materialization with an explicit sort operator"],"tags":["scan","ordering","not-implemented","rows-and-columns"],"backgroundTag":"method-not-implemented","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"}