{"record":{"id":"f084ad58f8af25c7","repo":"apache/druid","slug":"cannot-accept-children","errorCode":null,"errorMessage":"Cannot accept children","messagePattern":"Cannot accept children","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/LeafDataSource.java","lineNumber":43,"sourceCode":"import java.util.Collections;\nimport java.util.List;\n\n/**\n * Leaf {@link DataSource}-s have no inputs.\n */\npublic abstract class LeafDataSource implements DataSource\n{\n  @Override\n  public final List<DataSource> getChildren()\n  {\n    return Collections.emptyList();\n  }\n\n  @Override\n  public final DataSource withChildren(List<DataSource> children)\n  {\n    if (!children.isEmpty()) {\n      throw new IAE(\"Cannot accept children\");\n    }\n\n    return this;\n  }\n\n  @Override\n  public SegmentMapFunction createSegmentMapFunction(Query query)\n  {\n    return SegmentMapFunction.IDENTITY;\n  }\n}\n","sourceCodeStart":25,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/LeafDataSource.java#L25-L55","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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."],"exampleFix":"// before\nfor (DataSource ds : allDataSources) { ds = ds.withChildren(newChildren); }\n// after\nfor (DataSource ds : allDataSources) {\n  if (!ds.isLeafDataSource()) { ds = ds.withChildren(newChildren); }\n}","handlingStrategy":"type-guard","validationCode":"if (!(ds instanceof LeafDataSource) && !children.isEmpty()) { ds = ds.withChildren(children); }","typeGuard":"boolean isLeaf(DataSource ds) { return ds instanceof LeafDataSource || ds.isLeafDataSource(); }","tryCatchPattern":"try {\n  ds = ds.withChildren(children);\n} catch (IllegalArgumentException e) {\n  if (\"Cannot accept children\".equals(e.getMessage())) { /* leave ds unchanged */ }\n  else { throw e; }\n}","preventionTips":["Check isLeafDataSource() before calling withChildren.","Only call withChildren with empty lists on leaves.","Extend the right DataSource base class for new datasource types."],"tags":["datasource","query-planning","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}