JeelRajodiya commented on code in PR #22707:
URL: https://github.com/apache/datafusion/pull/22707#discussion_r3339655982
##########
datafusion/functions-aggregate-common/src/aggregate/count_distinct/native.rs:
##########
@@ -518,3 +519,101 @@ impl Accumulator for
Bitmap65536DistinctCountAccumulatorI16 {
size_of_val(self) + 8192
}
}
+
+/// Optimized COUNT DISTINCT accumulator for `Boolean` using two flags.
+///
+/// Tracks whether `false` and `true` have been observed; nulls are skipped.
+/// Result is always 0, 1, or 2.
+#[derive(Debug)]
+pub struct BooleanDistinctCountAccumulator {
+ has_seen_false: bool,
+ has_seen_true: bool,
+}
+
+impl BooleanDistinctCountAccumulator {
+ pub fn new() -> Self {
+ Self {
+ has_seen_false: false,
+ has_seen_true: false,
+ }
+ }
+
+ #[inline]
+ fn seen_both(&self) -> bool {
+ self.has_seen_false && self.has_seen_true
+ }
+
+ #[inline]
+ fn count(&self) -> i64 {
+ self.has_seen_false as i64 + self.has_seen_true as i64
Review Comment:
Yes. I've updated it now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]