Skip to content

Commit 6a8c4a6

Browse files
authored
fix: return schema of ExtensionPlan instead of its children's (#5514)
* fix: return schema of ExtensionPlan instead of its children's Signed-off-by: Ruihang Xia <[email protected]> * add test case Signed-off-by: Ruihang Xia <[email protected]> --------- Signed-off-by: Ruihang Xia <[email protected]>
1 parent 55c7c4d commit 6a8c4a6

1 file changed

Lines changed: 68 additions & 1 deletion

File tree

  • datafusion/expr/src/logical_plan

‎datafusion/expr/src/logical_plan/plan.rs‎

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,13 @@ impl LogicalPlan {
201201
| LogicalPlan::Values(_)
202202
| LogicalPlan::SubqueryAlias(_)
203203
| LogicalPlan::Union(_)
204+
| LogicalPlan::Extension(_)
204205
| LogicalPlan::TableScan(_) => {
205206
vec![self.schema()]
206207
}
207208
// return children schemas
208209
LogicalPlan::Limit(_)
209210
| LogicalPlan::Subquery(_)
210-
| LogicalPlan::Extension(_)
211211
| LogicalPlan::Repartition(_)
212212
| LogicalPlan::Sort(_)
213213
| LogicalPlan::CreateMemoryTable(_)
@@ -2381,4 +2381,71 @@ mod tests {
23812381
.build()
23822382
.unwrap()
23832383
}
2384+
2385+
/// Extension plan that panic when trying to access its input plan
2386+
#[derive(Debug)]
2387+
struct NoChildExtension {
2388+
empty_schema: DFSchemaRef,
2389+
}
2390+
2391+
impl NoChildExtension {
2392+
fn empty() -> Self {
2393+
Self {
2394+
empty_schema: Arc::new(DFSchema::empty()),
2395+
}
2396+
}
2397+
}
2398+
2399+
impl UserDefinedLogicalNode for NoChildExtension {
2400+
fn as_any(&self) -> &dyn std::any::Any {
2401+
unimplemented!()
2402+
}
2403+
2404+
fn name(&self) -> &str {
2405+
unimplemented!()
2406+
}
2407+
2408+
fn inputs(&self) -> Vec<&LogicalPlan> {
2409+
panic!("Should not be called")
2410+
}
2411+
2412+
fn schema(&self) -> &DFSchemaRef {
2413+
&self.empty_schema
2414+
}
2415+
2416+
fn expressions(&self) -> Vec<Expr> {
2417+
unimplemented!()
2418+
}
2419+
2420+
fn fmt_for_explain(&self, _: &mut fmt::Formatter) -> fmt::Result {
2421+
unimplemented!()
2422+
}
2423+
2424+
fn from_template(
2425+
&self,
2426+
_: &[Expr],
2427+
_: &[LogicalPlan],
2428+
) -> Arc<dyn UserDefinedLogicalNode> {
2429+
unimplemented!()
2430+
}
2431+
2432+
fn dyn_hash(&self, _: &mut dyn Hasher) {
2433+
unimplemented!()
2434+
}
2435+
2436+
fn dyn_eq(&self, _: &dyn UserDefinedLogicalNode) -> bool {
2437+
unimplemented!()
2438+
}
2439+
}
2440+
2441+
#[test]
2442+
fn test_extension_all_schemas() {
2443+
let plan = LogicalPlan::Extension(Extension {
2444+
node: Arc::new(NoChildExtension::empty()),
2445+
});
2446+
2447+
let schemas = plan.all_schemas();
2448+
assert_eq!(1, schemas.len());
2449+
assert_eq!(0, schemas[0].fields().len());
2450+
}
23842451
}

0 commit comments

Comments
 (0)