对于以下两种检查数据帧是否为空的方法:
df.isEmpty
df.limit(1).count == 0
我看到df.isEmpty
有以下实现:
def isEmpty: Boolean = withAction("isEmpty", limit(1).groupBy().count().queryExecution) { plan =>
plan.executeCollect().head.getLong(0) == 0
}
Run Code Online (Sandbox Code Playgroud)
看起来它不只是直接计数。
其背后的想法是groupBy
什么?只是为了获取数据框?
为什么要queryExecution
使用该计划?