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
8420 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
use polars_utils::float16::pf16;
11
match $key_type {
12
Int8 => __with_ty__! { i8 },
13
Int16 => __with_ty__! { i16 },
14
Int32 => __with_ty__! { i32 },
15
Int64 => __with_ty__! { i64 },
16
Int128 => __with_ty__! { i128 },
17
UInt8 => __with_ty__! { u8 },
18
UInt16 => __with_ty__! { u16 },
19
UInt32 => __with_ty__! { u32 },
20
UInt64 => __with_ty__! { u64 },
21
UInt128 => __with_ty__! { u128 },
22
Float16 => __with_ty__! { pf16 },
23
Float32 => __with_ty__! { f32 },
24
Float64 => __with_ty__! { f64 },
25
_ => unreachable!(),
26
}
27
})}
28
29
pub(crate) unsafe fn decode_opt_nulls(rows: &[&[u8]], null_sentinel: u8) -> Option<Bitmap> {
30
let first_null = rows
31
.iter()
32
.position(|row| *row.get_unchecked(0) == null_sentinel)?;
33
34
let mut bm = BitmapBuilder::with_capacity(rows.len());
35
bm.extend_constant(first_null, true);
36
bm.push(false);
37
38
bm.extend_trusted_len_iter(
39
rows[first_null + 1..]
40
.iter()
41
.map(|row| *row.get_unchecked(0) != null_sentinel),
42
);
43
44
bm.into_opt_validity()
45
}
46
47