amalicode
amalicode

Reputation: 37

How to search value in Dataset<Row> in java spark?

My Dataset< Row > (java spark) input is :

Heros Powers Rank
Superman Invisible 1
Batman Strength 2
SpiderMan Strong 3

By knowing the name of my heros, i would like to retrieve the rank. For exemple for Superman, i would like to have the return 1, not all the line but just the value. I don't know how to do by using a spark dataset. Thank for your help !

Upvotes: 0

Views: 633

Answers (1)

blackbishop
blackbishop

Reputation: 32660

You can try:

int rank = dataset.filter("Heros ='Superman'").select(col("Rank")).first().getInt(0);

Upvotes: 1

Related Questions