Rich-T-kid commented on code in PR #10325: URL: https://github.com/apache/arrow-rs/pull/10325#discussion_r3564873162
########## arrow-cmp/src/lib.rs: ########## @@ -0,0 +1,1889 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Basic comparator factories shared by Arrow crates that need to compare +//! arbitrary array slots without pulling in the full `arrow-ord` crate. +//! +//! The only public surface is [`make_comparator`] (with [`DynComparator`] as the +//! returned function type). `arrow-ord` re-exports both from here, so its +//! public API is unchanged. +//! +//! This crate exists so that crates such as `arrow-select` can use slot-wise +//! comparison (e.g. for the run-end-encoded `take` fast path) without taking on +//! the full ordering kernel suite — which would either create a circular +//! dependency (`arrow-ord` already depends on `arrow-select`) or force every +//! downstream user of `arrow-array` to compile the comparator machinery whether Review Comment: can remove these comemnts ########## arrow-select/src/take.rs: ########## @@ -2915,4 +2926,74 @@ mod tests { assert_eq!(run_result.run_ends().len(), 0); assert_eq!(run_result.values().len(), 0); } + + #[test] + fn test_take_run_end_encoded_merges_identical_runs() { + // https://github.com/apache/arrow-rs/issues/7710 + // Indices [0,1,4,5] select from [1,1,0,0,1,1] — the 0s are skipped, + // so the output should be a single run of 1s, not two. + let mut builder = PrimitiveRunBuilder::<Int32Type, Int32Type>::new(); + builder.extend([1, 1, 0, 0, 1, 1].into_iter().map(Some)); + let ree = builder.finish(); + + let indexes = Int32Array::from_iter_values(vec![0, 1, 4, 5]); + let result = take(&ree, &indexes, None).unwrap(); + let result = result + .as_run::<Int32Type>() + .downcast::<Int32Array>() + .unwrap(); + + let actual = result.into_iter().flatten().collect::<Vec<_>>(); + assert_eq!(actual, vec![1, 1, 1, 1]); + } + + #[test] + fn test_take_run_end_encoded_merges_identical_string_runs() { + let mut builder = StringRunBuilder::<Int32Type>::new(); + builder.extend( + ["bob", "bob", "alice", "alice", "bob", "bob"] + .into_iter() + .map(Some), + ); + let ree = builder.finish(); + + let indexes = Int32Array::from_iter_values(vec![0, 1, 4, 5]); + let result = take(&ree, &indexes, None).unwrap(); + let result = result + .as_run::<Int32Type>() + .downcast::<StringArray>() + .unwrap(); + + let actual = result.into_iter().flatten().collect::<Vec<_>>(); + assert_eq!(actual, vec!["bob", "bob", "bob", "bob"]); + } + + #[test] + fn test_take_run_end_encoded_mixed_runs() { + // Validates that runs are merged whether the same logical value comes + // from the same physical index (repeated indices) or distinct physical indices. + let mut builder = StringRunBuilder::<Int32Type>::new(); + builder.extend( + ["bob", "bob", "alice", "alice", "bob", "bob", "eve", "eve"] + .into_iter() + .map(Some), + ); Review Comment: nit: its more readable to have `Some(str)` directly ########## arrow-select/src/take.rs: ########## @@ -2915,4 +2926,74 @@ mod tests { assert_eq!(run_result.run_ends().len(), 0); assert_eq!(run_result.values().len(), 0); } + + #[test] + fn test_take_run_end_encoded_merges_identical_runs() { + // https://github.com/apache/arrow-rs/issues/7710 Review Comment: we can remove the link to the issue. once this is merged it will be the default behavior -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
