星火数据框中检查平等和过滤 [英] Spark dataframe checking equality and filtering

查看:122
本文介绍了星火数据框中检查平等和过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何与特定值筛选列?

How do I filter column with particular value?

这正常工作>

scala> dataframe.filter("postalCode > 900").count()

== 失败

scala> dataframe.filter("postalCode == 900").count()
java.lang.RuntimeException: [1.13] failure: identifier expected

postalCode == 900 ##Error line

我知道我缺少明显的东西,但我不能弄清楚。我检查 API文档因此对于相同的。此外,试图让 ===

I know I am missing something obvious but I cant figure out. I checked API doc and SO for same. Also, tried giving ===

推荐答案

您传递给前pression字符串过滤 / 其中,应该是一个有效的SQL前pression。这意味着你必须使用一个单一的运营商平等的:

Expression string you pass to filter / where should be a valid SQL expression. It means you have to use a single equal operator:

dataframe.filter("postalCode = 900")

和例子

val df = sc.parallelize(Seq(("foo", 900), ("bar", 100))).toDF("k", "postalCode")
df.where("postalCode = 900").show

// +---+----------+
// |  k|postalCode|
// +---+----------+
// |foo|       900|
// +---+----------+

这篇关于星火数据框中检查平等和过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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