{"record":{"id":"b5e75624b78857db","repo":"apache/druid","slug":"cannot-work-with-segment-of-type-s","errorCode":null,"errorMessage":"Cannot work with segment of type[%s]","messagePattern":"Cannot work with segment of type\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/operator/SegmentToRowsAndColumnsOperator.java","lineNumber":58,"sourceCode":"    this.segment = segment;\n  }\n\n  @Override\n  public Closeable goOrContinue(Closeable continuation, Receiver receiver)\n  {\n    try (final CloseableShapeshifter shifty = segment.as(CloseableShapeshifter.class)) {\n      if (shifty == null) {\n        throw DruidException.defensive(\"Segment [%s] cannot shapeshift\", segment.getDebugString());\n      }\n      RowsAndColumns rac;\n      if (shifty instanceof RowsAndColumns) {\n        rac = (RowsAndColumns) shifty;\n      } else {\n        rac = shifty.as(RowsAndColumns.class);\n      }\n\n      if (rac == null) {\n        throw new ISE(\"Cannot work with segment of type[%s]\", segment.getClass());\n      }\n\n      // After pushing in a single object, we are done, so ignore the signal and call completed()\n      receiver.push(rac);\n      receiver.completed();\n    }\n    catch (IOException e) {\n      throw new RE(e, \"Problem closing resources for segment[%s]\", segment.getId());\n    }\n    return null;\n  }\n}\n","sourceCodeStart":40,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/operator/SegmentToRowsAndColumnsOperator.java#L40-L71","documentation":"SegmentToRowsAndColumnsOperator converts a Segment into RowsAndColumns, either directly (QuerySegment/RowsAndColumns types) or via Segment.as(RowsAndColumns.class). If the segment cannot be viewed as RowsAndColumns at all, the operator cannot process it and throws this ISE.","triggerScenarios":"Running a window operator query over a data source whose segments are neither QuerySegment/Shifty-backed with RowsAndColumns support nor expose an as(RowsAndColumns.class) adapter — e.g. a legacy or custom Segment implementation.","commonSituations":"Custom or third-party segment types fed into operator (window) queries, misconfigured data sources producing non-materializable segments, or version mismatches where a segment type lost its RowsAndColumns adapter.","solutions":["Ensure the query reads from a supported datasource (inline, table with standard Druid segments) for window operator queries","Upgrade or replace the custom Segment implementation to expose RowsAndColumns via Segment.as(...)","Log segment.getClass() and confirm which segment type is being passed; fix the upstream source accordingly"],"exampleFix":"// before\nclass MySegment implements Segment { /* no as(RowsAndColumns.class) */ }\n// after\nclass MySegment implements Segment {\n  @Override public <T> T as(Class<T> clazz) {\n    if (clazz.equals(RowsAndColumns.class)) return clazz.cast(myRowsAndColumns);\n    return null;\n  }\n}","handlingStrategy":"type-guard","validationCode":"if (segment.as(RowsAndColumns.class) == null) {\n  throw new IllegalArgumentException(\"Segment \" + segment.getId() + \" cannot be viewed as RowsAndColumns\");\n}","typeGuard":"RowsAndColumns asRowsAndColumns(Segment s) {\n  if (s instanceof RowsAndColumns) return (RowsAndColumns) s;\n  return s.as(RowsAndColumns.class);\n}","tryCatchPattern":"try {\n  operator.go(receiver, cont);\n} catch (ISE e) {\n  if (e.getMessage().startsWith(\"Cannot work with segment of type\")) {\n    // route the segment through a supported query type or materialize it first\n  } else throw e;\n}","preventionTips":["Use only datasource types supported by the operator framework for window queries","Make custom Segment implementations implement/return RowsAndColumns via as(...)","Add a planning-time check that all leaf segments support RowsAndColumns"],"tags":["segment","operator","unsupported-type","window-operator"],"backgroundTag":"incompatible-source-type","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"}