apache-spark-sql - 在sparksql中过滤掉空字符串和空字符串

标签 apache-spark-sql

好的,我有一些数据,我想在其中过滤掉所有空值和空值。所以我使用简单的sql命令首先过滤掉空值。

hiveContext.sql("select username from daten where username is not null").show()

我得到的是这样的。

org.apache.spark.sql.DataFrame = [username: array<string>]

用户名

|          [null]|
|          [null]|
|          [null]|
|              []|
|              []|
|          [null]|
|          [null]|
|              []|
|          [null]|
|          [null]|
|          [null]|
|          [null]|
|[dirk.staszak.3]|
|              []|
|              []|
|          [null]|
|          [null]|
|          [null]|
|          [null]|
|          [null]|

所以那里仍然有一些空条目。我不知道为什么?

有没有办法通过使用 sparksql 过滤掉这个空条目并额外过滤掉所有空字符串?我考虑过按字符串长度进行过滤,但 sparksql 不支持 len 函数。

最佳答案

您可以从给定的表创建一个数据框,并在 spark sql 中使用过滤器来完成任务 dataframe.filter("username is not null and username !='null'")

关于apache-spark-sql - 在sparksql中过滤掉空字符串和空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36935424/

相关文章:

apache-spark - Apache Spark SQL 中如何计算不同的工作

python - 从列表 PySpark 的列表创建单行数据框

scala - (数组/ML Vector/MLlib Vector)RDD 到 ML Vector Dataframe 可以

scala - java.lang.AssertionError : assertion failed: No plan for HiveTableRelation

pandas - 如何使用 Spark2 和 Scala 获取不同值、数据帧中列的计数并作为 (k,v) 对存储在另一个数据帧中

python - pyspark withcolumn 在每行中插入列表

scala - 如何计算 Spark 中每位客户在 12 个月内按 1 个月滑动的订单总和

python - 调用返回 FloatType() 的 UDF 时为 "expected zero arguments for construction of ClassDict (for numpy.dtype)"

apache-spark - 使用 Spark SQL 查询 Hive 分区中子目录中的数据

python - 将数据帧结果值保存到字符串变量?