@@ -2656,6 +2656,55 @@ impl TableScan {
26562656 } )
26572657 }
26582658
2659+ /// Sets the preferred ordering for this table scan using the builder pattern.
2660+ ///
2661+ /// The preferred ordering serves as a hint to table providers about the desired
2662+ /// sort order for the data. Table providers can use this information to optimize
2663+ /// data access patterns, choose appropriate indexes, or leverage existing sort
2664+ /// orders in the underlying storage.
2665+ ///
2666+ /// # Parameters
2667+ ///
2668+ /// * `preferred_ordering` - An optional vector of sort expressions representing
2669+ /// the desired ordering. `None` indicates no specific ordering preference.
2670+ ///
2671+ /// # Returns
2672+ ///
2673+ /// Returns `self` to enable method chaining in the builder pattern.
2674+ ///
2675+ /// # Examples
2676+ ///
2677+ /// ```rust
2678+ /// use datafusion_expr::{col, SortExpr};
2679+ /// # use datafusion_expr::logical_plan::TableScan;
2680+ /// # use std::sync::Arc;
2681+ /// # use datafusion_common::TableReference;
2682+ ///
2683+ /// // Create a table scan with preferred ordering by column 'a' ascending
2684+ /// # let table_name = TableReference::bare("test");
2685+ /// # let source = Arc::new(datafusion_expr::test::table_source(vec![]));
2686+ /// # let projection = None;
2687+ /// # let projected_schema = Arc::new(datafusion_common::DFSchema::empty());
2688+ /// # let filters = vec![];
2689+ /// # let fetch = None;
2690+ /// let table_scan = TableScan {
2691+ /// table_name,
2692+ /// source,
2693+ /// projection,
2694+ /// projected_schema,
2695+ /// filters,
2696+ /// fetch,
2697+ /// preferred_ordering: None,
2698+ /// }.with_preferred_ordering(Some(vec![
2699+ /// SortExpr::new(col("a"), true, false) // ASC NULLS LAST
2700+ /// ]));
2701+ /// ```
2702+ ///
2703+ /// # Notes
2704+ ///
2705+ /// This is purely an optimization hint. The table provider may choose to ignore
2706+ /// the preferred ordering if it cannot be efficiently satisfied, and the query
2707+ /// execution engine should not rely on the data being returned in this order.
26592708 pub fn with_preferred_ordering (
26602709 mut self ,
26612710 preferred_ordering : Option < Vec < SortExpr > > ,
0 commit comments