【发布时间】:2020-01-31 06:26:58
【问题描述】:
我想为每个 score_threshold 显示 Column1 的不同计数;但是,我收到此行的“非法声明开始”错误:
results = results :+ (threshold,count)
我正在尝试 z.show() 这些计数在 Zeppelin 笔记本中的图表上。
我有以下 scala 代码:
val score_threshold = Seq(50.0,100.0,200.0,250.00,500.00,1000.00)
var results = Seq((0.0,0.0))
score_threshold.foreach(threshold:Double => {
val counts = DF.filter($"score" >= threshold)
.groupBy().agg(countDistinct("column1").as("count")).rdd.map(x=> x.getDouble(0)).collect.head
results = results :+ (threshold,count)
})
z.show(results.toDF("threshold","count"))
这是我得到的错误:
error: illegal start of declaration
results = results :+ (threshold,count)
【问题讨论】:
-
score_threshold 是字符串序列,而不是双精度序列。您必须将其读取为字符串并将每个值转换为双精度。
标签: scala foreach apache-zeppelin