|
18 | 18 | //! Defines physical expressions that can evaluated at runtime during query execution |
19 | 19 |
|
20 | 20 | use crate::hyperloglog::{HLL_HASH_STATE, HyperLogLog}; |
21 | | -use arrow::array::{Array, BinaryArray, BooleanArray, StringViewArray}; |
| 21 | +use arrow::array::{Array, BinaryArray, StringViewArray}; |
22 | 22 | use arrow::array::{ |
23 | 23 | GenericBinaryArray, GenericStringArray, OffsetSizeTrait, PrimitiveArray, |
24 | 24 | }; |
@@ -48,7 +48,6 @@ use datafusion_macros::user_doc; |
48 | 48 | use std::fmt::{Debug, Formatter}; |
49 | 49 | use std::hash::{BuildHasher, Hash}; |
50 | 50 | use std::marker::PhantomData; |
51 | | -use std::mem::size_of_val; |
52 | 51 |
|
53 | 52 | make_udaf_expr_and_func!( |
54 | 53 | ApproxDistinct, |
@@ -303,67 +302,6 @@ impl Debug for ApproxDistinct { |
303 | 302 | } |
304 | 303 | } |
305 | 304 |
|
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 | | - |
367 | 305 | impl Default for ApproxDistinct { |
368 | 306 | fn default() -> Self { |
369 | 307 | Self::new() |
@@ -510,7 +448,6 @@ impl AggregateUDFImpl for ApproxDistinct { |
510 | 448 | DataType::Utf8View => Box::new(StringViewHLLAccumulator::new()), |
511 | 449 | DataType::Binary => Box::new(BinaryHLLAccumulator::<i32>::new()), |
512 | 450 | DataType::LargeBinary => Box::new(BinaryHLLAccumulator::<i64>::new()), |
513 | | - DataType::Boolean => Box::new(BoolDistinctAccumulator::new()), |
514 | 451 | DataType::Null => { |
515 | 452 | Box::new(NoopAccumulator::new(ScalarValue::UInt64(Some(0)))) |
516 | 453 | } |
|
0 commit comments