Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/iter.rs
8446 views
1
use super::plan::*;
2
3
impl DslPlan {
4
fn inputs<'a>(&'a self, scratch: &mut Vec<&'a DslPlan>) {
5
use DslPlan::*;
6
match self {
7
Select { input, .. }
8
| GroupBy { input, .. }
9
| Filter { input, .. }
10
| Distinct { input, .. }
11
| Sort { input, .. }
12
| Slice { input, .. }
13
| HStack { input, .. }
14
| MatchToSchema { input, .. }
15
| MapFunction { input, .. }
16
| Sink { input, .. }
17
| Cache { input, .. } => scratch.push(input),
18
Union { inputs, .. } | HConcat { inputs, .. } | SinkMultiple { inputs } => {
19
scratch.extend(inputs)
20
},
21
PipeWithSchema { input, .. } => scratch.extend(input.iter()),
22
Join {
23
input_left,
24
input_right,
25
..
26
} => {
27
scratch.push(input_left);
28
scratch.push(input_right);
29
},
30
ExtContext { input, contexts } => {
31
scratch.push(input);
32
scratch.extend(contexts);
33
},
34
IR { dsl, .. } => scratch.push(dsl),
35
Scan { .. } | DataFrameScan { .. } => (),
36
#[cfg(feature = "pivot")]
37
Pivot { input, .. } => scratch.push(input),
38
#[cfg(feature = "python")]
39
PythonScan { .. } => (),
40
#[cfg(feature = "merge_sorted")]
41
MergeSorted {
42
input_left,
43
input_right,
44
..
45
} => {
46
scratch.push(input_left);
47
scratch.push(input_right);
48
},
49
}
50
}
51
}
52
53
pub struct DslPlanIter<'a> {
54
stack: Vec<&'a DslPlan>,
55
}
56
57
impl<'a> Iterator for DslPlanIter<'a> {
58
type Item = &'a DslPlan;
59
60
fn next(&mut self) -> Option<Self::Item> {
61
self.stack
62
.pop()
63
.inspect(|next| next.inputs(&mut self.stack))
64
}
65
}
66
67
impl<'a> IntoIterator for &'a DslPlan {
68
type Item = &'a DslPlan;
69
type IntoIter = DslPlanIter<'a>;
70
71
fn into_iter(self) -> Self::IntoIter {
72
DslPlanIter { stack: vec![self] }
73
}
74
}
75
76