Jimexist commented on a change in pull request #424: URL: https://github.com/apache/arrow-rs/pull/424#discussion_r647891165
########## File path: arrow/src/compute/kernels/partition.rs ########## @@ -0,0 +1,314 @@ +// 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. + +//! Defines partition kernel for `ArrayRef` + +use crate::compute::kernels::sort::LexicographicalComparator; +use crate::compute::SortColumn; +use crate::error::{ArrowError, Result}; +use std::cmp::Ordering; +use std::ops::Range; + +/// Given a list of already sorted columns, find partition ranges that would partition +/// lexicographically equal values across columns. +/// +/// Here LexicographicalComparator is used in conjunction with binary +/// search so the columns *MUST* be pre-sorted already. +/// +/// The returned vec would be of size k where k is cardinality of the sorted values; Consecutive +/// values will be connected: (a, b) and (b, c), where start = 0 and end = n for the first and last +/// range. +pub fn lexicographical_partition_ranges( + columns: &[SortColumn], +) -> Result<Vec<Range<usize>>> { + let partition_points = lexicographical_partition_points(columns)?; + Ok(partition_points + .iter() + .zip(partition_points[1..].iter()) + .map(|(&start, &end)| Range { start, end }) + .collect()) +} + +/// Given a list of already sorted columns, find partition ranges that would partition +/// lexicographically equal values across columns. +/// +/// Here LexicographicalComparator is used in conjunction with binary +/// search so the columns *MUST* be pre-sorted already. +/// +/// The returned vec would be of size k+1 where k is cardinality of the sorted values; the first and +/// last value would be 0 and n. +fn lexicographical_partition_points(columns: &[SortColumn]) -> Result<Vec<usize>> { Review comment: tracked in https://github.com/apache/arrow-rs/issues/437 -- 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. For queries about this service, please contact Infrastructure at: [email protected]
