This function compares two tuples depending on the given sort options.
(
x: &[ScalarValue],
y: &[ScalarValue],
sort_options: &[SortOptions],
)
| 117 | |
| 118 | /// This function compares two tuples depending on the given sort options. |
| 119 | pub 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` |
searching dependent graphs…