在pyspark中捕获explain()的结果 [英] Capturing the result of explain() in pyspark

查看:330
本文介绍了在pyspark中捕获explain()的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在pyspark中,运行:

In pyspark, running:

sdf = sqlContext.sql("""SELECT * FROM t1 JOIN t2 on t1.c1 = t2.c1 """)

然后:

sdf.explain(extended=True)

它打印查询执行的逻辑和物理计划.

it prints the logical and physical plans of the query execution.

我的问题是:如何捕获输出而不是打印输出?

v = sdf.explain(extended=True)自然是行不通的

推荐答案

如果您查看

If you take a look at the source code of explain, you see that :

def explain(self, extended=False):
    if extended:
        print(self._jdf.queryExecution().toString())
    else:
        print(self._jdf.queryExecution().simpleString())

因此,如果要直接检索解释计划,只需在数据框上使用方法_jdf.queryExecution():

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()

这篇关于在pyspark中捕获explain()的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆