Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-plan/src/dsl/file_scan/deletion.rs
6940 views
1
use std::sync::Arc;
2
3
use polars_core::prelude::PlIndexMap;
4
5
// Note, there are a lot of single variant enums here, but the intention is that we'll support
6
// Delta deletion vectors as well at some point in the future.
7
8
#[derive(Debug, Clone, Eq, PartialEq)]
9
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10
#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]
11
pub enum DeletionFilesList {
12
// Chose to use a hashmap keyed by the scan source index.
13
// * There may be data files without deletion files.
14
// * A single data file may have multiple associated deletion files.
15
//
16
// Note that this uses `PlIndexMap` instead of `PlHashMap` for schemars compatibility.
17
//
18
// Other possible options:
19
// * ListArray(inner: Utf8Array)
20
//
21
/// Iceberg positional deletes
22
IcebergPositionDelete(Arc<PlIndexMap<usize, Arc<[String]>>>),
23
}
24
25
impl DeletionFilesList {
26
/// Converts `Some(v)` to `None` if `v` is empty.
27
pub fn filter_empty(this: Option<Self>) -> Option<Self> {
28
use DeletionFilesList::*;
29
30
match this {
31
Some(IcebergPositionDelete(paths)) => {
32
(!paths.is_empty()).then_some(IcebergPositionDelete(paths))
33
},
34
None => None,
35
}
36
}
37
38
pub fn num_files_with_deletions(&self) -> usize {
39
use DeletionFilesList::*;
40
41
match self {
42
IcebergPositionDelete(paths) => paths.len(),
43
}
44
}
45
}
46
47
impl std::hash::Hash for DeletionFilesList {
48
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
49
use DeletionFilesList::*;
50
51
std::mem::discriminant(self).hash(state);
52
53
match self {
54
IcebergPositionDelete(paths) => {
55
let addr = paths
56
.first()
57
.map_or(0, |(_, paths)| Arc::as_ptr(paths) as *const () as usize);
58
59
addr.hash(state)
60
},
61
}
62
}
63
}
64
65
impl std::fmt::Display for DeletionFilesList {
66
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67
use DeletionFilesList::*;
68
69
match self {
70
IcebergPositionDelete(paths) => {
71
let s = if paths.len() == 1 { "" } else { "s" };
72
write!(f, "iceberg-position-delete: {} source{s}", paths.len())?;
73
},
74
}
75
76
Ok(())
77
}
78
}
79
80