E B
E B

Reputation: 1073

How to filter a RDD according to list of values

I am able to accomplish a filter for RDD[Test] using a specific value

Test.filter(_.state == "NY") 

I need to extend this to be able to filter Test with multiple values like ("NY","CA","PA")

Is there an "in list" or in ("NY","CA","PA") in scala

Upvotes: 3

Views: 5436

Answers (1)

Nyavro
Nyavro

Reputation: 8866

You can put values in Set and filter the following way:

val set = Set("NY", "CA", "PA")
rdd.filter(item => set(item.state))

to test if value is in set:

set.contains(value) 

or

set(value)

Upvotes: 2

Related Questions