Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-arrow/src/io/ipc/read/array/binview.rs
6940 views
1
use std::io::{Read, Seek};
2
use std::sync::Arc;
3
4
use polars_error::polars_err;
5
6
use super::super::read_basic::*;
7
use super::*;
8
use crate::array::{ArrayRef, BinaryViewArrayGeneric, View, ViewType};
9
use crate::buffer::Buffer;
10
11
#[allow(clippy::too_many_arguments)]
12
pub fn read_binview<T: ViewType + ?Sized, R: Read + Seek>(
13
field_nodes: &mut VecDeque<Node>,
14
variadic_buffer_counts: &mut VecDeque<usize>,
15
dtype: ArrowDataType,
16
buffers: &mut VecDeque<IpcBuffer>,
17
reader: &mut R,
18
block_offset: u64,
19
is_little_endian: bool,
20
compression: Option<Compression>,
21
limit: Option<usize>,
22
scratch: &mut Vec<u8>,
23
) -> PolarsResult<ArrayRef> {
24
let field_node = try_get_field_node(field_nodes, &dtype)?;
25
26
let validity = read_validity(
27
buffers,
28
field_node,
29
reader,
30
block_offset,
31
is_little_endian,
32
compression,
33
limit,
34
scratch,
35
)?;
36
37
let length = try_get_array_length(field_node, limit)?;
38
let views: Buffer<View> = read_buffer(
39
buffers,
40
length,
41
reader,
42
block_offset,
43
is_little_endian,
44
compression,
45
scratch,
46
)?;
47
48
let n_variadic = variadic_buffer_counts.pop_front().ok_or_else(
49
|| polars_err!(ComputeError: "IPC: unable to fetch the variadic buffers\n\nThe file or stream is corrupted.")
50
)?;
51
52
let variadic_buffers = (0..n_variadic)
53
.map(|_| {
54
read_bytes(
55
buffers,
56
reader,
57
block_offset,
58
is_little_endian,
59
compression,
60
scratch,
61
)
62
})
63
.collect::<PolarsResult<Vec<Buffer<u8>>>>()?;
64
65
BinaryViewArrayGeneric::<T>::try_new(dtype, views, Arc::from(variadic_buffers), validity)
66
.map(|arr| arr.boxed())
67
}
68
69
pub fn skip_binview(
70
field_nodes: &mut VecDeque<Node>,
71
buffers: &mut VecDeque<IpcBuffer>,
72
variadic_buffer_counts: &mut VecDeque<usize>,
73
) -> PolarsResult<()> {
74
let _ = field_nodes.pop_front().ok_or_else(|| {
75
polars_err!(
76
oos = "IPC: unable to fetch the field for utf8. The file or stream is corrupted."
77
)
78
})?;
79
80
let _ = buffers
81
.pop_front()
82
.ok_or_else(|| polars_err!(oos = "IPC: missing validity buffer."))?;
83
84
let _ = buffers
85
.pop_front()
86
.ok_or_else(|| polars_err!(oos = "IPC: missing views buffer."))?;
87
88
let n_variadic = variadic_buffer_counts.pop_front().ok_or_else(
89
|| polars_err!(ComputeError: "IPC: unable to fetch the variadic buffers\n\nThe file or stream is corrupted.")
90
)?;
91
92
for _ in 0..n_variadic {
93
let _ = buffers
94
.pop_front()
95
.ok_or_else(|| polars_err!(oos = "IPC: missing variadic buffer"))?;
96
}
97
Ok(())
98
}
99
100