Skip to main content

polars_core/chunked_array/
binary_offset.rs

1use polars_error::PolarsResult;
2use polars_row::{RowEncodingOptions, RowEncodingOutput};
3
4use crate::prelude::{BinaryOffsetChunked, DataType, Field, IntoSeries};
5
6#[cfg(feature = "dtype-struct")]
7impl BinaryOffsetChunked {
8    pub fn row_decode_ordered(
9        &self,
10        fields: &[Field],
11        descending: &[bool],
12        nulls_last: &[bool],
13    ) -> PolarsResult<super::StructChunked> {
14        assert_eq!(fields.len(), descending.len());
15        assert_eq!(fields.len(), nulls_last.len());
16
17        use super::ops::row_encode::ordered_opts;
18
19        self.row_decode(fields, &ordered_opts(descending, nulls_last))
20    }
21
22    pub fn row_decode_unordered(&self, fields: &[Field]) -> PolarsResult<super::StructChunked> {
23        let mut opts = Vec::with_capacity(fields.len());
24        opts.extend(std::iter::repeat_n(
25            RowEncodingOptions::new_unsorted(),
26            fields.len(),
27        ));
28        self.row_decode(fields, &opts)
29    }
30
31    fn row_decode(
32        &self,
33        fields: &[Field],
34        opts: &[RowEncodingOptions],
35    ) -> PolarsResult<super::StructChunked> {
36        use super::ops::row_encode::{get_row_encoding_layout, row_encoding_decode};
37
38        let dtypes: Vec<DataType> = fields.iter().map(|f| f.dtype().clone()).collect();
39        let layout = get_row_encoding_layout(&dtypes, opts, RowEncodingOutput::AlwaysBinaryOffset);
40        row_encoding_decode(&self.clone().into_series(), fields, &layout)
41    }
42}