-
Notifications
You must be signed in to change notification settings - Fork 11
feat: pretty-printer for plan and expr #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ACTION NEEDED Substrait follows the Conventional Commits The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. |
Let me know if you need further modification. The goal here is to have a good basis we can increment on to offer a nice debugging experience with substrait. I realise this is a big PR, sorry about that but the init of a recursive function took a while to get right 😬 |
Substrait Plan Pretty Printer - Architecture DiagramMermaid diagram to understand a bit better the flow graph TB
%% Main Entry Points
subgraph "Public Interface"
PP[pretty_print_plan]
PE[pretty_print_expression]
SP[stringify_plan]
SE[stringify_expression]
end
%% Core Printer Class
subgraph "PlanPrinter Class"
PPClass[PlanPrinter]
Init[__init__]
ColorDetect[_detect_color_support]
Color[_color]
IndentArrow[_get_indent_with_arrow]
ResolveField[_resolve_field_name]
end
%% Main Streaming Methods
subgraph "Core Streaming Methods"
StreamPlan[_stream_plan]
StreamRel[_stream_relation]
StreamExpr[_stream_expression]
end
%% Relation Handlers
subgraph "Relation Handlers"
ReadRel[_stream_read_rel]
FilterRel[_stream_filter_rel]
ProjectRel[_stream_project_rel]
AggregateRel[_stream_aggregate_rel]
SortRel[_stream_sort_rel]
JoinRel[_stream_join_rel]
CrossRel[_stream_cross_rel]
FetchRel[_stream_fetch_rel]
end
%% Expression Handlers
subgraph "Expression Handlers"
Literal[_stream_literal]
Selection[_stream_selection]
ScalarFunc[_stream_scalar_function]
Cast[_stream_cast]
IfThen[_stream_if_then]
WindowFunc[_stream_window_function]
end
%% Specialized Handlers
subgraph "Specialized Handlers"
FuncArg[_stream_function_argument]
MapLiteral[_stream_map_literal]
LiteralValue[_stream_literal_value]
TypeToString[_type_to_string]
end
%% Helper Methods
subgraph "Helper Methods"
GetFuncArgString[_get_function_argument_string]
end
%% Data Flow
PP --> PPClass
PE --> PPClass
SP --> PPClass
SE --> PPClass
PPClass --> Init
Init --> ColorDetect
Init --> Color
Init --> IndentArrow
Init --> ResolveField
PPClass --> StreamPlan
StreamPlan --> StreamRel
StreamRel --> ReadRel
StreamRel --> FilterRel
StreamRel --> ProjectRel
StreamRel --> AggregateRel
StreamRel --> SortRel
StreamRel --> JoinRel
StreamRel --> CrossRel
StreamRel --> FetchRel
ReadRel --> StreamExpr
FilterRel --> StreamExpr
ProjectRel --> StreamExpr
AggregateRel --> StreamExpr
SortRel --> StreamExpr
JoinRel --> StreamExpr
CrossRel --> StreamExpr
FetchRel --> StreamExpr
StreamExpr --> Literal
StreamExpr --> Selection
StreamExpr --> ScalarFunc
StreamExpr --> Cast
StreamExpr --> IfThen
StreamExpr --> WindowFunc
ScalarFunc --> FuncArg
ScalarFunc --> MapLiteral
ScalarFunc --> LiteralValue
FuncArg --> MapLiteral
FuncArg --> LiteralValue
FuncArg --> ScalarFunc
MapLiteral --> LiteralValue
LiteralValue --> MapLiteral
%% Color and Styling
classDef public fill:#e1f5fe,stroke:#01579b,stroke-width:2px
classDef core fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
classDef relation fill:#e8f5e8,stroke:#1b5e20,stroke-width:2px
classDef expression fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef specialized fill:#fce4ec,stroke:#880e4f,stroke-width:2px
classDef helper fill:#f1f8e9,stroke:#33691e,stroke-width:2px
class PP,PE,SP,SE public
class PPClass,Init,ColorDetect,Color,IndentArrow,ResolveField,StreamPlan,StreamRel,StreamExpr core
class ReadRel,FilterRel,ProjectRel,AggregateRel,SortRel,JoinRel,CrossRel,FetchRel relation
class Literal,Selection,ScalarFunc,Cast,IfThen,WindowFunc expression
class FuncArg,MapLiteral,LiteralValue,TypeToString specialized
class GetFuncArgString helper
Flow Description1. Entry Points
2. Core Initialization
3. Plan Processing Flow
4. Expression Processing Flow
5. Recursive Expansion
6. Output Formatting
Key Design Principles
|
This is definitely better than reading protos 😆 minor nit: On a more serious note, I know David has been working on text representation of a substrait plan (https://github.com/EpsilonPrime/substrait-textplan) which is essentially the same thing and also has python bindings. If the goal there is to establish a standard text format for substrait, we should probably try to avoid reimplementing the format here. |
I wasn't aware of I am just not a fan of having to load an external dependencies for something that's a debugging use-case essentially since it means i have to load a dependency I'm not using most of the time OR I have to add an external deps in my system every time I decide I need to add telemetry / logs to debug my substraits. I am very much in favor of 'battery included' libraries :)
In my mind, the goal here is to have a nicer debugging experience when building systems around substraits. Substrait being protobuf the 'standard' should be text_format I believe ? |
…dule to keep architcture retro compatible
CI error unrelated :
|
No description provided.