|
65 | 65 | from enum import Enum |
66 | 66 |
|
67 | 67 |
|
| 68 | +class ExplainFormat(Enum): |
| 69 | + """Output format for explain plans. |
| 70 | +
|
| 71 | + Controls how the query plan is rendered in :py:meth:`DataFrame.explain`. |
| 72 | + """ |
| 73 | + |
| 74 | + INDENT = "indent" |
| 75 | + """Default indented text format.""" |
| 76 | + |
| 77 | + TREE = "tree" |
| 78 | + """Tree-style visual format with box-drawing characters.""" |
| 79 | + |
| 80 | + PGJSON = "pgjson" |
| 81 | + """PostgreSQL-compatible JSON format for use with visualization tools.""" |
| 82 | + |
| 83 | + GRAPHVIZ = "graphviz" |
| 84 | + """Graphviz DOT format for graph rendering.""" |
| 85 | + |
| 86 | + |
68 | 87 | # excerpt from deltalake |
69 | 88 | # https://github.com/apache/datafusion-python/pull/981#discussion_r1905619163 |
70 | 89 | class Compression(Enum): |
@@ -918,16 +937,24 @@ def join_on( |
918 | 937 | exprs = [ensure_expr(expr) for expr in on_exprs] |
919 | 938 | return DataFrame(self.df.join_on(right.df, exprs, how)) |
920 | 939 |
|
921 | | - def explain(self, verbose: bool = False, analyze: bool = False) -> None: |
| 940 | + def explain( |
| 941 | + self, |
| 942 | + verbose: bool = False, |
| 943 | + analyze: bool = False, |
| 944 | + format: ExplainFormat | None = None, |
| 945 | + ) -> None: |
922 | 946 | """Print an explanation of the DataFrame's plan so far. |
923 | 947 |
|
924 | 948 | If ``analyze`` is specified, runs the plan and reports metrics. |
925 | 949 |
|
926 | 950 | Args: |
927 | 951 | verbose: If ``True``, more details will be included. |
928 | 952 | analyze: If ``True``, the plan will run and metrics reported. |
| 953 | + format: Output format for the plan. Defaults to |
| 954 | + :py:attr:`ExplainFormat.INDENT`. |
929 | 955 | """ |
930 | | - self.df.explain(verbose, analyze) |
| 956 | + fmt = format.value if format is not None else None |
| 957 | + self.df.explain(verbose, analyze, fmt) |
931 | 958 |
|
932 | 959 | def logical_plan(self) -> LogicalPlan: |
933 | 960 | """Return the unoptimized ``LogicalPlan``. |
|
0 commit comments