The underlying issue is how Spark and Hive treat 0.0 and -0.0, which are numerically identical but not the same double value:
In hive, 0.0 and -0.0 are equal since https://issues.apache.org/jira/browse/HIVE-11174.
That's not the case with spark sql as "group by" (non-codegen) treats them as different values. Since their hash is different they're put in different buckets of UnsafeFixedWidthAggregationMap.
In addition there's an inconsistency when using the codegen, for example the following unit test:
Note that the only difference between the first 2 lines is the order of the elements in the Seq.
This inconsistency is resulted by different partitioning of the Seq and the usage of the generated fast hash map in the first, partial, aggregation.
It looks like we need to add a specific check for -0.0 before hashing (both in codegen and non-codegen modes) if we want to fix this.