如何在Spark SQL中定義和使用用戶定義的聚合函數(shù)?我知道如何在Spark SQL中編寫UDF:def belowThreshold(power: Int): Boolean = {
return power < -40
}sqlContext.udf.register("belowThreshold", belowThreshold _)我可以做類似的定義聚合函數(shù)嗎?這是怎么做到的?對于上下文,我想運行以下SQL查詢:val aggDF = sqlContext.sql("""SELECT span, belowThreshold(opticalReceivePower), timestamp
FROM ifDF
WHERE opticalReceivePower IS NOT null
GROUP BY span, timestamp
ORDER BY span""")它應該返回類似的東西Row(span1, false, T0)我希望聚合函數(shù)告訴我opticalReceivePower在定義的組中是否有任何值span,timestamp哪些值低于閾值。我是否需要以不同的方式將UDAF寫入上面粘貼的UDF?
如何在Spark SQL中定義和使用用戶定義的聚合函數(shù)?
墨色風雨
2019-08-19 14:35:13