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

Method with_values

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

Returns a new [`RunArray`] with the same `run_ends` and the supplied `values`. # Panics Panics if `values.len()` does not equal `self.values().len()`. # Example ``` # use std::sync::Arc; # use arrow_array::{RunArray, Int32Array, StringArray, ArrayRef,Array}; # use arrow_array::types::Int32Type; // A RunArray logically representing ["a", "a", "b", "c", "c"] let run_ends = Int32Array::from(vec![

(&self, values: ArrayRef)

Source from the content-addressed store, hash-verified

245 /// assert_eq!(new_run_array.run_ends().values(), &[2, 3, 5]);
246 /// ```
247 pub fn with_values(&self, values: ArrayRef) -> Self {
248 assert_eq!(values.len(), self.values.len());
249 let (run_ends_field, values_field) = match &self.data_type {
250 DataType::RunEndEncoded(r, v) => {
251 let new_v = Arc::new(Field::new(
252 v.name(),
253 values.data_type().clone(),
254 v.is_nullable(),
255 ));
256 (r, new_v)
257 }
258 _ => unreachable!("RunArray should have type RunEndEncoded"),
259 };
260 let data_type = DataType::RunEndEncoded(Arc::clone(run_ends_field), values_field);
261
262 Self {
263 data_type,
264 run_ends: self.run_ends.clone(),
265 values,
266 }
267 }
268
269 /// Similar to [`values`] but accounts for logical slicing, returning only the values
270 /// that are part of the logical slice of this array.

Callers 5

test_timezoneFunction · 0.45
lengthFunction · 0.45
bit_lengthFunction · 0.45

Calls 5

RunEndEncodedClass · 0.85
nameMethod · 0.45
cloneMethod · 0.45
data_typeMethod · 0.45
is_nullableMethod · 0.45

Tested by 2

test_timezoneFunction · 0.36