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

Method try_new

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

Attempts to create a [`RunArray`] using the given `run_ends` and `values`. # Errors - If `run_ends` and `values` have different lengths - If `run_ends` has any null values - If `run_ends` doesn't consist of strictly increasing positive integers

(run_ends: &PrimitiveArray<R>, values: &dyn Array)

Source from the content-addressed store, hash-verified

116 /// - If `run_ends` has any null values
117 /// - If `run_ends` doesn't consist of strictly increasing positive integers
118 pub fn try_new(run_ends: &PrimitiveArray<R>, values: &dyn Array) -> Result<Self, ArrowError> {
119 let run_ends_type = run_ends.data_type().clone();
120 let values_type = values.data_type().clone();
121 let ree_array_type = DataType::RunEndEncoded(
122 Arc::new(Field::new("run_ends", run_ends_type, false)),
123 Arc::new(Field::new("values", values_type, true)),
124 );
125 let len = RunArray::logical_len(run_ends);
126 let builder = ArrayDataBuilder::new(ree_array_type)
127 .len(len)
128 .add_child_data(run_ends.to_data())
129 .add_child_data(values.to_data());
130
131 // `build_unchecked` is used to avoid recursive validation of child arrays.
132 let array_data = unsafe { builder.build_unchecked() };
133
134 // Safety: `validate_data` checks below
135 // 1. The given array data has exactly two child arrays.
136 // 2. The first child array (run_ends) has valid data type.
137 // 3. run_ends array does not have null values
138 // 4. run_ends array has non-zero and strictly increasing values.
139 // 5. The length of run_ends array and values array are the same.
140 array_data.validate_data()?;
141
142 Ok(array_data.into())
143 }
144
145 /// Create a new [`RunArray`] from the provided parts, without validation
146 ///

Callers

nothing calls this directly

Calls 8

RunEndEncodedClass · 0.85
add_child_dataMethod · 0.80
validate_dataMethod · 0.80
cloneMethod · 0.45
data_typeMethod · 0.45
lenMethod · 0.45
to_dataMethod · 0.45
build_uncheckedMethod · 0.45

Tested by

no test coverage detected