Returns the order by expressions from the query with the select expressions.
(
order_by: Option<OrderBy>,
select_exprs: Option<&Vec<Expr>>,
)
| 388 | |
| 389 | /// Returns the order by expressions from the query with the select expressions. |
| 390 | pub(crate) fn to_order_by_exprs_with_select( |
| 391 | order_by: Option<OrderBy>, |
| 392 | select_exprs: Option<&Vec<Expr>>, |
| 393 | ) -> Result<Vec<OrderByExpr>> { |
| 394 | let Some(OrderBy { kind, interpolate }) = order_by else { |
| 395 | // If no order by, return an empty array. |
| 396 | return Ok(vec![]); |
| 397 | }; |
| 398 | if let Some(_interpolate) = interpolate { |
| 399 | return not_impl_err!("ORDER BY INTERPOLATE is not supported"); |
| 400 | } |
| 401 | match kind { |
| 402 | OrderByKind::All(order_by_options) => { |
| 403 | let Some(exprs) = select_exprs else { |
| 404 | return Ok(vec![]); |
| 405 | }; |
| 406 | let order_by_exprs = exprs |
| 407 | .iter() |
| 408 | .map(|select_expr| match select_expr { |
| 409 | Expr::Column(column) => Ok(OrderByExpr { |
| 410 | expr: SQLExpr::Identifier(Ident { |
| 411 | value: column.name.clone(), |
| 412 | quote_style: None, |
| 413 | span: Span::empty(), |
| 414 | }), |
| 415 | options: order_by_options, |
| 416 | with_fill: None, |
| 417 | }), |
| 418 | // TODO: Support other types of expressions |
| 419 | _ => not_impl_err!( |
| 420 | "ORDER BY ALL is not supported for non-column expressions" |
| 421 | ), |
| 422 | }) |
| 423 | .collect::<Result<Vec<_>>>()?; |
| 424 | Ok(order_by_exprs) |
| 425 | } |
| 426 | OrderByKind::Expressions(order_by_exprs) => Ok(order_by_exprs), |
| 427 | } |
| 428 | } |
no test coverage detected
searching dependent graphs…