apache/druid · error · IllegalArgumentException
Cannot accept children
Error message
Cannot accept children
What it means
LeafDataSource is the base class for leaf datasources (table, lookup, query, inline) which by definition have no child data sources. Its final withChildren throws this IllegalArgumentException whenever a non-empty children list is supplied, enforcing the leaf invariant during datasource tree rewrites.
Solutions
- Skip withChildren for leaf datasources (check DataSource.isLeafDataSource() or instanceof LeafDataSource) — returning the datasource itself is the correct behavior for empty children.
- Fix the rewrite pass so it only calls withChildren on non-leaf (parent) datasources.
- If your datasource truly has children, extend a non-leaf base instead of LeafDataSource.
Example fix
// before
for (DataSource ds : allDataSources) { ds = ds.withChildren(newChildren); }
// after
for (DataSource ds : allDataSources) {
if (!ds.isLeafDataSource()) { ds = ds.withChildren(newChildren); }
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!(ds instanceof LeafDataSource) && !children.isEmpty()) { ds = ds.withChildren(children); } Type guard
boolean isLeaf(DataSource ds) { return ds instanceof LeafDataSource || ds.isLeafDataSource(); } Try / catch
try {
ds = ds.withChildren(children);
} catch (IllegalArgumentException e) {
if ("Cannot accept children".equals(e.getMessage())) { /* leave ds unchanged */ }
else { throw e; }
} Prevention
- Check isLeafDataSource() before calling withChildren.
- Only call withChildren with empty lists on leaves.
- Extend the right DataSource base class for new datasource types.
When it happens
Trigger: Calling withChildren with any non-empty list on a table/lookup/inline/query datasource — typically a generic rewrite pass that calls withChildren uniformly on all datasources without checking isLeafDataSource().
Common situations: Custom datasource-rewriting/analysis code that pushes children into every node; new DataSource implementations accidentally extending LeafDataSource while carrying children; planner utilities that iterate all datasources calling withChildren.
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
- Cannot read directly out of dataSource
- Cannot retrieve map view from lookup
- Expected [1] child, got
- Expected [2] children, got
- Union datasource with non-leaf inputs is not supported
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/f084ad58f8af25c7.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/query/LeafDataSource.java:43
import java.util.Collections;
import java.util.List;
/**
* Leaf {@link DataSource}-s have no inputs.
*/
public abstract class LeafDataSource implements DataSource
{
@Override
public final List<DataSource> getChildren()
{
return Collections.emptyList();
}
@Override
public final DataSource withChildren(List<DataSource> children)
{
if (!children.isEmpty()) {
throw new IAE("Cannot accept children");
}
return this;
}
@Override
public SegmentMapFunction createSegmentMapFunction(Query query)
{
return SegmentMapFunction.IDENTITY;
}
}
View on GitHub (pinned to 9b90983fd2)