【发布时间】:2019-10-01 07:48:23
【问题描述】:
我有以下数据,我需要根据键分组并根据键计数以监控指标。我可以使用 groupBy 并为该组进行计数,但这涉及一些洗牌。我们可以不做 shuffle 吗?
ID,TempID,PermanantID
----------
xxx, abcd, 12345
xxx, efg, 1345
xxx, ijk, 1534
xxx, lmn, 13455
xxx, null, 12345
xxx, axg, null
yyy, abcd, 12345
yyy, efg, 1345
yyy, ijk, 1534
zzz, lmn, 13455
zzz, abc, null
输出应该是
ID Count1 Count2
----------
XXX 5 5
YYY 3 3
ZZZ 2 1
我可以用 groupBy 和 count 做到这一点
dataframe.groupby("ID").agg(col("TempID").as("Count1"),count(col("PermanantID").as("Count2"))
我们可以使用 mapPartition 做到这一点吗?
【问题讨论】:
标签: scala dataframe apache-spark streaming spark-structured-streaming