Skip to content

Commit c16592d

Browse files
author
B Vadlamani
committed
remove_bool_accumulator
1 parent e0f2aa9 commit c16592d

1 file changed

Lines changed: 1 addition & 64 deletions

File tree

datafusion/functions-aggregate/src/approx_distinct.rs

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! Defines physical expressions that can evaluated at runtime during query execution
1919
2020
use crate::hyperloglog::{HLL_HASH_STATE, HyperLogLog};
21-
use arrow::array::{Array, BinaryArray, BooleanArray, StringViewArray};
21+
use arrow::array::{Array, BinaryArray, StringViewArray};
2222
use arrow::array::{
2323
GenericBinaryArray, GenericStringArray, OffsetSizeTrait, PrimitiveArray,
2424
};
@@ -48,7 +48,6 @@ use datafusion_macros::user_doc;
4848
use std::fmt::{Debug, Formatter};
4949
use std::hash::{BuildHasher, Hash};
5050
use std::marker::PhantomData;
51-
use std::mem::size_of_val;
5251

5352
make_udaf_expr_and_func!(
5453
ApproxDistinct,
@@ -303,67 +302,6 @@ impl Debug for ApproxDistinct {
303302
}
304303
}
305304

306-
/// Optimized accumulator for Boolean type - only 2 possible distinct values.
307-
#[derive(Debug)]
308-
struct BoolDistinctAccumulator {
309-
seen_true: bool,
310-
seen_false: bool,
311-
}
312-
313-
impl BoolDistinctAccumulator {
314-
fn new() -> Self {
315-
Self {
316-
seen_true: false,
317-
seen_false: false,
318-
}
319-
}
320-
}
321-
322-
impl Accumulator for BoolDistinctAccumulator {
323-
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()> {
324-
if values.is_empty() {
325-
return Ok(());
326-
}
327-
328-
let array: &BooleanArray = downcast_value!(values[0], BooleanArray);
329-
for value in array.iter().flatten() {
330-
if value {
331-
self.seen_true = true;
332-
} else {
333-
self.seen_false = true;
334-
}
335-
}
336-
Ok(())
337-
}
338-
339-
fn evaluate(&mut self) -> Result<ScalarValue> {
340-
let count = self.seen_true as u64 + self.seen_false as u64;
341-
Ok(ScalarValue::UInt64(Some(count)))
342-
}
343-
344-
fn size(&self) -> usize {
345-
size_of_val(self)
346-
}
347-
348-
fn state(&mut self) -> Result<Vec<ScalarValue>> {
349-
// State: two booleans packed into a binary
350-
let state = vec![self.seen_false as u8, self.seen_true as u8];
351-
Ok(vec![ScalarValue::Binary(Some(state))])
352-
}
353-
354-
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()> {
355-
assert_eq!(1, states.len(), "expect only 1 element in the states");
356-
let binary_array = downcast_value!(states[0], BinaryArray);
357-
for v in binary_array.iter().flatten() {
358-
if v.len() >= 2 {
359-
self.seen_false = self.seen_false || v[0] != 0;
360-
self.seen_true = self.seen_true || v[1] != 0;
361-
}
362-
}
363-
Ok(())
364-
}
365-
}
366-
367305
impl Default for ApproxDistinct {
368306
fn default() -> Self {
369307
Self::new()
@@ -510,7 +448,6 @@ impl AggregateUDFImpl for ApproxDistinct {
510448
DataType::Utf8View => Box::new(StringViewHLLAccumulator::new()),
511449
DataType::Binary => Box::new(BinaryHLLAccumulator::<i32>::new()),
512450
DataType::LargeBinary => Box::new(BinaryHLLAccumulator::<i64>::new()),
513-
DataType::Boolean => Box::new(BoolDistinctAccumulator::new()),
514451
DataType::Null => {
515452
Box::new(NoopAccumulator::new(ScalarValue::UInt64(Some(0))))
516453
}

0 commit comments

Comments
 (0)