Skip to content

Commit 88b93a3

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 6150a37 commit 88b93a3

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ impl BitmapStorage for [u64; 4] {
5757
}
5858
}
5959

60+
impl BitmapStorage for Box<[u64; 1024]> {
61+
#[inline]
62+
fn new_zeroed() -> Self {
63+
Box::new([0u64; 1024])
64+
}
65+
#[inline]
66+
fn set_bit(&mut self, index: usize) {
67+
self[index / 64] |= 1u64 << (index % 64);
68+
}
69+
#[inline(always)]
70+
fn get_bit(&self, index: usize) -> bool {
71+
(self[index / 64] >> (index % 64)) & 1 != 0
72+
}
73+
}
74+
6075
/// Configuration trait for bitmap filters.
6176
pub(crate) trait BitmapFilterConfig: Send + Sync + 'static {
6277
type Native: ArrowNativeType + Copy + Send + Sync;
@@ -79,6 +94,19 @@ impl BitmapFilterConfig for U8Config {
7994
}
8095
}
8196

97+
/// Config for u16 bitmap (65536 bits = 8 KB, fits in L1 cache).
98+
pub(crate) enum U16Config {}
99+
impl BitmapFilterConfig for U16Config {
100+
type Native = u16;
101+
type ArrowType = UInt16Type;
102+
type Storage = Box<[u64; 1024]>;
103+
104+
#[inline(always)]
105+
fn to_index(v: u16) -> usize {
106+
v as usize
107+
}
108+
}
109+
82110
/// Bitmap filter for O(1) set membership via single bit test.
83111
///
84112
/// For small integer types (u8/u16), bitmap lookup outperforms both branchless
@@ -285,7 +313,6 @@ primitive_static_filter!(Int8StaticFilter, Int8Type);
285313
primitive_static_filter!(Int16StaticFilter, Int16Type);
286314
primitive_static_filter!(Int32StaticFilter, Int32Type);
287315
primitive_static_filter!(Int64StaticFilter, Int64Type);
288-
primitive_static_filter!(UInt16StaticFilter, UInt16Type);
289316
primitive_static_filter!(UInt32StaticFilter, UInt32Type);
290317
primitive_static_filter!(UInt64StaticFilter, UInt64Type);
291318

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn instantiate_static_filter(
4040
DataType::Int32 => Ok(Arc::new(Int32StaticFilter::try_new(&in_array)?)),
4141
DataType::Int64 => Ok(Arc::new(Int64StaticFilter::try_new(&in_array)?)),
4242
DataType::UInt8 => Ok(Arc::new(BitmapFilter::<U8Config>::try_new(&in_array)?)),
43-
DataType::UInt16 => Ok(Arc::new(UInt16StaticFilter::try_new(&in_array)?)),
43+
DataType::UInt16 => Ok(Arc::new(BitmapFilter::<U16Config>::try_new(&in_array)?)),
4444
DataType::UInt32 => Ok(Arc::new(UInt32StaticFilter::try_new(&in_array)?)),
4545
DataType::UInt64 => Ok(Arc::new(UInt64StaticFilter::try_new(&in_array)?)),
4646
DataType::Float32 => Ok(Arc::new(Float32StaticFilter::try_new(&in_array)?)),

0 commit comments

Comments
 (0)