为了账号安全,请及时绑定邮箱和手机立即绑定

如何在Spark SQL中定义和使用用户定义的聚合函数?

如何在Spark SQL中定义和使用用户定义的聚合函数?

如何在Spark SQL中定义和使用用户定义的聚合函数?我知道如何在Spark SQL中编写UDF:def belowThreshold(power: Int): Boolean = {         return power < -40       }sqlContext.udf.register("belowThreshold", belowThreshold _)我可以做类似的定义聚合函数吗?这是怎么做到的?对于上下文,我想运行以下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)我希望聚合函数告诉我opticalReceivePower在定义的组中是否有任何值span,timestamp哪些值低于阈值。我是否需要以不同的方式将UDAF写入上面粘贴的UDF?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 451 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信