Spark - extracting single value from DataFrame

前端 未结 3 1889
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 20:55

I have a Spark DataFrame query that is guaranteed to return single column with single Int value. What is the best way to extract this value as Int from the resulting DataFrame?<

3条回答
  •  迷失自我
    2021-01-30 21:18

    You can use head

    df.head().getInt(0)
    

    or first

    df.first().getInt(0)
    

    Check DataFrame scala docs for more details

提交回复
热议问题