apache/druid · error · IllegalStateException

Cannot read directly out of dataSource

Error message

Cannot read directly out of dataSource: %s

What it means

MapSegmentWrangler only knows how to produce segments for dataSources that have a registered SegmentWrangler for their concrete class. For other dataSource types (which normally reach the server via segment loading, not direct lookup) it throws this ISE with a user-facing message.

Solutions

  1. Only invoke this method for dataSource classes registered in the wranglers map (check dataSource.getClass() membership first).
  2. Register a SegmentWrangler for the custom dataSource class in the WranglerModule/extension.
  3. Route the query through the standard segment-loading path instead of direct wrangler lookup.

Example fix

// before
final List<SegmentId> segs = wrangler.getSegmentsForIntervals(anyDataSource, intervals);
// after
if (wrangler.getSupportedTypes().contains(dataSource.getClass())) {
  final List<SegmentId> segs = wrangler.getSegmentsForIntervals(dataSource, intervals);
}
Defensive patterns

Strategy: type-guard

Validate before calling

boolean readable = wrangler.getSupportedTypes().contains(dataSource.getClass());

Type guard

if (dataSource instanceof InlineDataSource || wrangler.getSupportedTypes().contains(dataSource.getClass())) {
  // safe to call getSegmentsForIntervals
}

Prevention

When it happens

Trigger: Calling getSegmentsForIntervals on a MapSegmentWrangler with a dataSource class that has no entry in the wranglers map — e.g. a non-Broker/native dataSource type passed into an inline/lookup-style query path.

Common situations: Querying a datasource type that isn't wrangler-readable (tables, joins over non-map sources) via an API expecting a wrangler-backed source; extension code registering wranglers for only some DataSource subclasses.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/dc73f9f0f7c04439. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/segment/MapSegmentWrangler.java:53

{
  private final Map<Class<? extends DataSource>, SegmentWrangler> wranglers;

  @Inject
  public MapSegmentWrangler(final Map<Class<? extends DataSource>, SegmentWrangler> wranglers)
  {
    this.wranglers = wranglers;
  }

  @Override
  public Iterable<Segment> getSegmentsForIntervals(final DataSource dataSource, final Iterable<Interval> intervals)
  {
    final SegmentWrangler wrangler = wranglers.get(dataSource.getClass());

    if (wrangler != null) {
      return wrangler.getSegmentsForIntervals(dataSource, intervals);
    } else {
      // Reasonable as a user-facing error message.
      throw new ISE("Cannot read directly out of dataSource: %s", dataSource);
    }
  }
}

View on GitHub (pinned to 9b90983fd2)