Sandeep Shetty
Sandeep Shetty

Reputation: 177

Filtering based on Key Value in spark dataframe

I have a column in my database/dataframe which is a key value pair. I want to filter data based on certain value. Say only those rows with value 'DDD' for the key 'ddd'. How can this be achived in spark/spark sql?

"{'aaa': 'AAA', 'bbb': 'BBB', 'ccc': 'CCC', 'ddd': 'DDD', 'eee': 'EEE', 'fff': 'FFF', 'ggg': 'GGG'}"
 "{'aaa': 'AAA1', 'bbb': 'BBB1', 'ccc': 'CCC1', 'ddd': 'DDD1', 'eee': 'EEE1', 'fff': 'FFF1', 'ggg': 'GGG1'}"

Upvotes: 0

Views: 1476

Answers (1)

SanthoshPrasad
SanthoshPrasad

Reputation: 1175

We can do it like below using filter function

     DataFrame inputDf= //read from database

     DataFrame filteredDf=inputDf.filter("ddd='DDD'");

Upvotes: 2

Related Questions