MCPcopy Create free account
hub / github.com/apache/datafusion / process_map_with_nested_key

Function process_map_with_nested_key

datafusion/functions/src/core/getfield.rs:156–191  ·  view source on GitHub ↗

Process a map array with a nested key type by iterating through entries and using a comparator for key matching. This specialized version is used when the key type is nested (e.g., struct, list).

(
    array: &dyn Array,
    key_array: &dyn Array,
)

Source from the content-addressed store, hash-verified

154///
155/// This specialized version is used when the key type is nested (e.g., struct, list).
156fn process_map_with_nested_key(
157 array: &dyn Array,
158 key_array: &dyn Array,
159) -> Result<ColumnarValue> {
160 let map_array = as_map_array(array)?;
161
162 let comparator =
163 make_comparator(map_array.keys().as_ref(), key_array, SortOptions::default())?;
164
165 let original_data = map_array.entries().column(1).to_data();
166 let capacity = Capacities::Array(original_data.len());
167 let mut mutable =
168 MutableArrayData::with_capacities(vec![&original_data], true, capacity);
169
170 for entry in 0..map_array.len() {
171 let start = map_array.value_offsets()[entry] as usize;
172 let end = map_array.value_offsets()[entry + 1] as usize;
173
174 let mut found_match = false;
175 for i in start..end {
176 if comparator(i, 0).is_eq() {
177 mutable.extend(0, i, i + 1);
178 found_match = true;
179 break;
180 }
181 }
182
183 if !found_match {
184 mutable.extend_nulls(1);
185 }
186 }
187
188 let data = mutable.freeze();
189 let data = make_array(data);
190 Ok(ColumnarValue::Array(data))
191}
192
193/// Extract a single field from a struct or map array
194fn extract_single_field(base: ColumnarValue, name: ScalarValue) -> Result<ColumnarValue> {

Callers 1

extract_single_fieldFunction · 0.85

Calls 9

as_map_arrayFunction · 0.85
make_arrayFunction · 0.85
columnMethod · 0.80
value_offsetsMethod · 0.80
as_refMethod · 0.45
entriesMethod · 0.45
lenMethod · 0.45
is_eqMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…