yjshen commented on a change in pull request #1526: URL: https://github.com/apache/arrow-datafusion/pull/1526#discussion_r782692980
########## File path: datafusion/src/physical_plan/sorts/in_mem_sort.rs ########## @@ -0,0 +1,241 @@ +// 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. + +use std::collections::BinaryHeap; +use std::pin::Pin; +use std::sync::Arc; +use std::task::{Context, Poll}; + +use arrow::{ + array::{make_array as make_arrow_array, MutableArrayData}, + compute::SortOptions, + datatypes::SchemaRef, + error::{ArrowError, Result as ArrowResult}, + record_batch::RecordBatch, +}; +use futures::Stream; + +use crate::error::Result; +use crate::physical_plan::metrics::BaselineMetrics; +use crate::physical_plan::sorts::{RowIndex, SortKeyCursor}; +use crate::physical_plan::{ + expressions::PhysicalSortExpr, PhysicalExpr, RecordBatchStream, +}; + +/// Merge buffered, self-sorted record batches to get an order. +/// +/// Internally, it uses MinHeap to reduce extra memory consumption +/// by not concatenating all batches into one and sorting it as done by `SortExec`. Review comment: The main difference between `InMemSortStream` and `SortPreservingMergeStream` lies in assuming different numbers of "entity" (batches for IMSS and streams for SPMS) merged. Since `InMemSort` means to merge much more partially ordered "entities", the sorter should reduce the num of comparison for each item pop-up. Hence a MinHeap was introduced. On the other hand, `InMemSort` is more specialized to have each "entity" only one record batch, therefore simplified logic compared to consider stream continuation in `SortPreservingMergeStream`. Currently, the common parts `SortKeyCursor` and `RowIndex` for both sorts are extracted to `sorts/mod.rs` reduce duplication. -- 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]
