Skip to content

Commit 724d476

Browse files
committed
move comments
1 parent 7552aad commit 724d476

File tree

1 file changed

+13
-53
lines changed
  • datafusion/expr/src/logical_plan

1 file changed

+13
-53
lines changed

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,14 @@ impl PartialOrd for Window {
25932593
}
25942594
}
25952595

2596+
/// Communicates the desired ordering of the output of a scan operation.
2597+
/// This can be used by implementers of [`TableProvider`] to optimize the order in which data is output from the scan.
2598+
/// It is a hint and not a requirement:
2599+
/// - If this information is completely ignored, e.g. data is scanned randomly, the query will still be correct because a sort will be applied to the data.
2600+
/// - Partially ordered data will also be re-sorted but this may result in optimizations like early stopping, additional data pruning, reduced memory usage during the sort, etc.
2601+
/// - If the scan produces exactly the requested ordering, and sets it's properties to reflect this, upstream sorts may be optimized away.
2602+
///
2603+
/// [`TableProvider`]: https://docs.rs/datafusion/latest/datafusion/catalog/trait.TableProvider.html
25962604
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Default)]
25972605
pub struct ScanOrdering {
25982606
/// Optional preferred ordering for the scan that matches the output order of upstream query nodes.
@@ -2604,7 +2612,8 @@ pub struct ScanOrdering {
26042612
}
26052613

26062614
impl ScanOrdering {
2607-
/// Create a new ScanOrdering
2615+
/// Attatch a preferred ordering to the scan ordering.
2616+
/// See [`ScanOrdering`] for details on how this is used.
26082617
pub fn with_preferred_ordering(mut self, preferred_ordering: Vec<SortExpr>) -> Self {
26092618
self.preferred_ordering = Some(preferred_ordering);
26102619
self
@@ -2690,7 +2699,7 @@ impl PartialOrd for TableScan {
26902699
pub filters: &'a Vec<Expr>,
26912700
/// Optional number of rows to read
26922701
pub fetch: &'a Option<usize>,
2693-
/// Optional preferred ordering for the scan
2702+
/// Ordering information passed from the query to the scan.
26942703
pub ordering: &'a Option<ScanOrdering>,
26952704
}
26962705
let comparable_self = ComparableTableScan {
@@ -2779,57 +2788,8 @@ impl TableScan {
27792788
})
27802789
}
27812790

2782-
/// Sets the preferred ordering for this table scan using the builder pattern.
2783-
///
2784-
/// The preferred ordering serves as a hint to table providers about the desired
2785-
/// sort order for the data. Table providers can use this information to optimize
2786-
/// data access patterns, choose appropriate indexes, or leverage existing sort
2787-
/// orders in the underlying storage.
2788-
///
2789-
/// # Parameters
2790-
///
2791-
/// * `preferred_ordering` - An optional vector of sort expressions representing
2792-
/// the desired ordering. `None` indicates no specific ordering preference.
2793-
///
2794-
/// # Returns
2795-
///
2796-
/// Returns `self` to enable method chaining in the builder pattern.
2797-
///
2798-
/// # Examples
2799-
///
2800-
/// ```rust
2801-
/// use datafusion_expr::{col, SortExpr};
2802-
/// # use datafusion_expr::logical_plan::{TableScan, builder::table_source};
2803-
/// # use std::sync::Arc;
2804-
/// # use datafusion_common::{TableReference, DFSchema};
2805-
/// # use arrow::datatypes::{Schema, Field, DataType};
2806-
///
2807-
/// // Create a table scan with preferred ordering by column 'a' ascending
2808-
/// # let table_name = TableReference::bare("test");
2809-
/// # let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);
2810-
/// # let source = table_source(&schema);
2811-
/// # let projection = None;
2812-
/// # let projected_schema = Arc::new(datafusion_common::DFSchema::empty());
2813-
/// # let filters = vec![];
2814-
/// # let fetch = None;
2815-
/// let table_scan = TableScan {
2816-
/// table_name,
2817-
/// source,
2818-
/// projection,
2819-
/// projected_schema,
2820-
/// filters,
2821-
/// fetch,
2822-
/// preferred_ordering: None,
2823-
/// }.with_preferred_ordering(Some(vec![
2824-
/// SortExpr::new(col("a"), true, false) // ASC NULLS LAST
2825-
/// ]));
2826-
/// ```
2827-
///
2828-
/// # Notes
2829-
///
2830-
/// This is purely an optimization hint. The table provider may choose to ignore
2831-
/// the preferred ordering if it cannot be efficiently satisfied, and the query
2832-
/// execution engine should not rely on the data being returned in this order.
2791+
/// Sets the ordering information for the scan.
2792+
/// See [`ScanOrdering`] for details on how this is used.
28332793
pub fn with_ordering(mut self, ordering: ScanOrdering) -> Self {
28342794
self.ordering = Some(ordering);
28352795
self

0 commit comments

Comments
 (0)