Path: blob/main/crates/polars-stream/src/physical_plan/visualization/models.rs
7884 views
use std::num::NonZeroUsize;12use polars_io::utils::sync_on_close::SyncOnCloseType;3use polars_ops::frame::MaintainOrderJoin;4use polars_ops::prelude::{JoinCoalesce, JoinValidation};5use polars_plan::dsl::PredicateFileSkip;6use polars_plan::dsl::sink2::FileProviderType;7use polars_utils::IdxSize;8use polars_utils::pl_str::PlSmallStr;910use crate::physical_plan::ZipBehavior;1112#[derive(serde::Serialize, serde::Deserialize, Debug)]13#[cfg_attr(14feature = "physical_plan_visualization_schema",15derive(schemars::JsonSchema)16)]17pub struct PhysicalPlanVisualizationData {18pub title: PlSmallStr,19/// Number of nodes from the start of `nodes` that are root nodes.20pub num_roots: u64,21pub nodes: Vec<PhysNodeInfo>,22pub edges: Vec<Edge>,23}2425impl PhysicalPlanVisualizationData {26pub fn to_json(&self) -> polars_error::PolarsResult<String> {27serde_json::to_string(self).map_err(polars_error::to_compute_err)28}29}3031#[derive(serde::Serialize, serde::Deserialize, Debug, Default)]32#[cfg_attr(33feature = "physical_plan_visualization_schema",34derive(schemars::JsonSchema)35)]36pub struct PhysNodeInfo {37pub id: u64,38pub title: PlSmallStr,39pub properties: PhysNodeProperties,40}4142#[derive(serde::Serialize, serde::Deserialize, Debug, Default)]43#[cfg_attr(44feature = "physical_plan_visualization_schema",45derive(schemars::JsonSchema)46)]47pub struct Edge {48pub source: u64,49pub target: u64,50}5152impl Edge {53pub fn new<T, U>(source: T, target: U) -> Self54where55u64: TryFrom<T> + TryFrom<U>,56<u64 as TryFrom<T>>::Error: std::fmt::Debug,57<u64 as TryFrom<U>>::Error: std::fmt::Debug,58{59Self {60source: source.try_into().unwrap(),61target: target.try_into().unwrap(),62}63}64}6566#[derive(serde::Serialize, serde::Deserialize)]67#[serde(tag = "type")]68#[derive(Default, Debug, strum_macros::IntoStaticStr)]69#[cfg_attr(70feature = "physical_plan_visualization_schema",71derive(schemars::JsonSchema)72)]73pub enum PhysNodeProperties {74#[default]75Default,76CallbackSink {77callback_function: PlSmallStr,78maintain_order: bool,79chunk_size: Option<NonZeroUsize>,80},81DynamicSlice,82FileSink {83target: PlSmallStr,84file_format: PlSmallStr,85sync_on_close: SyncOnCloseType,86maintain_order: bool,87mkdir: bool,88cloud_options: bool,89},90Filter {91predicate: PlSmallStr,92},93GatherEvery {94n: u64,95offset: u64,96},97GroupBy {98keys: Vec<PlSmallStr>,99aggs: Vec<PlSmallStr>,100},101#[cfg(feature = "dynamic_group_by")]102DynamicGroupBy {103index_column: PlSmallStr,104period: PlSmallStr,105every: PlSmallStr,106offset: PlSmallStr,107start_by: PlSmallStr,108label: PlSmallStr,109include_boundaries: bool,110closed_window: PlSmallStr,111aggs: Vec<PlSmallStr>,112slice: Option<(u64, u64)>,113},114#[cfg(feature = "dynamic_group_by")]115RollingGroupBy {116index_column: PlSmallStr,117period: PlSmallStr,118offset: PlSmallStr,119closed_window: PlSmallStr,120slice: Option<(u64, u64)>,121aggs: Vec<PlSmallStr>,122},123SortedGroupBy {124key: PlSmallStr,125aggs: Vec<PlSmallStr>,126slice: Option<(IdxSize, IdxSize)>,127},128InMemoryMap {129format_str: PlSmallStr,130},131InMemorySink,132InMemorySource {133n_rows: u64,134schema_names: Vec<PlSmallStr>,135},136InputIndependentSelect {137selectors: Vec<PlSmallStr>,138},139// Joins140CrossJoin {141maintain_order: MaintainOrderJoin,142suffix: Option<PlSmallStr>,143},144EquiJoin {145how: PlSmallStr,146left_on: Vec<PlSmallStr>,147right_on: Vec<PlSmallStr>,148nulls_equal: bool,149coalesce: JoinCoalesce,150maintain_order: MaintainOrderJoin,151validation: JoinValidation,152suffix: Option<PlSmallStr>,153},154InMemoryJoin {155how: PlSmallStr,156left_on: Vec<PlSmallStr>,157right_on: Vec<PlSmallStr>,158nulls_equal: bool,159coalesce: JoinCoalesce,160maintain_order: MaintainOrderJoin,161validation: JoinValidation,162suffix: Option<PlSmallStr>,163slice: Option<(i64, u64)>,164},165InMemoryAsOfJoin {166left_on: PlSmallStr,167right_on: PlSmallStr,168left_by: Option<Vec<PlSmallStr>>,169right_by: Option<Vec<PlSmallStr>>,170strategy: polars_ops::frame::AsofStrategy,171/// [value, dtype_str]172tolerance: Option<[PlSmallStr; 2]>,173suffix: Option<PlSmallStr>,174slice: Option<(i64, u64)>,175coalesce: JoinCoalesce,176allow_eq: bool,177check_sortedness: bool,178},179InMemoryIEJoin {180left_on: Vec<PlSmallStr>,181right_on: Vec<PlSmallStr>,182inequality_operators: Vec<polars_ops::frame::InequalityOperator>,183suffix: Option<PlSmallStr>,184slice: Option<(i64, u64)>,185},186Map {187display_str: PlSmallStr,188format_str: PlSmallStr,189},190MultiScan {191scan_type: PlSmallStr,192num_sources: u64,193first_source: Option<PlSmallStr>,194projected_file_columns: Vec<PlSmallStr>,195file_projection_builder_type: PlSmallStr,196row_index_name: Option<PlSmallStr>,197row_index_offset: Option<u64>,198pre_slice: Option<(i64, u64)>,199predicate: Option<PlSmallStr>,200predicate_file_skip_applied: Option<PredicateFileSkip>,201has_table_statistics: bool,202include_file_paths: Option<PlSmallStr>,203deletion_files_type: Option<PlSmallStr>,204hive_columns: Option<Vec<PlSmallStr>>,205},206Multiplexer,207NegativeSlice {208offset: i64,209length: u64,210},211OrderedUnion {212num_inputs: u64,213},214PartitionSink {215base_path: PlSmallStr,216file_path_callback: Option<PlSmallStr>,217partition_variant: PlSmallStr,218partition_variant_max_size: Option<u64>,219partition_variant_key_exprs: Option<Vec<PlSmallStr>>,220partition_variant_include_key: Option<bool>,221file_type: PlSmallStr,222per_partition_sort_exprs: Option<Vec<PlSmallStr>>,223per_partition_sort_descending: Option<Vec<bool>>,224per_partition_sort_nulls_last: Option<Vec<bool>>,225finish_callback: Option<PlSmallStr>,226sync_on_close: SyncOnCloseType,227maintain_order: bool,228mkdir: bool,229},230PartitionSink2 {231base_path: PlSmallStr,232file_path_provider: FileProviderType,233file_format: PlSmallStr,234partition_strategy: PlSmallStr,235partition_key_exprs: Option<Vec<PlSmallStr>>,236include_keys: Option<bool>,237per_partition_sort_exprs: Option<Vec<PlSmallStr>>,238per_partition_sort_descending: Option<Vec<bool>>,239per_partition_sort_nulls_last: Option<Vec<bool>>,240mkdir: bool,241maintain_order: bool,242sync_on_close: SyncOnCloseType,243cloud_options: bool,244max_rows_per_file: u64,245approximate_bytes_per_file: u64,246},247PeakMin,248PeakMax,249Reduce {250exprs: Vec<PlSmallStr>,251},252Repeat,253Rle,254RleId,255Select {256selectors: Vec<PlSmallStr>,257extend_original: bool,258},259Shift {260has_fill: bool,261},262SimpleProjection {263columns: Vec<PlSmallStr>,264},265SinkMultiple {266num_sinks: u64,267},268Sort {269by_exprs: Vec<PlSmallStr>,270slice: Option<(i64, u64)>,271descending: Vec<bool>,272nulls_last: Vec<bool>,273multithreaded: bool,274maintain_order: bool,275limit: Option<u64>,276},277Slice {278offset: i64,279length: u64,280},281TopK {282by_exprs: Vec<PlSmallStr>,283reverse: Vec<bool>,284nulls_last: Vec<bool>,285},286WithRowIndex {287name: PlSmallStr,288offset: Option<u64>,289},290Zip {291num_inputs: u64,292zip_behavior: ZipBehavior,293},294//295// Feature gated296//297#[cfg(feature = "cum_agg")]298CumAgg {299kind: PlSmallStr,300},301#[cfg(feature = "ewma")]302Ewm {303variant: PlSmallStr,304alpha: f64,305adjust: bool,306bias: bool,307min_periods: usize,308ignore_nulls: bool,309},310#[cfg(feature = "semi_anti_join")]311SemiAntiJoin {312left_on: Vec<PlSmallStr>,313right_on: Vec<PlSmallStr>,314nulls_equal: bool,315output_as_bool: bool,316},317#[cfg(feature = "merge_sorted")]318MergeSorted,319#[cfg(feature = "python")]320PythonScan {321scan_source_type: polars_plan::prelude::python_dsl::PythonScanSource,322n_rows: Option<u64>,323projection: Option<Vec<PlSmallStr>>,324predicate: Option<PlSmallStr>,325schema_names: Vec<PlSmallStr>,326is_pure: bool,327validate_schema: bool,328},329}330331332