问题
This can be a really simple question. I am using Spark 1.6 with scala
var DF=hivecontext.sql("select name from myTable")
val name_max_len =DF.agg(max(length($"name"))) // did not work
println(name_max_len)
How can I get max length?
回答1:
You should collect result:
import org.apache.spark.sql.functions.max
val df = Seq("foo", "bar", "foobar").toDF("name")
df.agg(max(length($"name"))).as[Int].first
// res0: Int = 6
来源:https://stackoverflow.com/questions/41270204/how-to-get-max-length-of-string-column-from-dataframe-using-scala