From 108cc0badbea3b4caf35f089bd8fb61e3f2a291f Mon Sep 17 00:00:00 2001
From: Xiaoxuan Meng <xiaoxmeng@meta.com>
Date: Mon, 16 Dec 2024 17:11:49 -0800
Subject: [PATCH] refactor: Simplify the partial full handling for distinct
 aggregation (#11876)

Summary:

We should have the case in aggregation add input that the partial aggregation has been marked as full
but there is no new distinct detected for a distinct aggregation operator. Instead of clearing the partial
full flag, we should add a distinct check there instead for simplicity.

Differential Revision: D67288365
---
 velox/exec/HashAggregation.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/velox/exec/HashAggregation.cpp b/velox/exec/HashAggregation.cpp
index 14e87f336ec2..faa046c8f8ba 100644
--- a/velox/exec/HashAggregation.cpp
+++ b/velox/exec/HashAggregation.cpp
@@ -206,10 +206,9 @@ void HashAggregation::addInput(RowVectorPtr input) {
       // Save input to use for output in getOutput().
       input_ = input;
     } else {
-      // If no new distinct groups (meaning we don't have anything to output),
-      // then we need to ensure we 'need input'. For that we need to reset
-      // the 'partial full' flag.
-      partialFull_ = false;
+      VELOX_CHECK(
+          !partialFull_,
+          "Unexpected partial full when there is no new distincts");
     }
   }
 }