diff --git a/datafusion/physical-plan/src/sorts/sort.rs b/datafusion/physical-plan/src/sorts/sort.rs index 9f7bd6b28a2e..e9f17ddebabc 100644 --- a/datafusion/physical-plan/src/sorts/sort.rs +++ b/datafusion/physical-plan/src/sorts/sort.rs @@ -203,39 +203,54 @@ impl ExternalSorterMetrics { /// in_mem_batches /// ``` struct ExternalSorter { - /// schema of the output (and the input) + // ======================================================================== + // PROPERTIES: + // Fields that define the sorter's configuration and remain constant + // ======================================================================== + /// Schema of the output (and the input) schema: SchemaRef, + /// Sort expressions + expr: Arc<[PhysicalSortExpr]>, + /// If Some, the maximum number of output rows that will be produced + fetch: Option, + /// The target number of rows for output batches + batch_size: usize, + /// If the in size of buffered memory batches is below this size, + /// the data will be concatenated and sorted in place rather than + /// sort/merged. + sort_in_place_threshold_bytes: usize, + + // ======================================================================== + // STATE BUFFERS: + // Fields that hold intermediate data during sorting + // ======================================================================== /// Potentially unsorted in memory buffer in_mem_batches: Vec, /// if `Self::in_mem_batches` are sorted in_mem_batches_sorted: bool, + /// If data has previously been spilled, the locations of the /// spill files (in Arrow IPC format) spills: Vec, - /// Sort expressions - expr: Arc<[PhysicalSortExpr]>, + + // ======================================================================== + // EXECUTION RESOURCES: + // Fields related to managing execution resources and monitoring performance. + // ======================================================================== /// Runtime metrics metrics: ExternalSorterMetrics, - /// If Some, the maximum number of output rows that will be - /// produced. - fetch: Option, + /// A handle to the runtime to get spill files + runtime: Arc, /// Reservation for in_mem_batches reservation: MemoryReservation, + /// Reservation for the merging of in-memory batches. If the sort /// might spill, `sort_spill_reservation_bytes` will be /// pre-reserved to ensure there is some space for this sort/merge. merge_reservation: MemoryReservation, - /// A handle to the runtime to get spill files - runtime: Arc, - /// The target number of rows for output batches - batch_size: usize, /// How much memory to reserve for performing in-memory sort/merges /// prior to spilling. sort_spill_reservation_bytes: usize, - /// If the in size of buffered memory batches is below this size, - /// the data will be concatenated and sorted in place rather than - /// sort/merged. - sort_in_place_threshold_bytes: usize, } impl ExternalSorter {