paleolimbot commented on code in PR #92:
URL: https://github.com/apache/sedona-db/pull/92#discussion_r2352740459
##########
python/sedonadb/src/dataframe.rs:
##########
@@ -186,6 +187,41 @@ impl InternalDataFrame {
Ok(content)
}
+ #[allow(clippy::too_many_arguments)]
+ fn explain<'py>(
+ &self,
+ py: Python<'py>,
+ ctx: &InternalContext,
+ verbose: bool,
+ analyze: bool,
+ format: &str,
+ width_chars: usize,
+ ascii: bool,
Review Comment:
If this function returned a `DataFrame` we could probably avoid having to
duplicate the show logic
##########
python/sedonadb/python/sedonadb/dataframe.py:
##########
@@ -361,6 +361,55 @@ def show(
width = _out_width(width)
print(self._impl.show(self._ctx, limit, width, ascii), end="")
+ def explain(
+ self,
+ verbose: bool = False,
+ analyze: bool = False,
+ format: str = "indent",
+ width: Optional[int] = None,
+ ascii: bool = False,
+ ) -> str:
+ """Print the execution plan for this DataFrame
+
+ Shows the logical and physical execution plans that will be used to
+ compute this DataFrame. This is useful for understanding query
+ performance and optimization.
+
+ Args:
+ verbose: Use True to show additional details in the plan output.
+ analyze: Use True to actually execute the plan and report metrics.
+ format: The format to use for displaying the plan. Supported
formats are
+ "indent", "tree", "pgjson" and "graphviz"
+ width: The number of characters to use to display the output.
+ If None, uses `Options.width` or detects the value from the
+ current terminal if available.
+ ascii: Use True to disable UTF-8 characters in the output.
+
+ Returns:
+ A string representation of the execution plan.
+
+ Examples:
+
+ >>> import sedonadb
+ >>> con = sedonadb.connect()
+ >>> df = con.sql("SELECT 1 as one")
+ >>> print(df.explain())
Review Comment:
I would have expected this function to do the `print()`ing (DuckDB's does)
so that the user doesn't have to. In the future we might want to return a
custom object like `class Explain` whose `__repr__` is the text output to more
easily provide access to the explanation (e.g., to render the JSON into a
jupyter widget).
##########
python/sedonadb/python/sedonadb/dataframe.py:
##########
@@ -361,6 +361,55 @@ def show(
width = _out_width(width)
print(self._impl.show(self._ctx, limit, width, ascii), end="")
+ def explain(
+ self,
+ verbose: bool = False,
+ analyze: bool = False,
Review Comment:
I'm not sure we need to maintain DuckDB compatibility here, but DuckDB
parameterizes this as `explain(type="standard")/explain(type="analyze")`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]