Best way to get the max value in a Spark dataframe column

后端 未结 13 1055
一整个雨季
一整个雨季 2020-12-07 10:27

I\'m trying to figure out the best way to get the largest value in a Spark dataframe column.

Consider the following example:

df = spark.createDataFra         


        
13条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 10:45

    In case some wonders how to do it using Scala (using Spark 2.0.+), here you go:

    scala> df.createOrReplaceTempView("TEMP_DF")
    scala> val myMax = spark.sql("SELECT MAX(x) as maxval FROM TEMP_DF").
        collect()(0).getInt(0)
    scala> print(myMax)
    117
    

提交回复
热议问题