You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/12/12 22:05:28 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #26861: [SPARK-30231][SQL][PYTHON] Support explain mode in PySpark df.explain

dongjoon-hyun commented on a change in pull request #26861: [SPARK-30231][SQL][PYTHON] Support explain mode in PySpark df.explain
URL: https://github.com/apache/spark/pull/26861#discussion_r357394962
 
 

 ##########
 File path: python/pyspark/sql/dataframe.py
 ##########
 @@ -271,11 +279,47 @@ def explain(self, extended=False):
         ...
         == Physical Plan ==
         ...
+
+        >>> df.explain(mode="formatted")
+        == Physical Plan ==
+        * Scan ExistingRDD (1)
+        (1) Scan ExistingRDD [codegen id : 1]
+        Output: [age#0, name#1]
+
+        .. versionchanged:: 3.0.0
+           Added optional argument `mode` to specify the expected output format of plans.
         """
-        if extended:
-            print(self._jdf.queryExecution().toString())
-        else:
-            print(self._jdf.queryExecution().simpleString())
+
+        if extended is not None and mode is not None:
+            raise Exception("extended and mode can not be specified simultaneously")
+
+        # For the no argument case: df.explain()
+        is_no_argument = extended is None and mode is None
+
+        # For the cases below:
+        #   explain(True)
+        #   explain(extended=False)
+        is_extended_case = extended is not None and isinstance(extended, bool)
+
+        # For the mode specified: df.explain(mode="formatted")
+        is_mode_case = mode is not None and isinstance(mode, basestring)
+
+        if not is_no_argument and not (is_extended_case or is_mode_case):
+            argtypes = [
+                str(type(arg)) for arg in [extended, mode] if arg is not None]
+            raise TypeError(
+                "extended (optional) and mode (optional) should be a bool and str; "
+                "however, got [%s]." % ", ".join(argtypes))
+
+        # Sets an explain mode depending on a given argument
+        if is_no_argument:
+          explainMode = "simple"
+        elif is_extended_case:
+          explainMode = "extended" if extended else "simple"
+        elif is_mode_case:
+          explainMode = mode
 
 Review comment:
   We need to have 4-space indentation, @maropu .
   ```
   ./python/pyspark/sql/dataframe.py:316:11: E111 indentation is not a multiple of four
   ./python/pyspark/sql/dataframe.py:318:11: E111 indentation is not a multiple of four
   ./python/pyspark/sql/dataframe.py:320:11: E111 indentation is not a multiple of four
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org