Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignored limit on lexsort_to_indices #2991

Merged
merged 3 commits into from Oct 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 32 additions & 7 deletions arrow/src/compute/kernels/sort.rs
Expand Up @@ -950,7 +950,7 @@ pub fn lexsort_to_indices(
});

Ok(UInt32Array::from_iter_values(
value_indices.iter().map(|i| *i as u32),
value_indices.iter().take(len).map(|i| *i as u32),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the bugfix

))
}

Expand Down Expand Up @@ -1422,6 +1422,18 @@ mod tests {
}
}

/// slace all arrays in expected_output to offset/length
alamb marked this conversation as resolved.
Show resolved Hide resolved
fn slice_arrays(
expected_output: Vec<ArrayRef>,
offset: usize,
length: usize,
) -> Vec<ArrayRef> {
expected_output
.into_iter()
.map(|array| array.slice(offset, length))
.collect()
}

fn test_sort_binary_arrays(
data: Vec<Option<Vec<u8>>>,
options: Option<SortOptions>,
Expand Down Expand Up @@ -3439,7 +3451,8 @@ mod tests {
Some(2),
Some(17),
])) as ArrayRef];
test_lex_sort_arrays(input.clone(), expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(input.clone(), slice_arrays(expected, 0, 2), Some(2));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place on master that a limit is passed to lexsort_to_indices in the tests is immediately below here. However, very sadly, there is a special case code path for single arrays that doesn't hit the bug path

        let expected = vec![Arc::new(PrimitiveArray::<Int64Type>::from(vec![
            Some(-1),
            Some(0),
            Some(2),
        ])) as ArrayRef];
        test_lex_sort_arrays(input, expected, Some(3));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition is strictly unnecessary from a coverage perspective (it was already covered), but I wanted to make the test_lex_sort_arrays based tests all consistently patterned so it was easier to reason about coverage


let expected = vec![Arc::new(PrimitiveArray::<Int64Type>::from(vec![
Some(-1),
Expand Down Expand Up @@ -3519,7 +3532,8 @@ mod tests {
Some(-2),
])) as ArrayRef,
];
test_lex_sort_arrays(input, expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(input, slice_arrays(expected, 0, 2), Some(2));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails immediately without the fix -- the output is too big!)


// test mix of string and in64 with option
let input = vec![
Expand Down Expand Up @@ -3562,7 +3576,8 @@ mod tests {
Some("7"),
])) as ArrayRef,
];
test_lex_sort_arrays(input, expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(input, slice_arrays(expected, 0, 3), Some(3));

// test sort with nulls first
let input = vec![
Expand Down Expand Up @@ -3605,7 +3620,8 @@ mod tests {
Some("world"),
])) as ArrayRef,
];
test_lex_sort_arrays(input, expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(input, slice_arrays(expected, 0, 1), Some(1));

// test sort with nulls last
let input = vec![
Expand Down Expand Up @@ -3648,7 +3664,8 @@ mod tests {
None,
])) as ArrayRef,
];
test_lex_sort_arrays(input, expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(input, slice_arrays(expected, 0, 2), Some(2));

// test sort with opposite options
let input = vec![
Expand Down Expand Up @@ -3695,7 +3712,15 @@ mod tests {
Some("foo"),
])) as ArrayRef,
];
test_lex_sort_arrays(input, expected, None);
test_lex_sort_arrays(input.clone(), expected.clone(), None);
test_lex_sort_arrays(
input.clone(),
slice_arrays(expected.clone(), 0, 5),
Some(5),
);

// Limiting by more rows than present should is ok
test_lex_sort_arrays(input, slice_arrays(expected, 0, 5), Some(10));
}

#[test]
Expand Down