Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-parquet/src/arrow/read/deserialize/null.rs
8468 views
1
//! This implements the [`Decoder`][utils::Decoder] trait for the `UNKNOWN` or `Null` nested type.
2
//! The implementation mostly stubs all the function and just keeps track of the length in the
3
//! `DecodedState`.
4
5
use arrow::array::NullArray;
6
use arrow::bitmap::{Bitmap, BitmapBuilder};
7
use arrow::datatypes::ArrowDataType;
8
9
use super::utils::filter::Filter;
10
use super::utils::{self};
11
use crate::parquet::error::ParquetResult;
12
use crate::parquet::page::{DataPage, DictPage};
13
use crate::read::deserialize::utils::Decoded;
14
use crate::read::expr::{ParquetScalar, SpecializedParquetColumnExpr};
15
16
pub(crate) struct NullDecoder;
17
pub(crate) struct NullTranslation {
18
num_rows: usize,
19
}
20
21
#[derive(Debug)]
22
pub(crate) struct NullArrayLength {
23
length: usize,
24
}
25
26
impl utils::Decoded for NullArrayLength {
27
fn len(&self) -> usize {
28
self.length
29
}
30
31
fn extend_nulls(&mut self, n: usize) {
32
self.length += n;
33
}
34
35
fn remaining_capacity(&self) -> usize {
36
usize::MAX
37
}
38
}
39
40
impl<'a> utils::StateTranslation<'a, NullDecoder> for NullTranslation {
41
type PlainDecoder = ();
42
43
fn new(
44
_decoder: &NullDecoder,
45
page: &'a DataPage,
46
_dict: Option<&'a <NullDecoder as utils::Decoder>::Dict>,
47
_page_validity: Option<&Bitmap>,
48
) -> ParquetResult<Self> {
49
Ok(NullTranslation {
50
num_rows: page.num_values(),
51
})
52
}
53
fn num_rows(&self) -> usize {
54
self.num_rows
55
}
56
}
57
58
impl utils::Decoder for NullDecoder {
59
type Translation<'a> = NullTranslation;
60
type Dict = NullArray;
61
type DecodedState = NullArrayLength;
62
type Output = NullArray;
63
64
/// Initializes a new state
65
fn with_capacity(&self, _: usize) -> Self::DecodedState {
66
NullArrayLength { length: 0 }
67
}
68
69
fn deserialize_dict(&mut self, _: DictPage) -> ParquetResult<Self::Dict> {
70
Ok(NullArray::new_empty(ArrowDataType::Null))
71
}
72
73
fn evaluate_predicate(
74
&mut self,
75
_state: &utils::State<'_, Self>,
76
_predicate: Option<&SpecializedParquetColumnExpr>,
77
_pred_true_mask: &mut BitmapBuilder,
78
_dict_mask: Option<&Bitmap>,
79
) -> ParquetResult<bool> {
80
Ok(false)
81
}
82
83
fn extend_decoded(
84
&self,
85
decoded: &mut Self::DecodedState,
86
additional: &dyn arrow::array::Array,
87
_is_optional: bool,
88
) -> ParquetResult<()> {
89
let additional = additional.as_any().downcast_ref::<NullArray>().unwrap();
90
decoded.length += additional.len();
91
92
Ok(())
93
}
94
95
fn finalize(
96
&self,
97
dtype: ArrowDataType,
98
_dict: Option<Self::Dict>,
99
decoded: Self::DecodedState,
100
) -> ParquetResult<Self::Output> {
101
Ok(NullArray::new(dtype, decoded.length))
102
}
103
104
fn extend_filtered_with_state(
105
&mut self,
106
state: utils::State<'_, Self>,
107
decoded: &mut Self::DecodedState,
108
filter: Option<Filter>,
109
_chunks: &mut Vec<Self::Output>,
110
) -> ParquetResult<()> {
111
if matches!(filter, Some(Filter::Predicate(_))) {
112
todo!()
113
}
114
115
let num_rows = match filter {
116
Some(f) => f.num_rows(0),
117
None => state.translation.num_rows,
118
};
119
decoded.length += num_rows;
120
121
Ok(())
122
}
123
124
fn extend_constant(
125
&mut self,
126
decoded: &mut Self::DecodedState,
127
length: usize,
128
value: &ParquetScalar,
129
) -> ParquetResult<()> {
130
assert!(matches!(value, ParquetScalar::Null));
131
decoded.extend_nulls(length);
132
Ok(())
133
}
134
}
135
136