如何使用scala从数据框中获取字符串列的最大长度? [英] How to get max length of string column from dataframe using scala?
本文介绍了如何使用scala从数据框中获取字符串列的最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个非常简单的问题.我在Scala中使用Spark 1.6
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)
如何获得最大长度?
推荐答案
您应该收集结果:
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
这篇关于如何使用scala从数据框中获取字符串列的最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文