Path: blob/main/crates/polars-parquet/src/arrow/read/deserialize/null.rs
6940 views
//! This implements the [`Decoder`][utils::Decoder] trait for the `UNKNOWN` or `Null` nested type.1//! The implementation mostly stubs all the function and just keeps track of the length in the2//! `DecodedState`.34use arrow::array::NullArray;5use arrow::bitmap::{Bitmap, BitmapBuilder};6use arrow::datatypes::ArrowDataType;78use super::PredicateFilter;9use super::utils::filter::Filter;10use super::utils::{self};11use crate::parquet::error::ParquetResult;12use crate::parquet::page::{DataPage, DictPage};1314pub(crate) struct NullDecoder;15pub(crate) struct NullTranslation {16num_rows: usize,17}1819#[derive(Debug)]20pub(crate) struct NullArrayLength {21length: usize,22}2324impl utils::Decoded for NullArrayLength {25fn len(&self) -> usize {26self.length27}28fn extend_nulls(&mut self, n: usize) {29self.length += n;30}31}3233impl<'a> utils::StateTranslation<'a, NullDecoder> for NullTranslation {34type PlainDecoder = ();3536fn new(37_decoder: &NullDecoder,38page: &'a DataPage,39_dict: Option<&'a <NullDecoder as utils::Decoder>::Dict>,40_page_validity: Option<&Bitmap>,41) -> ParquetResult<Self> {42Ok(NullTranslation {43num_rows: page.num_values(),44})45}46fn num_rows(&self) -> usize {47self.num_rows48}49}5051impl utils::Decoder for NullDecoder {52type Translation<'a> = NullTranslation;53type Dict = NullArray;54type DecodedState = NullArrayLength;55type Output = NullArray;5657/// Initializes a new state58fn with_capacity(&self, _: usize) -> Self::DecodedState {59NullArrayLength { length: 0 }60}6162fn deserialize_dict(&mut self, _: DictPage) -> ParquetResult<Self::Dict> {63Ok(NullArray::new_empty(ArrowDataType::Null))64}6566fn has_predicate_specialization(67&self,68_state: &utils::State<'_, Self>,69_predicate: &PredicateFilter,70) -> ParquetResult<bool> {71// @TODO: This can be enabled for the fast paths72Ok(false)73}7475fn extend_decoded(76&self,77decoded: &mut Self::DecodedState,78additional: &dyn arrow::array::Array,79_is_optional: bool,80) -> ParquetResult<()> {81let additional = additional.as_any().downcast_ref::<NullArray>().unwrap();82decoded.length += additional.len();8384Ok(())85}8687fn finalize(88&self,89dtype: ArrowDataType,90_dict: Option<Self::Dict>,91decoded: Self::DecodedState,92) -> ParquetResult<Self::Output> {93Ok(NullArray::new(dtype, decoded.length))94}9596fn extend_filtered_with_state(97&mut self,98state: utils::State<'_, Self>,99decoded: &mut Self::DecodedState,100_pred_true_mask: &mut BitmapBuilder,101filter: Option<Filter>,102) -> ParquetResult<()> {103if matches!(filter, Some(Filter::Predicate(_))) {104todo!()105}106107let num_rows = match filter {108Some(f) => f.num_rows(0),109None => state.translation.num_rows,110};111decoded.length += num_rows;112113Ok(())114}115}116117118