Skip to content

Commit a1335b7

Browse files
committed
refactor(planner): expose scan plans as USearchExec children
Report provider_scan and full_scan as children so DataFusion's physical optimizer can traverse and optimize the scan plans. with_new_children correctly replaces whichever scans are present.
1 parent 87b15ff commit a1335b7

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/planner.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,36 @@ impl ExecutionPlan for USearchExec {
261261
&self.properties
262262
}
263263
fn children(&self) -> Vec<&Arc<dyn ExecutionPlan>> {
264-
vec![]
264+
let mut children = Vec::new();
265+
if let Some(ref scan) = self.params.provider_scan {
266+
children.push(scan);
267+
}
268+
if let Some(ref full) = self.params.full_scan {
269+
children.push(full);
270+
}
271+
children
265272
}
266273

267274
fn with_new_children(
268275
self: Arc<Self>,
269276
children: Vec<Arc<dyn ExecutionPlan>>,
270277
) -> Result<Arc<dyn ExecutionPlan>> {
271-
if children.is_empty() {
272-
Ok(self)
273-
} else {
274-
Err(DataFusionError::Internal(
275-
"USearchExec is a leaf node and takes no children".to_string(),
276-
))
278+
let expected = self.children().len();
279+
if children.len() != expected {
280+
return Err(DataFusionError::Internal(format!(
281+
"USearchExec: expected {expected} children, got {}",
282+
children.len()
283+
)));
284+
}
285+
let mut params = self.params.clone();
286+
let mut iter = children.into_iter();
287+
if params.provider_scan.is_some() {
288+
params.provider_scan = Some(iter.next().unwrap());
289+
}
290+
if params.full_scan.is_some() {
291+
params.full_scan = Some(iter.next().unwrap());
277292
}
293+
Ok(Arc::new(USearchExec::new(params)))
278294
}
279295

280296
fn execute(

0 commit comments

Comments
 (0)