Copilot commented on code in PR #92:
URL: https://github.com/apache/sedona-db/pull/92#discussion_r2352701284


##########
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,
+    ) -> Result<String, PySedonaError> {
+        let format = ExplainFormat::from_str(format)?;
+        let explain_option = ExplainOption::default()
+            .with_analyze(analyze)
+            .with_verbose(verbose)
+            .with_format(format);
+        let explain_df = 
self.inner.clone().explain_with_options(explain_option)?;
+
+        let mut options = DisplayTableOptions::new();
+        options.table_width = width_chars.try_into().unwrap_or(u16::MAX);

Review Comment:
   Using `unwrap_or(u16::MAX)` as a fallback for width conversion could lead to 
unexpected behavior. Consider using a more reasonable default width (e.g., 120 
or 100) or explicitly handling the conversion error with a proper error message.
   ```suggestion
           options.table_width = width_chars.try_into().unwrap_or(120);
   ```



##########
rust/sedona/src/context.rs:
##########
@@ -292,9 +292,23 @@ impl SedonaDataFrame for DataFrame {
         self,
         ctx: &SedonaContext,
         limit: Option<usize>,
-        options: DisplayTableOptions<'a>,
+        mut options: DisplayTableOptions<'a>,
     ) -> Result<String> {
-        let df = self.limit(0, limit)?;
+        let df = if matches!(
+            self.logical_plan(),
+            LogicalPlan::Explain(_) | LogicalPlan::DescribeTable(_) | 
LogicalPlan::Analyze(_)
+        ) {
+            // Show multi-line output without truncation for plans like 
`EXPLAIN`
+            options.max_row_height = usize::MAX;
+
+            // We don't want to apply an additional .limit() to plans like 
`Explain`
+            // as that will trigger an internal error: Unsupported logical 
plan: Explain must be root of the plan
+            self
+        } else {
+            // Apply limit if specified
+            self.limit(0, limit)?

Review Comment:
   [nitpick] The `options` parameter is changed from immutable to mutable, but 
this modification is only used within a specific conditional branch. Consider 
cloning the options within the conditional block instead of making the entire 
parameter mutable to maintain clearer ownership semantics.



-- 
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]

Reply via email to