Converts logical sort expressions to physical sort expressions. This function transforms a collection of logical sort expressions into their physical representation that can be used during query execution. # Arguments `schema` - The schema containing column definitions. `sort_order` - A collection of logical sort expressions grouped into lexicographic orderings. # Returns A vector of lexicogr
(
schema: &Schema,
sort_order: &[Vec<SortExpr>],
)
| 132 | /// let result = create_ordering(&schema, &sort_exprs).unwrap(); |
| 133 | /// ``` |
| 134 | pub fn create_ordering( |
| 135 | schema: &Schema, |
| 136 | sort_order: &[Vec<SortExpr>], |
| 137 | ) -> Result<Vec<LexOrdering>> { |
| 138 | let mut all_sort_orders = vec![]; |
| 139 | |
| 140 | for (group_idx, exprs) in sort_order.iter().enumerate() { |
| 141 | // Construct PhysicalSortExpr objects from Expr objects: |
| 142 | let mut sort_exprs = vec![]; |
| 143 | for (expr_idx, sort) in exprs.iter().enumerate() { |
| 144 | match &sort.expr { |
| 145 | Expr::Column(col) => match expressions::col(&col.name, schema) { |
| 146 | Ok(expr) => { |
| 147 | let opts = SortOptions::new(!sort.asc, sort.nulls_first); |
| 148 | sort_exprs.push(PhysicalSortExpr::new(expr, opts)); |
| 149 | } |
| 150 | // Cannot find expression in the projected_schema, stop iterating |
| 151 | // since rest of the orderings are violated |
| 152 | Err(_) => break, |
| 153 | }, |
| 154 | expr => { |
| 155 | return plan_err!( |
| 156 | "Expected single column reference in sort_order[{}][{}], got {}", |
| 157 | group_idx, |
| 158 | expr_idx, |
| 159 | expr |
| 160 | ); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | all_sort_orders.extend(LexOrdering::new(sort_exprs)); |
| 165 | } |
| 166 | Ok(all_sort_orders) |
| 167 | } |
| 168 | |
| 169 | /// Creates a vector of [LexOrdering] from a vector of logical expression |
| 170 | pub fn create_lex_ordering( |