如何检查 DataFrame(Scala)以最快的方式为空?我用DF.limit(1).rdd.isEmpty,比 DF.rdd.isEmpty 更快,但并不理想。有没有更好的方法可以做到这一点?
我通常会打电话给first
围绕一个Try
:
import scala.util.Try
val t = Try(df.first)
从那里你可以匹配它,如果它是Success
or Failure
控制逻辑:
import scala.util.{Success,Failure}
t match {
case Success(df) => //do stuff with the dataframe
case Failure(e) =>
// dataframe is empty; do other stuff
//e.getMessage will return the exception message
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)