Derive from DelegateConstantToCountAggregateFunction instead. This will help handle the albeit strange case of COUNT(DISTINCT 1). In this case, when the child expression is a constant, we'll delegate to the CountAggregateFunction. You'll need to tweak the evaluate method slightly to handle this case, but basically you'll either return 0 if CountAggregateFunction returns 0 or 1 if anything else.