Apache Spark's RewriteDistinctAggregate Rule

Table of Contents Introduction First Case Second Case Third Case Introduction These are some of my notes on the optimizer rule RewriteDistinctAggregate . At the time I jotted down these notes, Apache Spark was at version 3.3.x, but I think these notes largely still hold true (as of some preview release of 4.1.0). These notes help to remind me what RewriteDistinctAggregate is trying to achieve, so…