Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-row/src/utils.rs
6939 views
1
#![allow(unsafe_op_in_unsafe_fn)]
2
use arrow::bitmap::{Bitmap, BitmapBuilder};
3
4
#[macro_export]
5
macro_rules! with_match_arrow_primitive_type {(
6
$key_type:expr, | $_:tt $T:ident | $($body:tt)*
7
) => ({
8
macro_rules! __with_ty__ {( $_ $T:ident ) => ( $($body)* )}
9
use arrow::datatypes::ArrowDataType::*;
10
match $key_type {
11
Int8 => __with_ty__! { i8 },
12
Int16 => __with_ty__! { i16 },
13
Int32 => __with_ty__! { i32 },
14
Int64 => __with_ty__! { i64 },
15
Int128 => __with_ty__! { i128 },
16
UInt8 => __with_ty__! { u8 },
17
UInt16 => __with_ty__! { u16 },
18
UInt32 => __with_ty__! { u32 },
19
UInt64 => __with_ty__! { u64 },
20
Float32 => __with_ty__! { f32 },
21
Float64 => __with_ty__! { f64 },
22
_ => unreachable!(),
23
}
24
})}
25
26
pub(crate) unsafe fn decode_opt_nulls(rows: &[&[u8]], null_sentinel: u8) -> Option<Bitmap> {
27
let first_null = rows
28
.iter()
29
.position(|row| *row.get_unchecked(0) == null_sentinel)?;
30
31
let mut bm = BitmapBuilder::with_capacity(rows.len());
32
bm.extend_constant(first_null, true);
33
bm.push(false);
34
35
bm.extend_trusted_len_iter(
36
rows[first_null + 1..]
37
.iter()
38
.map(|row| *row.get_unchecked(0) != null_sentinel),
39
);
40
41
bm.into_opt_validity()
42
}
43
44