Skip to content

Commit

Permalink
build_compare for non-nested
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 committed Feb 19, 2024
1 parent 119e23d commit 76d960f
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions arrow-ord/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use arrow_schema::{ArrowError, DataType};
use arrow_select::take::take;
use std::ops::Not;

use crate::ord::{build_compare, DynComparator};

#[derive(Debug, Copy, Clone)]
enum Op {
Equal,
Expand Down Expand Up @@ -185,35 +187,55 @@ fn process_nested(
for i in 0..l.len() {
let l = l.value(i);
let r = r.value(i);

// Since `compare_op` does not support inconsistent lengths, we compare the
// prefix with `compare_op` only, and compare the left if the prefix is equal
let l_t = l.data_type();
let r_t = r.data_type();
let l_len = l.len();
let r_len = r.len();
let min_len = std::cmp::min(l_len, r_len);
let l = l.slice(0, min_len);
let r = r.slice(0, min_len);

let lt_res = lt(&l, &r)?;
let eq_res = eq(&l, &r)?;

fn post_process(
lt: &BooleanArray,
eq: &BooleanArray,
r_is_longer: bool,
) -> bool {
for j in 0..lt.len() {
if lt.value(j) {
return true;
if !l_t.is_nested() && !r_t.is_nested() {
let cmp = build_compare(&l, &r)?;

fn post_process(len: usize, cmp: DynComparator, r_is_longer: bool) -> bool {
for j in 0..len {
let ord = cmp(j, j);
if ord == std::cmp::Ordering::Less {
return true;
}
if ord == std::cmp::Ordering::Greater {
return false;
}
}
if !eq.value(j) {
return false;
r_is_longer
}
values.append_value(post_process(min_len, cmp, r_len > l_len));
} else {
// Since `compare_op` does not support inconsistent lengths, we compare the
// prefix with `compare_op` only, and compare the left if the prefix is equal
let l = l.slice(0, min_len);
let r = r.slice(0, min_len);

let lt_res = lt(&l, &r)?;
let eq_res = eq(&l, &r)?;

fn post_process(
lt: &BooleanArray,
eq: &BooleanArray,
r_is_longer: bool,
) -> bool {
for j in 0..lt.len() {
if lt.value(j) {
return true;
}
if !eq.value(j) {
return false;
}
}
r_is_longer
}
r_is_longer
}

values.append_value(post_process(&lt_res, &eq_res, r_len > l_len));
values.append_value(post_process(&lt_res, &eq_res, r_len > l_len));
}
}

let values = values.finish();
Expand Down

0 comments on commit 76d960f

Please sign in to comment.