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

Function compare_rows

datafusion/common/src/utils/mod.rs:119–145  ·  view source on GitHub ↗

This function compares two tuples depending on the given sort options.

(
    x: &[ScalarValue],
    y: &[ScalarValue],
    sort_options: &[SortOptions],
)

Source from the content-addressed store, hash-verified

117
118/// This function compares two tuples depending on the given sort options.
119pub fn compare_rows(
120 x: &[ScalarValue],
121 y: &[ScalarValue],
122 sort_options: &[SortOptions],
123) -> Result<Ordering> {
124 let zip_it = x.iter().zip(y.iter()).zip(sort_options.iter());
125 // Preserving lexical ordering.
126 for ((lhs, rhs), sort_options) in zip_it {
127 // Consider all combinations of NULLS FIRST/LAST and ASC/DESC configurations.
128 let result = match (lhs.is_null(), rhs.is_null(), sort_options.nulls_first) {
129 (true, false, false) | (false, true, true) => Ordering::Greater,
130 (true, false, true) | (false, true, false) => Ordering::Less,
131 (false, false, _) => {
132 if sort_options.descending {
133 rhs.try_cmp(lhs)?
134 } else {
135 lhs.try_cmp(rhs)?
136 }
137 }
138 (true, true, _) => continue,
139 };
140 if result != Ordering::Equal {
141 return Ok(result);
142 }
143 }
144 Ok(Ordering::Equal)
145}
146
147/// This function searches for a tuple of given values (`target`) among the given
148/// rows (`item_columns`) using the bisection algorithm. It assumes that `item_columns`

Callers 12

is_row_aheadFunction · 0.85
updated_sort_keyMethod · 0.85
orderingMethod · 0.85
bisectFunction · 0.85
linear_searchFunction · 0.85
sortMethod · 0.85
should_update_stateMethod · 0.85
update_batchMethod · 0.85
merge_batchMethod · 0.85

Calls 3

try_cmpMethod · 0.80
iterMethod · 0.45
is_nullMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…