If you take a look at the source code of explain
(version 2.4 or older), you see that :
def explain(self, extended=False):
if extended:
print(self._jdf.queryExecution().toString())
else:
print(self._jdf.queryExecution().simpleString())
Therefore, if you want to retrieve the explain plan directly, just use the method _jdf.queryExecution()
on your dataframe :
v = sdf._jdf.queryExecution().toString() # or .simpleString()
From 3.0, the code is :
print(
self._sc._jvm.PythonSQLUtils.explainString(self._jdf.queryExecution(), explain_mode)
)
Removing the print, you get the explain
as a string.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…