Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/plans/ir/visualization/models.rs
7889 views
1
use polars_core::frame::UniqueKeepStrategy;
2
use polars_ops::frame::{JoinCoalesce, JoinValidation, MaintainOrderJoin};
3
use polars_utils::pl_str::PlSmallStr;
4
use polars_utils::unique_id::UniqueId;
5
6
use crate::dsl::PredicateFileSkip;
7
8
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9
#[cfg_attr(feature = "ir_visualization_schema", derive(schemars::JsonSchema))]
10
#[derive(Debug)]
11
pub struct IRVisualizationData {
12
pub title: PlSmallStr,
13
/// Number of nodes from the start of `nodes` that are root nodes.
14
pub num_roots: u64,
15
pub nodes: Vec<IRNodeInfo>,
16
pub edges: Vec<Edge>,
17
}
18
19
impl IRVisualizationData {
20
pub fn to_json(&self) -> polars_error::PolarsResult<String> {
21
serde_json::to_string(self).map_err(polars_error::to_compute_err)
22
}
23
}
24
25
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
26
#[cfg_attr(feature = "ir_visualization_schema", derive(schemars::JsonSchema))]
27
#[derive(Debug, Default)]
28
pub struct IRNodeInfo {
29
pub id: u64,
30
pub title: PlSmallStr,
31
pub properties: IRNodeProperties,
32
}
33
34
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
35
#[cfg_attr(feature = "ir_visualization_schema", derive(schemars::JsonSchema))]
36
#[derive(Debug, Default)]
37
pub struct Edge {
38
pub source: u64,
39
pub target: u64,
40
}
41
42
impl Edge {
43
pub fn new<T, U>(source: T, target: U) -> Self
44
where
45
u64: TryFrom<T> + TryFrom<U>,
46
<u64 as TryFrom<T>>::Error: std::fmt::Debug,
47
<u64 as TryFrom<U>>::Error: std::fmt::Debug,
48
{
49
Self {
50
source: source.try_into().unwrap(),
51
target: target.try_into().unwrap(),
52
}
53
}
54
}
55
56
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
57
#[cfg_attr(feature = "serde", serde(tag = "type"))]
58
#[cfg_attr(feature = "ir_visualization_schema", derive(schemars::JsonSchema))]
59
#[derive(Debug, Default, strum_macros::IntoStaticStr)]
60
pub enum IRNodeProperties {
61
Cache {
62
id: UniqueId,
63
},
64
DataFrameScan {
65
n_rows: u64,
66
schema_names: Vec<PlSmallStr>,
67
},
68
Distinct {
69
subset: Option<Vec<PlSmallStr>>,
70
maintain_order: bool,
71
keep_strategy: UniqueKeepStrategy,
72
slice: Option<(i64, u64)>,
73
},
74
ExtContext {
75
num_contexts: u64,
76
schema_names: Vec<PlSmallStr>,
77
},
78
Filter {
79
predicate: PlSmallStr,
80
},
81
GroupBy {
82
keys: Vec<PlSmallStr>,
83
aggs: Vec<PlSmallStr>,
84
maintain_order: bool,
85
slice: Option<(i64, u64)>,
86
plan_callback: Option<PlSmallStr>,
87
},
88
HConcat {
89
num_inputs: u64,
90
schema_names: Vec<PlSmallStr>,
91
parallel: bool,
92
strict: bool,
93
},
94
HStack {
95
exprs: Vec<PlSmallStr>,
96
run_parallel: bool,
97
duplicate_check: bool,
98
should_broadcast: bool,
99
},
100
#[default]
101
Invalid,
102
Join {
103
how: PlSmallStr,
104
left_on: Vec<PlSmallStr>,
105
right_on: Vec<PlSmallStr>,
106
nulls_equal: bool,
107
coalesce: JoinCoalesce,
108
maintain_order: MaintainOrderJoin,
109
validation: JoinValidation,
110
suffix: Option<PlSmallStr>,
111
slice: Option<(i64, u64)>,
112
allow_parallel: bool,
113
force_parallel: bool,
114
},
115
CrossJoin {
116
maintain_order: MaintainOrderJoin,
117
slice: Option<(i64, u64)>,
118
predicate: Option<PlSmallStr>,
119
suffix: Option<PlSmallStr>,
120
},
121
MapFunction {
122
function: PlSmallStr,
123
},
124
Scan {
125
scan_type: PlSmallStr,
126
num_sources: u64,
127
first_source: Option<PlSmallStr>,
128
file_columns: Option<Vec<PlSmallStr>>,
129
projection: Option<Vec<PlSmallStr>>,
130
row_index_name: Option<PlSmallStr>,
131
row_index_offset: Option<u64>,
132
pre_slice: Option<(i64, u64)>,
133
predicate: Option<PlSmallStr>,
134
predicate_file_skip_applied: Option<PredicateFileSkip>,
135
has_table_statistics: bool,
136
include_file_paths: Option<PlSmallStr>,
137
column_mapping_type: Option<PlSmallStr>,
138
default_values_type: Option<PlSmallStr>,
139
deletion_files_type: Option<PlSmallStr>,
140
rechunk: bool,
141
hive_columns: Option<Vec<PlSmallStr>>,
142
},
143
Select {
144
exprs: Vec<PlSmallStr>,
145
run_parallel: bool,
146
duplicate_check: bool,
147
should_broadcast: bool,
148
},
149
SimpleProjection {
150
columns: Vec<PlSmallStr>,
151
},
152
Sink {
153
payload: PlSmallStr,
154
},
155
SinkMultiple {
156
num_inputs: u64,
157
},
158
Slice {
159
offset: i64,
160
len: u64,
161
},
162
Sort {
163
by_exprs: Vec<PlSmallStr>,
164
slice: Option<(i64, u64)>,
165
descending: Vec<bool>,
166
nulls_last: Vec<bool>,
167
multithreaded: bool,
168
maintain_order: bool,
169
limit: Option<u64>,
170
},
171
Union {
172
maintain_order: bool,
173
parallel: bool,
174
rechunk: bool,
175
slice: Option<(i64, u64)>,
176
from_partitioned_ds: bool,
177
flattened_by_opt: bool,
178
},
179
//
180
// Feature gated
181
//
182
#[cfg(feature = "asof_join")]
183
AsOfJoin {
184
left_on: PlSmallStr,
185
right_on: PlSmallStr,
186
left_by: Option<Vec<PlSmallStr>>,
187
right_by: Option<Vec<PlSmallStr>>,
188
strategy: polars_ops::frame::AsofStrategy,
189
/// [value, dtype_str]
190
tolerance: Option<[PlSmallStr; 2]>,
191
suffix: Option<PlSmallStr>,
192
slice: Option<(i64, u64)>,
193
coalesce: JoinCoalesce,
194
allow_eq: bool,
195
check_sortedness: bool,
196
},
197
#[cfg(feature = "iejoin")]
198
IEJoin {
199
left_on: Vec<PlSmallStr>,
200
right_on: Vec<PlSmallStr>,
201
inequality_operators: Vec<polars_ops::frame::InequalityOperator>,
202
suffix: Option<PlSmallStr>,
203
slice: Option<(i64, u64)>,
204
},
205
#[cfg(feature = "dynamic_group_by")]
206
DynamicGroupBy {
207
index_column: PlSmallStr,
208
every: PlSmallStr,
209
period: PlSmallStr,
210
offset: PlSmallStr,
211
label: polars_time::prelude::Label,
212
include_boundaries: bool,
213
closed_window: polars_time::ClosedWindow,
214
group_by: Vec<PlSmallStr>,
215
start_by: polars_time::prelude::StartBy,
216
plan_callback: Option<PlSmallStr>,
217
},
218
#[cfg(feature = "dynamic_group_by")]
219
RollingGroupBy {
220
keys: Vec<PlSmallStr>,
221
aggs: Vec<PlSmallStr>,
222
index_column: PlSmallStr,
223
period: PlSmallStr,
224
offset: PlSmallStr,
225
closed_window: polars_time::ClosedWindow,
226
slice: Option<(i64, u64)>,
227
plan_callback: Option<PlSmallStr>,
228
},
229
#[cfg(feature = "merge_sorted")]
230
MergeSorted {
231
key: PlSmallStr,
232
},
233
#[cfg(feature = "python")]
234
PythonScan {
235
scan_source_type: crate::prelude::python_dsl::PythonScanSource,
236
n_rows: Option<u64>,
237
projection: Option<Vec<PlSmallStr>>,
238
predicate: Option<PlSmallStr>,
239
schema_names: Vec<PlSmallStr>,
240
is_pure: bool,
241
validate_schema: bool,
242
},
243
}
244
245