电光中用于检查数据框中列为空或空字符串的isNullOrEmpty函数 [英] isNullOrEmpty function in spark to check column in data frame is null or empty string

查看:30
本文介绍了电光中用于检查数据框中列为空或空字符串的isNullOrEmpty函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查电光中的dataframe列是否为空

例如

type IdentifiedDataFrame = {SourceIdentfier, DataFrame}
def splitRequestIntoDFsWithAndWithoutTransactionId(df: DataFrame) : Seq[IdentifiedDataFrame] = {
  seq((DeltaTableStream(RequestWithTransactionId), df.filter(col(RequestLocationCodeColName).isNull
      && col(ServiceNumberColName).isNull
      && col(DateOfServiceColName).isNull
      && col(TransactionIdColName).isNotNull)).
    
      (DeltaTableStream(RequestWithoutTransactionId), df.filter(col(RequestLocationCodeColName).isNotNull
       && col(ServiceNumberColName).isNotNull
       && col(DateOfServiceColName).isNotNull))
      )
}
注意:此代码仅检查列中的NULL值,我希望同时检查NULL或空字符串 请帮帮忙

推荐答案

您可以使用isNull函数,使用filter检查空字符串,如下所示

val columns = List("column1", "column2")

val filter = columns.map(c => isnull(col(c)) || !(col(c) <=> lit("")))
  .reduce(_ and _)

df.filter(filter)

这篇关于电光中用于检查数据框中列为空或空字符串的isNullOrEmpty函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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