首页 > 代码库 > Spark2 DataFrame数据框常用操作(八)之cube与rollup
Spark2 DataFrame数据框常用操作(八)之cube与rollup
val df6 = spark.sql("select gender,children,max(age),avg(age),count(age) from Affairs group by Cube(gender,children) order by 1,2") df6.show +------+--------+--------+--------+----------+ |gender|children|max(age)|avg(age)|count(age)| +------+--------+--------+--------+----------+ | null| null| 57.0| 34.0| 10| | null| no| 37.0| 27.0| 6| | null| yes| 57.0| 44.5| 4| |female| null| 32.0| 29.0| 5| |female| no| 32.0| 27.0| 3| |female| yes| 32.0| 32.0| 2| | male| null| 57.0| 39.0| 5| | male| no| 37.0| 27.0| 3| | male| yes| 57.0| 57.0| 2| +------+--------+--------+--------+----------+ val df7 = spark.sql("select gender,children,max(age),avg(age),count(age) from Affairs group by rollup(gender,children) order by 1,2") df7.show +------+--------+--------+--------+----------+ |gender|children|max(age)|avg(age)|count(age)| +------+--------+--------+--------+----------+ | null| null| 57.0| 34.0| 10| |female| null| 32.0| 29.0| 5| |female| no| 32.0| 27.0| 3| |female| yes| 32.0| 32.0| 2| | male| null| 57.0| 39.0| 5| | male| no| 37.0| 27.0| 3| | male| yes| 57.0| 57.0| 2| +------+--------+--------+--------+----------+
Spark2 DataFrame数据框常用操作(八)之cube与rollup
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。