Skip to content

Commit 55f3836

Browse files
Extend Bitmap Filter to UInt16 (Heap-based)
Implements an 8 KB heap-allocated bitmap for UInt16. Maintains O(1) performance while handling the larger value space. Triggers for UInt16 arrays.
1 parent b910c6a commit 55f3836

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

datafusion/physical-expr/src/expressions/in_list/primitive_filter.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ impl BitmapStorage for [u64; 4] {
4949
}
5050
}
5151

52+
impl BitmapStorage for Box<[u64; 1024]> {
53+
#[inline]
54+
fn new_zeroed() -> Self {
55+
Box::new([0u64; 1024])
56+
}
57+
#[inline]
58+
fn set_bit(&mut self, index: usize) {
59+
self[index / 64] |= 1u64 << (index % 64);
60+
}
61+
#[inline(always)]
62+
fn get_bit(&self, index: usize) -> bool {
63+
(self[index / 64] >> (index % 64)) & 1 != 0
64+
}
65+
}
66+
5267
pub(super) trait BitmapFilterConfig: Send + Sync + 'static {
5368
const DATA_TYPE_NAME: &'static str;
5469

@@ -73,10 +88,24 @@ impl BitmapFilterConfig for UInt8BitmapConfig {
7388
}
7489
}
7590

91+
pub(super) enum UInt16BitmapConfig {}
92+
impl BitmapFilterConfig for UInt16BitmapConfig {
93+
const DATA_TYPE_NAME: &'static str = "UInt16";
94+
95+
type Native = u16;
96+
type ArrowType = UInt16Type;
97+
type Storage = Box<[u64; 1024]>;
98+
99+
#[inline(always)]
100+
fn to_index(v: u16) -> usize {
101+
v as usize
102+
}
103+
}
104+
76105
/// Bitmap filter for O(1) set membership via single bit test.
77106
///
78-
/// `UInt8` has only 256 possible values, so the filter stores membership in a
79-
/// 256-bit bitmap instead of using a hash table.
107+
/// Small integer domains can store membership in a fixed-size bitmap instead
108+
/// of using a hash table.
80109
pub(super) struct BitmapFilter<C: BitmapFilterConfig> {
81110
null_count: usize,
82111
bits: C::Storage,
@@ -321,7 +350,6 @@ primitive_static_filter!(Int8StaticFilter, Int8Type);
321350
primitive_static_filter!(Int16StaticFilter, Int16Type);
322351
primitive_static_filter!(Int32StaticFilter, Int32Type);
323352
primitive_static_filter!(Int64StaticFilter, Int64Type);
324-
primitive_static_filter!(UInt16StaticFilter, UInt16Type);
325353
primitive_static_filter!(UInt32StaticFilter, UInt32Type);
326354
primitive_static_filter!(UInt64StaticFilter, UInt64Type);
327355

datafusion/physical-expr/src/expressions/in_list/strategy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ pub(super) fn instantiate_static_filter(
4545
DataType::UInt8 => Ok(Arc::new(BitmapFilter::<UInt8BitmapConfig>::try_new(
4646
&in_array,
4747
)?)),
48-
DataType::UInt16 => Ok(Arc::new(UInt16StaticFilter::try_new(&in_array)?)),
48+
DataType::UInt16 => Ok(Arc::new(BitmapFilter::<UInt16BitmapConfig>::try_new(
49+
&in_array,
50+
)?)),
4951
DataType::UInt32 => Ok(Arc::new(UInt32StaticFilter::try_new(&in_array)?)),
5052
DataType::UInt64 => Ok(Arc::new(UInt64StaticFilter::try_new(&in_array)?)),
5153
// Float primitive types (use ordered wrappers for Hash/Eq)

0 commit comments

Comments
 (0)