Skip to content

Commit db87ea2

Browse files
author
Davies Liu
committed
output explain in Python
1 parent 9b746f3 commit db87ea2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

python/pyspark/sql/dataframe.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,25 @@ def explain(self, extended=False):
244244
debugging purpose.
245245
246246
If extended is False, only prints the physical plan.
247-
"""
248-
self._jdf.explain(extended)
247+
248+
>>> df.explain()
249+
PhysicalRDD [age#0,name#1], MapPartitionsRDD[...] at mapPartitions at SQLContext.scala:...
250+
251+
>>> df.explain(True)
252+
== Parsed Logical Plan ==
253+
...
254+
== Analyzed Logical Plan ==
255+
...
256+
== Optimized Logical Plan ==
257+
...
258+
== Physical Plan ==
259+
...
260+
== RDD ==
261+
"""
262+
if extended:
263+
print self._jdf.queryExecution().toString()
264+
else:
265+
print self._jdf.queryExecution().executedPlan().toString()
249266

250267
def isLocal(self):
251268
"""
@@ -1034,7 +1051,7 @@ def _test():
10341051
Row(name='Bob', age=5, height=85)]).toDF()
10351052
(failure_count, test_count) = doctest.testmod(
10361053
pyspark.sql.dataframe, globs=globs,
1037-
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
1054+
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF)
10381055
globs['sc'].stop()
10391056
if failure_count:
10401057
exit(-1)

0 commit comments

Comments
 (0)