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

Method new_unchecked

arrow-array/src/array/run_array.rs:150–202  ·  view source on GitHub ↗

Create a new [`RunArray`] from the provided parts, without validation # Safety Safe if [`Self::try_new`] would not error

(
        data_type: DataType,
        run_ends: RunEndBuffer<R::Native>,
        values: ArrayRef,
    )

Source from the content-addressed store, hash-verified

148 ///
149 /// Safe if [`Self::try_new`] would not error
150 pub unsafe fn new_unchecked(
151 data_type: DataType,
152 run_ends: RunEndBuffer<R::Native>,
153 values: ArrayRef,
154 ) -> Self {
155 if cfg!(feature = "force_validate") {
156 match &data_type {
157 DataType::RunEndEncoded(run_ends, values_field) => {
158 assert!(!run_ends.is_nullable(), "run_ends should not be nullable");
159 assert_eq!(
160 run_ends.data_type(),
161 &R::DATA_TYPE,
162 "Incorrect run ends type"
163 );
164 assert_eq!(
165 values_field.data_type(),
166 values.data_type(),
167 "Incorrect values type"
168 );
169 }
170 _ => {
171 panic!(
172 "Invalid data type {data_type:?} for RunArray. Should be DataType::RunEndEncoded"
173 );
174 }
175 }
176
177 let run_array = Self {
178 data_type,
179 run_ends,
180 values,
181 };
182
183 // Safety: `validate_data` checks below
184 // 1. The given array data has exactly two child arrays.
185 // 2. The first child array (run_ends) has valid data type.
186 // 3. run_ends array does not have null values
187 // 4. run_ends array has non-zero and strictly increasing values.
188 // 5. The length of run_ends array and values array are the same.
189 run_array
190 .to_data()
191 .validate_data()
192 .expect("RunArray data should be valid");
193
194 return run_array;
195 }
196
197 Self {
198 data_type,
199 run_ends,
200 values,
201 }
202 }
203
204 /// Deconstruct this array into its constituent parts
205 pub fn into_parts(self) -> (DataType, RunEndBuffer<R::Native>, ArrayRef) {

Callers

nothing calls this directly

Calls 2

validate_dataMethod · 0.80
to_dataMethod · 0.45

Tested by

no test coverage detected