Path: blob/main/crates/polars-parquet/src/parquet/metadata/column_descriptor.rs
6940 views
use std::ops::Deref;1use std::sync::Arc;23use polars_utils::pl_str::PlSmallStr;4#[cfg(feature = "serde")]5use serde::{Deserialize, Serialize};67use crate::parquet::schema::types::{ParquetType, PrimitiveType};89/// A descriptor of a parquet column. It contains the necessary information to deserialize10/// a parquet column.11#[derive(Debug, Clone, PartialEq, Eq, Hash)]12#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]13pub struct Descriptor {14/// The [`PrimitiveType`] of this column15pub primitive_type: PrimitiveType,1617/// The maximum definition level18pub max_def_level: i16,1920/// The maximum repetition level21pub max_rep_level: i16,22}2324#[derive(Debug, Clone)]25#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]26pub enum BaseType {27Owned(ParquetType),28Arc(Arc<ParquetType>),29}3031impl BaseType {32pub fn into_arc(self) -> Self {33match self {34BaseType::Owned(t) => Self::Arc(Arc::new(t)),35BaseType::Arc(t) => Self::Arc(t),36}37}38}3940impl PartialEq for BaseType {41fn eq(&self, other: &Self) -> bool {42self.deref() == other.deref()43}44}4546impl Deref for BaseType {47type Target = ParquetType;4849fn deref(&self) -> &Self::Target {50match self {51BaseType::Owned(i) => i,52BaseType::Arc(i) => i.as_ref(),53}54}55}5657/// A descriptor for leaf-level primitive columns.58/// This encapsulates information such as definition and repetition levels and is used to59/// re-assemble nested data.60#[derive(Debug, PartialEq, Clone)]61#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]62pub struct ColumnDescriptor {63/// The descriptor this columns' leaf.64pub descriptor: Descriptor,6566/// The path of this column. For instance, "a.b.c.d".67pub path_in_schema: Vec<PlSmallStr>,6869/// The [`ParquetType`] this descriptor is a leaf of70pub base_type: BaseType,71}7273impl ColumnDescriptor {74/// Creates new descriptor for leaf-level column.75pub fn new(76descriptor: Descriptor,77path_in_schema: Vec<PlSmallStr>,78base_type: BaseType,79) -> Self {80Self {81descriptor,82path_in_schema,83base_type,84}85}86}878889