Path: blob/main/crates/polars-plan/src/dsl/file_scan/deletion.rs
6940 views
use std::sync::Arc;12use polars_core::prelude::PlIndexMap;34// Note, there are a lot of single variant enums here, but the intention is that we'll support5// Delta deletion vectors as well at some point in the future.67#[derive(Debug, Clone, Eq, PartialEq)]8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]9#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]10pub enum DeletionFilesList {11// Chose to use a hashmap keyed by the scan source index.12// * There may be data files without deletion files.13// * A single data file may have multiple associated deletion files.14//15// Note that this uses `PlIndexMap` instead of `PlHashMap` for schemars compatibility.16//17// Other possible options:18// * ListArray(inner: Utf8Array)19//20/// Iceberg positional deletes21IcebergPositionDelete(Arc<PlIndexMap<usize, Arc<[String]>>>),22}2324impl DeletionFilesList {25/// Converts `Some(v)` to `None` if `v` is empty.26pub fn filter_empty(this: Option<Self>) -> Option<Self> {27use DeletionFilesList::*;2829match this {30Some(IcebergPositionDelete(paths)) => {31(!paths.is_empty()).then_some(IcebergPositionDelete(paths))32},33None => None,34}35}3637pub fn num_files_with_deletions(&self) -> usize {38use DeletionFilesList::*;3940match self {41IcebergPositionDelete(paths) => paths.len(),42}43}44}4546impl std::hash::Hash for DeletionFilesList {47fn hash<H: std::hash::Hasher>(&self, state: &mut H) {48use DeletionFilesList::*;4950std::mem::discriminant(self).hash(state);5152match self {53IcebergPositionDelete(paths) => {54let addr = paths55.first()56.map_or(0, |(_, paths)| Arc::as_ptr(paths) as *const () as usize);5758addr.hash(state)59},60}61}62}6364impl std::fmt::Display for DeletionFilesList {65fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {66use DeletionFilesList::*;6768match self {69IcebergPositionDelete(paths) => {70let s = if paths.len() == 1 { "" } else { "s" };71write!(f, "iceberg-position-delete: {} source{s}", paths.len())?;72},73}7475Ok(())76}77}787980