Path: blob/main/crates/polars-parquet/src/arrow/read/deserialize/null.rs
8468 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::utils::filter::Filter;9use super::utils::{self};10use crate::parquet::error::ParquetResult;11use crate::parquet::page::{DataPage, DictPage};12use crate::read::deserialize::utils::Decoded;13use crate::read::expr::{ParquetScalar, SpecializedParquetColumnExpr};1415pub(crate) struct NullDecoder;16pub(crate) struct NullTranslation {17num_rows: usize,18}1920#[derive(Debug)]21pub(crate) struct NullArrayLength {22length: usize,23}2425impl utils::Decoded for NullArrayLength {26fn len(&self) -> usize {27self.length28}2930fn extend_nulls(&mut self, n: usize) {31self.length += n;32}3334fn remaining_capacity(&self) -> usize {35usize::MAX36}37}3839impl<'a> utils::StateTranslation<'a, NullDecoder> for NullTranslation {40type PlainDecoder = ();4142fn new(43_decoder: &NullDecoder,44page: &'a DataPage,45_dict: Option<&'a <NullDecoder as utils::Decoder>::Dict>,46_page_validity: Option<&Bitmap>,47) -> ParquetResult<Self> {48Ok(NullTranslation {49num_rows: page.num_values(),50})51}52fn num_rows(&self) -> usize {53self.num_rows54}55}5657impl utils::Decoder for NullDecoder {58type Translation<'a> = NullTranslation;59type Dict = NullArray;60type DecodedState = NullArrayLength;61type Output = NullArray;6263/// Initializes a new state64fn with_capacity(&self, _: usize) -> Self::DecodedState {65NullArrayLength { length: 0 }66}6768fn deserialize_dict(&mut self, _: DictPage) -> ParquetResult<Self::Dict> {69Ok(NullArray::new_empty(ArrowDataType::Null))70}7172fn evaluate_predicate(73&mut self,74_state: &utils::State<'_, Self>,75_predicate: Option<&SpecializedParquetColumnExpr>,76_pred_true_mask: &mut BitmapBuilder,77_dict_mask: Option<&Bitmap>,78) -> ParquetResult<bool> {79Ok(false)80}8182fn extend_decoded(83&self,84decoded: &mut Self::DecodedState,85additional: &dyn arrow::array::Array,86_is_optional: bool,87) -> ParquetResult<()> {88let additional = additional.as_any().downcast_ref::<NullArray>().unwrap();89decoded.length += additional.len();9091Ok(())92}9394fn finalize(95&self,96dtype: ArrowDataType,97_dict: Option<Self::Dict>,98decoded: Self::DecodedState,99) -> ParquetResult<Self::Output> {100Ok(NullArray::new(dtype, decoded.length))101}102103fn extend_filtered_with_state(104&mut self,105state: utils::State<'_, Self>,106decoded: &mut Self::DecodedState,107filter: Option<Filter>,108_chunks: &mut Vec<Self::Output>,109) -> ParquetResult<()> {110if matches!(filter, Some(Filter::Predicate(_))) {111todo!()112}113114let num_rows = match filter {115Some(f) => f.num_rows(0),116None => state.translation.num_rows,117};118decoded.length += num_rows;119120Ok(())121}122123fn extend_constant(124&mut self,125decoded: &mut Self::DecodedState,126length: usize,127value: &ParquetScalar,128) -> ParquetResult<()> {129assert!(matches!(value, ParquetScalar::Null));130decoded.extend_nulls(length);131Ok(())132}133}134135136