MCPcopy Create free account
hub / github.com/apache/arrow-rs / try_new

Method try_new

arrow-array/src/array/byte_array.rs:128–155  ·  view source on GitHub ↗

Create a new [`GenericByteArray`] from the provided parts, returning an error on failure # Errors `offsets.len() - 1 != nulls.len()` Any consecutive pair of `offsets` does not denote a valid slice of `values`

(
        offsets: OffsetBuffer<T::Offset>,
        values: Buffer,
        nulls: Option<NullBuffer>,
    )

Source from the content-addressed store, hash-verified

126 /// * `offsets.len() - 1 != nulls.len()`
127 /// * Any consecutive pair of `offsets` does not denote a valid slice of `values`
128 pub fn try_new(
129 offsets: OffsetBuffer<T::Offset>,
130 values: Buffer,
131 nulls: Option<NullBuffer>,
132 ) -> Result<Self, ArrowError> {
133 let len = offsets.len() - 1;
134
135 // Verify that each pair of offsets is a valid slices of values
136 T::validate(&offsets, &values)?;
137
138 if let Some(n) = nulls.as_ref() {
139 if n.len() != len {
140 return Err(ArrowError::InvalidArgumentError(format!(
141 "Incorrect length of null buffer for {}{}Array, expected {len} got {}",
142 T::Offset::PREFIX,
143 T::PREFIX,
144 n.len(),
145 )));
146 }
147 }
148
149 Ok(Self {
150 data_type: T::DATA_TYPE,
151 value_offsets: offsets,
152 value_data: values,
153 nulls,
154 })
155 }
156
157 /// Create a new [`GenericByteArray`] from the provided parts, without validation
158 ///

Callers

nothing calls this directly

Calls 3

validateFunction · 0.85
lenMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected