Path: blob/main/crates/polars-arrow/src/io/ipc/read/array/binview.rs
6940 views
use std::io::{Read, Seek};1use std::sync::Arc;23use polars_error::polars_err;45use super::super::read_basic::*;6use super::*;7use crate::array::{ArrayRef, BinaryViewArrayGeneric, View, ViewType};8use crate::buffer::Buffer;910#[allow(clippy::too_many_arguments)]11pub fn read_binview<T: ViewType + ?Sized, R: Read + Seek>(12field_nodes: &mut VecDeque<Node>,13variadic_buffer_counts: &mut VecDeque<usize>,14dtype: ArrowDataType,15buffers: &mut VecDeque<IpcBuffer>,16reader: &mut R,17block_offset: u64,18is_little_endian: bool,19compression: Option<Compression>,20limit: Option<usize>,21scratch: &mut Vec<u8>,22) -> PolarsResult<ArrayRef> {23let field_node = try_get_field_node(field_nodes, &dtype)?;2425let validity = read_validity(26buffers,27field_node,28reader,29block_offset,30is_little_endian,31compression,32limit,33scratch,34)?;3536let length = try_get_array_length(field_node, limit)?;37let views: Buffer<View> = read_buffer(38buffers,39length,40reader,41block_offset,42is_little_endian,43compression,44scratch,45)?;4647let n_variadic = variadic_buffer_counts.pop_front().ok_or_else(48|| polars_err!(ComputeError: "IPC: unable to fetch the variadic buffers\n\nThe file or stream is corrupted.")49)?;5051let variadic_buffers = (0..n_variadic)52.map(|_| {53read_bytes(54buffers,55reader,56block_offset,57is_little_endian,58compression,59scratch,60)61})62.collect::<PolarsResult<Vec<Buffer<u8>>>>()?;6364BinaryViewArrayGeneric::<T>::try_new(dtype, views, Arc::from(variadic_buffers), validity)65.map(|arr| arr.boxed())66}6768pub fn skip_binview(69field_nodes: &mut VecDeque<Node>,70buffers: &mut VecDeque<IpcBuffer>,71variadic_buffer_counts: &mut VecDeque<usize>,72) -> PolarsResult<()> {73let _ = field_nodes.pop_front().ok_or_else(|| {74polars_err!(75oos = "IPC: unable to fetch the field for utf8. The file or stream is corrupted."76)77})?;7879let _ = buffers80.pop_front()81.ok_or_else(|| polars_err!(oos = "IPC: missing validity buffer."))?;8283let _ = buffers84.pop_front()85.ok_or_else(|| polars_err!(oos = "IPC: missing views buffer."))?;8687let n_variadic = variadic_buffer_counts.pop_front().ok_or_else(88|| polars_err!(ComputeError: "IPC: unable to fetch the variadic buffers\n\nThe file or stream is corrupted.")89)?;9091for _ in 0..n_variadic {92let _ = buffers93.pop_front()94.ok_or_else(|| polars_err!(oos = "IPC: missing variadic buffer"))?;95}96Ok(())97}9899100