Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-parquet/src/parquet/mod.rs
6940 views
1
#[macro_use]
2
pub mod error;
3
#[cfg(feature = "bloom_filter")]
4
pub mod bloom_filter;
5
pub mod compression;
6
pub mod encoding;
7
pub mod metadata;
8
pub mod page;
9
mod parquet_bridge;
10
pub mod read;
11
pub mod schema;
12
pub mod statistics;
13
pub mod types;
14
pub mod write;
15
16
use std::ops::Deref;
17
18
use polars_parquet_format as thrift_format;
19
use polars_utils::mmap::MemSlice;
20
pub use streaming_decompression::{FallibleStreamingIterator, fallible_streaming_iterator};
21
22
pub const HEADER_SIZE: u64 = PARQUET_MAGIC.len() as u64;
23
pub const FOOTER_SIZE: u64 = 8;
24
pub const PARQUET_MAGIC: [u8; 4] = [b'P', b'A', b'R', b'1'];
25
26
/// The number of bytes read at the end of the parquet file on first read
27
const DEFAULT_FOOTER_READ_SIZE: u64 = 64 * 1024;
28
29
/// A copy-on-write buffer over bytes
30
#[derive(Debug, Clone)]
31
pub enum CowBuffer {
32
Borrowed(MemSlice),
33
Owned(Vec<u8>),
34
}
35
36
impl Deref for CowBuffer {
37
type Target = [u8];
38
39
#[inline(always)]
40
fn deref(&self) -> &Self::Target {
41
match self {
42
CowBuffer::Borrowed(v) => v.deref(),
43
CowBuffer::Owned(v) => v.deref(),
44
}
45
}
46
}
47
48
impl CowBuffer {
49
pub fn to_mut(&mut self) -> &mut Vec<u8> {
50
match self {
51
CowBuffer::Borrowed(v) => {
52
*self = Self::Owned(v.clone().to_vec());
53
self.to_mut()
54
},
55
CowBuffer::Owned(v) => v,
56
}
57
}
58
59
pub fn into_vec(self) -> Vec<u8> {
60
match self {
61
CowBuffer::Borrowed(v) => v.to_vec(),
62
CowBuffer::Owned(v) => v,
63
}
64
}
65
}
66
67