Jhon
Jhon

Reputation: 137

How to get max length of string column from dataframe using scala?

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?

Upvotes: 5

Views: 13828

Answers (1)

user7327360
user7327360

Reputation: 136

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

Upvotes: 12

Related Questions