Github user davies commented on the pull request:
https://github.com/apache/spark/pull/8362#issuecomment-143902631
I took a round, this looks pretty good to me over all.
Currently, each grouping key needs 200 bytes (b=8, by default), so the
sparse version could help to reduce the memory usage in case of the average
number of distinct value is small (I believe it's a common case). Since we
already support external aggregation (using sort based), so it's not critical,
could be a optional improvement (separated PR).
Had ran a small benchmark for this patch, I'm surprised it's slower than
1.5 (using old aggregation). The test code:
```
df = sqlContext.range(1<<25).agg(approxCountDistinct("id"))
df.explain()
t = time.time()
print df.collect()
print time.time() - t
```
It took 3.4 seconds in 1.5, but 6.4 seconds with this patch.
The plain in 1.5:
```
Aggregate false, [APPROXIMATE COUNT(DISTINCT PartialApproxCountDistinct#2)
AS APPROXIMATE COUNT(DISTINCT id)#1L]
Exchange SinglePartition
Aggregate true, [APPROXIMATE COUNT(DISTINCT id#0L) AS
PartialApproxCountDistinct#2]
Scan PhysicalRDD[id#0L]
```
The plan with this patch:
```
SortBasedAggregate(key=[],
functions=[(hyperloglogplusplus(id#0L),mode=Final,isDistinct=false)],
output=[APPROXIMATE COUNT(DISTINCT id)#1L])
ConvertToSafe
TungstenExchange SinglePartition
ConvertToUnsafe
SortBasedAggregate(key=[],
functions=[(hyperloglogplusplus(id#0L),mode=Partial,isDistinct=false)],
output=[MS[0]#30L,MS[1]#31L,MS[2]#32L,MS[3]#33L,MS[4]#34L,MS[5]#35L,MS[6]#36L,MS[7]#37L,MS[8]#38L,MS[9]#39L,MS[10]#40L,MS[11]#41L,MS[12]#42L,MS[13]#43L,MS[14]#44L,MS[15]#45L,MS[16]#46L,MS[17]#47L,MS[18]#48L,MS[19]#49L,MS[20]#50L,MS[21]#51L,MS[22]#52L,MS[23]#53L,MS[24]#54L,MS[25]#55L])
Scan PhysicalRDD[id#0L]
```
Discussed this with @yhuai , the slowness may come from the new
aggregation, that only not support AAlgebraicAggregate in hash mode, we will
fix that in 1.6.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]