alamb opened a new issue #563:
URL: https://github.com/apache/arrow-rs/issues/563


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   
   In DataFusion we are working on a Merge operator that needs to compare 
multiple sorted streams of record batches, merge them together, and produce a 
single sorted output stream (see more context in 
https://github.com/apache/arrow-datafusion/pull/722)
   
   The current interface for comparing arrays in Arrow is getting a 
[`DynComparator`](https://github.com/apache/arrow-rs/blob/f873d77bc77847b95921374aa66ba1d38e9cebf8/arrow/src/array/ord.rs#L30)
   
   Which is a function that you give two indexes and get the result. You 
effectively have to do
   ```rust
   let cmp = build_compare(array1, array2);
   ... 
   if cmp(index1, index2) == OrderingEqual:: {
   
   }
   ```
   
   This has two problems for the merge operator:
   1. it has to keep track of different comparators for each pairs of arrays 
that are used
   2. (unobviously) by memoizing the comparators it will prevent the underlying 
array memory from being freed (as each comparator has a reference to the 
underlying array data)
   
   **Describe the solution you'd like**
   
   I would ideally like a comparator that does not have the array bound and 
instead was passed array indexes. Something like
   
   ```rust
   let cmp = build_compare(array1.data_type(), array2.data_type());
   ... 
   if cmp(&array1, index1, &array2, index2) == OrderingEqual:: {
   
   }
   ```
   
   We can probably also keep the existing interface 
   
   **Describe alternatives you've considered**
   None
   
   **Additional context**
   See discussion with @Dandandan  and @e-dard  here: 
https://github.com/apache/arrow-datafusion/pull/722#discussion_r671825464
   


-- 
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]


Reply via email to