Spark - 按数据帧语法分组? [英] Spark - Group by HAVING with dataframe syntax?

查看:27
本文介绍了Spark - 按数据帧语法分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在没有 sql/hiveContext 的情况下在 Spark 中使用 groupby-have 的语法是什么?我知道我能做到

What's the syntax for using a groupby-having in Spark without an sql/hiveContext? I know I can do

DataFrame df = some_df
df.registreTempTable("df");    
df1 = sqlContext.sql("SELECT * FROM df GROUP BY col1 HAVING some stuff")

但是我如何使用像

df.select(df.col("*")).groupBy(df.col("col1")).having("some stuff")

这个.have()似乎不存在.

推荐答案

是的,它不存在.您可以使用 agg 后跟 where:

Yes, it doesn't exist. You express the same logic with agg followed by where:

df.groupBy(someExpr).agg(somAgg).where(somePredicate) 

这篇关于Spark - 按数据帧语法分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆