How do I check for equality using Spark Dataframe without SQL Query?

Instinct picture Instinct · Jul 9, 2015 · Viewed 129.8k times · Source

I want to select a column that equals to a certain value. I am doing this in scala and having a little trouble.

Heres my code

df.select(df("state")==="TX").show()

this returns the state column with boolean values instead of just TX

Ive also tried

df.select(df("state")=="TX").show() 

but this doesn't work either.

Answer

user3487888 picture user3487888 · Feb 8, 2016

I had the same issue, and the following syntax worked for me:

df.filter(df("state")==="TX").show()

I'm using Spark 1.6.