You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/05/29 12:14:08 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request, #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

alamb opened a new pull request, #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645

   # Which issue does this PR close?
   
   
   re : https://github.com/apache/arrow-datafusion/issues/2427
   
   
    # Rationale for this change
   `SortKeyCursor::compare` is the bottleneck for merge performance (details on https://github.com/apache/arrow-datafusion/issues/2427#issuecomment-1140425072)
   
   As I prepare to improve the performance of this code (and make it more complicated),  I want it more isolated and independent so I can:
   1. Understand the code better
   2. Validate my approach
   3. Ensure I dont introduce performance 
   
   
   # What changes are included in this PR?
   1. Move `SortKeyCursor` into its own module
   2. Move `RowIndex` into its own module
   3. add `sort_key_cursor` test
   
   # Are there any user-facing changes?
   No
   
   
   # Does this PR break compatibility with Ballista?
   no


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884847337


##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors
+/// appear on the correct line.
+///
+/// Designed so that failure output can be directly copy/pasted
+/// into the test code as expected results.
+///
+/// Expects to be called about like this:
+///
+/// `assert_indexes!(expected_indexes: &[&str], indexes: &[RowIndex])`
+#[macro_export]
+macro_rules! assert_indexes {
+    ($EXPECTED_LINES: expr, $INDEXES: expr) => {
+        let expected_lines: Vec<String> =
+            $EXPECTED_LINES.iter().map(|&s| s.into()).collect();
+
+        let actual_lines = format_as_strings($INDEXES);
+
+        assert_eq!(
+            expected_lines, actual_lines,
+            "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
+            expected_lines, actual_lines
+        );
+    };
+}
+
+#[test]
+fn test_single_column() {
+    let array1 = Int64Array::from(vec![Some(1), Some(2), Some(5), Some(6)]);
+    let batch1 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array1) as _)]).unwrap();
+
+    let array2 = Int64Array::from(vec![Some(3), Some(4), Some(8), Some(9)]);
+    let batch2 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array2) as _)]).unwrap();
+
+    let c1 = col("c1", &batch1.schema()).unwrap();
+    let sort_key = vec![c1];
+
+    let sort_options = Arc::new(vec![SortOptions::default()]);
+
+    let mut cursor1 =
+        SortKeyCursor::new(1, 0, &batch1, &sort_key, Arc::clone(&sort_options)).unwrap();
+    let mut cursor2 =
+        SortKeyCursor::new(2, 0, &batch2, &sort_key, Arc::clone(&sort_options)).unwrap();
+
+    let expected = vec![

Review Comment:
   Good call, will do



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884769181


##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors
+/// appear on the correct line.
+///
+/// Designed so that failure output can be directly copy/pasted
+/// into the test code as expected results.
+///
+/// Expects to be called about like this:
+///
+/// `assert_indexes!(expected_indexes: &[&str], indexes: &[RowIndex])`
+#[macro_export]
+macro_rules! assert_indexes {
+    ($EXPECTED_LINES: expr, $INDEXES: expr) => {
+        let expected_lines: Vec<String> =
+            $EXPECTED_LINES.iter().map(|&s| s.into()).collect();
+
+        let actual_lines = format_as_strings($INDEXES);
+
+        assert_eq!(
+            expected_lines, actual_lines,
+            "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
+            expected_lines, actual_lines
+        );
+    };
+}
+
+#[test]
+fn test_single_column() {
+    let array1 = Int64Array::from(vec![Some(1), Some(2), Some(5), Some(6)]);
+    let batch1 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array1) as _)]).unwrap();
+
+    let array2 = Int64Array::from(vec![Some(3), Some(4), Some(8), Some(9)]);
+    let batch2 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array2) as _)]).unwrap();
+
+    let c1 = col("c1", &batch1.schema()).unwrap();
+    let sort_key = vec![c1];
+
+    let sort_options = Arc::new(vec![SortOptions::default()]);
+
+    let mut cursor1 =
+        SortKeyCursor::new(1, 0, &batch1, &sort_key, Arc::clone(&sort_options)).unwrap();
+    let mut cursor2 =
+        SortKeyCursor::new(2, 0, &batch2, &sort_key, Arc::clone(&sort_options)).unwrap();
+
+    let expected = vec![

Review Comment:
   If you were feeling fancy you could test stability, i.e. ties are broken by the lower stream idx



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884261456


##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,135 @@
+//! Contains tests for SortKeyCursor

Review Comment:
   These tests are new -- I plan to expand them over time



##########
datafusion/core/src/physical_plan/sorts/mod.rs:
##########
@@ -17,208 +17,16 @@
 
 //! Sort functionalities
 
-use crate::error;
-use crate::error::{DataFusionError, Result};
-use crate::physical_plan::{PhysicalExpr, SendableRecordBatchStream};
-use arrow::array::{ArrayRef, DynComparator};
-use arrow::compute::SortOptions;
-use arrow::record_batch::RecordBatch;
-use hashbrown::HashMap;
-use parking_lot::RwLock;
-use std::borrow::BorrowMut;
-use std::cmp::Ordering;
+use crate::physical_plan::SendableRecordBatchStream;
 use std::fmt::{Debug, Formatter};
-use std::sync::Arc;
 
+mod cursor;
+mod index;
 pub mod sort;
 pub mod sort_preserving_merge;
 
-/// A `SortKeyCursor` is created from a `RecordBatch`, and a set of

Review Comment:
   This code is just moved



##########
datafusion/core/src/physical_plan/sorts/index.rs:
##########
@@ -0,0 +1,42 @@
+/// A `RowIndex` identifies a specific row in a logical stream.
+///
+/// Each stream is identified by an `stream_idx` and is formed from a

Review Comment:
   This code is moved into a new module, and I added some comments / ascii art to help my future self not have to read the code the next time



##########
datafusion/core/src/physical_plan/sorts/cursor.rs:
##########
@@ -0,0 +1,203 @@
+use crate::error;
+use crate::error::{DataFusionError, Result};
+use crate::physical_plan::PhysicalExpr;
+use arrow::array::{ArrayRef, DynComparator};
+use arrow::compute::SortOptions;
+use arrow::record_batch::RecordBatch;
+use hashbrown::HashMap;
+use parking_lot::RwLock;
+use std::borrow::BorrowMut;
+use std::cmp::Ordering;
+use std::sync::Arc;
+
+/// A `SortKeyCursor` is created from a `RecordBatch`, and a set of

Review Comment:
   This code is moved, and I added `stream_id()` and `batch_idx()` accessors



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] tustvold commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884763644


##########
datafusion/core/src/physical_plan/sorts/index.rs:
##########
@@ -0,0 +1,59 @@
+// 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.
+
+/// A `RowIndex` identifies a specific row in a logical stream.
+///
+/// Each stream is identified by an `stream_idx` and is formed from a
+/// sequence of RecordBatches batches, each of which is identified by
+/// a unique `batch_idx` within that stream.
+///
+/// This is used by `SortPreservingMergeStream` to identify which
+/// the order of the tuples in the final sorted output stream.
+///
+/// ```text

Review Comment:
   This diagram seems to imply all streams must have the same number of batches, I'm not sure this is the case



##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors

Review Comment:
   I mean unwrap() will give you a stack trace... I'm not a massive fan of macros as they are hard to read, and slow to compile...



##########
datafusion/core/src/physical_plan/sorts/index.rs:
##########
@@ -0,0 +1,59 @@
+// 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.
+
+/// A `RowIndex` identifies a specific row in a logical stream.
+///
+/// Each stream is identified by an `stream_idx` and is formed from a
+/// sequence of RecordBatches batches, each of which is identified by
+/// a unique `batch_idx` within that stream.
+///
+/// This is used by `SortPreservingMergeStream` to identify which
+/// the order of the tuples in the final sorted output stream.
+///
+/// ```text
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀─────── (batch_idx = 0)
+/// │    │ │    │ │    │
+/// └────┘ └────┘ └────┘
+///
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀─────── (batch_idx = 1)
+/// │    │ │    │ │    │
+/// └────┘ └────┘ └────┘
+///
+///          ...
+///
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀────── (batch_idx = N-1)

Review Comment:
   ```suggestion
   /// │ C1 │ │... │ │ CN │◀────── (batch_idx = M-1)
   ```
   I think the dimensions are independent?



##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors
+/// appear on the correct line.
+///
+/// Designed so that failure output can be directly copy/pasted
+/// into the test code as expected results.
+///
+/// Expects to be called about like this:
+///
+/// `assert_indexes!(expected_indexes: &[&str], indexes: &[RowIndex])`
+#[macro_export]
+macro_rules! assert_indexes {
+    ($EXPECTED_LINES: expr, $INDEXES: expr) => {
+        let expected_lines: Vec<String> =
+            $EXPECTED_LINES.iter().map(|&s| s.into()).collect();
+
+        let actual_lines = format_as_strings($INDEXES);
+
+        assert_eq!(
+            expected_lines, actual_lines,
+            "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
+            expected_lines, actual_lines
+        );
+    };
+}
+
+#[test]
+fn test_single_column() {
+    let array1 = Int64Array::from(vec![Some(1), Some(2), Some(5), Some(6)]);
+    let batch1 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array1) as _)]).unwrap();
+
+    let array2 = Int64Array::from(vec![Some(3), Some(4), Some(8), Some(9)]);
+    let batch2 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array2) as _)]).unwrap();
+
+    let c1 = col("c1", &batch1.schema()).unwrap();
+    let sort_key = vec![c1];
+
+    let sort_options = Arc::new(vec![SortOptions::default()]);
+
+    let mut cursor1 =
+        SortKeyCursor::new(1, 0, &batch1, &sort_key, Arc::clone(&sort_options)).unwrap();
+    let mut cursor2 =
+        SortKeyCursor::new(2, 0, &batch2, &sort_key, Arc::clone(&sort_options)).unwrap();
+
+    let expected = vec![
+        "1: (0, 0)",
+        "1: (0, 1)",
+        "2: (0, 0)",
+        "2: (0, 1)",
+        "1: (0, 2)",
+        "1: (0, 3)",
+        "2: (0, 2)",
+        "2: (0, 3)",
+    ];
+
+    assert_indexes!(expected, run(&mut cursor1, &mut cursor2));
+}
+
+/// Runs the two cursors to completion, sorting them, and
+/// returning the sorted order of rows that would have produced
+fn run(cursor1: &mut SortKeyCursor, cursor2: &mut SortKeyCursor) -> Vec<RowIndex> {

Review Comment:
   This code doesn't seem to be being used by SortPreservingMerge, is this intentional?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884788428


##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors
+/// appear on the correct line.
+///
+/// Designed so that failure output can be directly copy/pasted
+/// into the test code as expected results.
+///
+/// Expects to be called about like this:
+///
+/// `assert_indexes!(expected_indexes: &[&str], indexes: &[RowIndex])`
+#[macro_export]
+macro_rules! assert_indexes {
+    ($EXPECTED_LINES: expr, $INDEXES: expr) => {
+        let expected_lines: Vec<String> =
+            $EXPECTED_LINES.iter().map(|&s| s.into()).collect();
+
+        let actual_lines = format_as_strings($INDEXES);
+
+        assert_eq!(
+            expected_lines, actual_lines,
+            "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
+            expected_lines, actual_lines
+        );
+    };
+}
+
+#[test]
+fn test_single_column() {
+    let array1 = Int64Array::from(vec![Some(1), Some(2), Some(5), Some(6)]);
+    let batch1 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array1) as _)]).unwrap();
+
+    let array2 = Int64Array::from(vec![Some(3), Some(4), Some(8), Some(9)]);
+    let batch2 = RecordBatch::try_from_iter(vec![("c1", Arc::new(array2) as _)]).unwrap();
+
+    let c1 = col("c1", &batch1.schema()).unwrap();
+    let sort_key = vec![c1];
+
+    let sort_options = Arc::new(vec![SortOptions::default()]);
+
+    let mut cursor1 =
+        SortKeyCursor::new(1, 0, &batch1, &sort_key, Arc::clone(&sort_options)).unwrap();
+    let mut cursor2 =
+        SortKeyCursor::new(2, 0, &batch2, &sort_key, Arc::clone(&sort_options)).unwrap();
+
+    let expected = vec![
+        "1: (0, 0)",
+        "1: (0, 1)",
+        "2: (0, 0)",
+        "2: (0, 1)",
+        "1: (0, 2)",
+        "1: (0, 3)",
+        "2: (0, 2)",
+        "2: (0, 3)",
+    ];
+
+    assert_indexes!(expected, run(&mut cursor1, &mut cursor2));
+}
+
+/// Runs the two cursors to completion, sorting them, and
+/// returning the sorted order of rows that would have produced
+fn run(cursor1: &mut SortKeyCursor, cursor2: &mut SortKeyCursor) -> Vec<RowIndex> {

Review Comment:
   At the moment, yes -- I want to unit test `SoryKeyCursor`. SortPreservingMerge already has reasonable test coverage in my mind



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884805160


##########
datafusion/core/src/physical_plan/sorts/index.rs:
##########
@@ -0,0 +1,59 @@
+// 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.
+
+/// A `RowIndex` identifies a specific row in a logical stream.
+///
+/// Each stream is identified by an `stream_idx` and is formed from a
+/// sequence of RecordBatches batches, each of which is identified by
+/// a unique `batch_idx` within that stream.
+///
+/// This is used by `SortPreservingMergeStream` to identify which
+/// the order of the tuples in the final sorted output stream.
+///
+/// ```text

Review Comment:
   that is an excellent point -- updated in 93668d2208



##########
datafusion/core/src/physical_plan/sorts/index.rs:
##########
@@ -0,0 +1,59 @@
+// 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.
+
+/// A `RowIndex` identifies a specific row in a logical stream.
+///
+/// Each stream is identified by an `stream_idx` and is formed from a
+/// sequence of RecordBatches batches, each of which is identified by
+/// a unique `batch_idx` within that stream.
+///
+/// This is used by `SortPreservingMergeStream` to identify which
+/// the order of the tuples in the final sorted output stream.
+///
+/// ```text
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀─────── (batch_idx = 0)
+/// │    │ │    │ │    │
+/// └────┘ └────┘ └────┘
+///
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀─────── (batch_idx = 1)
+/// │    │ │    │ │    │
+/// └────┘ └────┘ └────┘
+///
+///          ...
+///
+/// ┌────┐ ┌────┐ ┌────┐           RecordBatch
+/// │    │ │    │ │    │
+/// │ C1 │ │... │ │ CN │◀────── (batch_idx = N-1)

Review Comment:
   in 93668d2208 👍 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#discussion_r884845628


##########
datafusion/core/tests/sort_key_cursor.rs:
##########
@@ -0,0 +1,152 @@
+// 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.
+
+//! Contains tests for SortKeyCursor
+
+use std::{cmp::Ordering, sync::Arc};
+
+use arrow::{array::Int64Array, compute::SortOptions, record_batch::RecordBatch};
+use datafusion::physical_plan::sorts::{RowIndex, SortKeyCursor};
+use datafusion_physical_expr::expressions::col;
+
+/// Compares [`RowIndex`]es with a vector of strings, the result of
+/// pretty formatting the [`RowIndex`]es. This is a macro so errors

Review Comment:
   changed to function in 0754ee5025



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #2645: Move `SortKeyCursor` and `RowIndex` into modules, add `sort_key_cursor` test

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2645:
URL: https://github.com/apache/arrow-datafusion/pull/2645#issuecomment-1141045544

   FYI @yjshen @richox 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org