【发布时间】:2017-06-12 02:16:53
【问题描述】:
我在 spark-sql 中有两个不同类型的值,如下所示
scala> val ageSum = df.agg(sum("age"))
ageSum: org.apache.spark.sql.DataFrame = [sum(age): bigint]
scala> val totalEntries = df.count();
scala> totalEntries
res37: Long = 45211
第一个值来自数据帧上的聚合函数,第二个值来自数据帧上的总计数函数。两者都有不同的类型,因为 ageSum 是 bigInt,totalEntries 是 Long。我想对其进行数学运算。平均值 = ageSum/totalEntries
scala> val mean = ageSum/totalEntries
<console>:31: error: value / is not a member of org.apache.spark.sql.DataFrame val mean = ageSum/totalEntries
我也尝试将 ageSum 转换为 long 类型,但无法这样做
scala> val ageSum = ageSum.longValue
<console>:29: error: recursive value ageSum needs type
val ageSum = ageSum.longValues
【问题讨论】:
标签: scala apache-spark apache-spark-sql bigdata