5

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 Answer 1

12

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
Sign up to request clarification or add additional context in comments.

1 Comment

df.agg(max(length($"name"))).as[Int].first did not work, ".as" became red. Do I need to import any library ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.