MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / plan_function_order_by

Function plan_function_order_by

src/sql/src/plan/query.rs:5176–5193  ·  view source on GitHub ↗

Plans the ORDER BY clause of a window function. Unfortunately, we have to create two HIR structs from an AST OrderByExpr: A ColumnOrder has asc/desc and nulls first/last, but can't represent an HirScalarExpr, just a column reference by index. Therefore, we return both HirScalarExprs and ColumnOrders. Note that the column references in the ColumnOrders point NOT to input columns, but into the `Vec

(
    ecx: &ExprContext,
    order_by: &[OrderByExpr<Aug>],
)

Source from the content-addressed store, hash-verified

5174/// Note that the column references in the ColumnOrders point NOT to input columns, but into the
5175/// `Vec<HirScalarExpr>` that we return.
5176fn plan_function_order_by(
5177 ecx: &ExprContext,
5178 order_by: &[OrderByExpr<Aug>],
5179) -> Result<(Vec<HirScalarExpr>, Vec<ColumnOrder>), PlanError> {
5180 let mut order_by_exprs = vec![];
5181 let mut col_orders = vec![];
5182 {
5183 for (i, obe) in order_by.iter().enumerate() {
5184 // Unlike `SELECT ... ORDER BY` clauses, function `ORDER BY` clauses
5185 // do not support ordinal references in PostgreSQL. So we use
5186 // `plan_expr` directly rather than `plan_order_by_or_distinct_expr`.
5187 let expr = plan_expr(ecx, &obe.expr)?.type_as_any(ecx)?;
5188 order_by_exprs.push(expr);
5189 col_orders.push(resolve_desc_and_nulls_last(obe, i));
5190 }
5191 }
5192 Ok((order_by_exprs, col_orders))
5193}
5194
5195/// Returns a human-readable rendering of `name`, falling back to a debug
5196/// dump of the `ResolvedItemName` if humanization fails. Used to construct

Callers 2

plan_aggregate_commonFunction · 0.85

Calls 6

plan_exprFunction · 0.85
enumerateMethod · 0.80
type_as_anyMethod · 0.80
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected