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