risingwave_frontend/binder/expr/order_by.rs
1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use risingwave_common::util::sort_util::OrderType;
16use risingwave_sqlparser::ast::OrderByExpr;
17
18use crate::Binder;
19use crate::error::Result;
20use crate::expr::OrderByExpr as BoundOrderByExpr;
21
22impl Binder {
23 /// Bind an `ORDER BY` expression in other places than
24 /// [`Query`](risingwave_sqlparser::ast::Query),
25 /// including in `OVER` and in aggregate functions.
26 ///
27 /// Different from a query-level `ORDER BY` ([`Self::bind_order_by_expr_in_query`]),
28 /// output-column names or numbers are not allowed here.
29 pub(super) fn bind_order_by_expr(
30 &mut self,
31 OrderByExpr {
32 expr,
33 asc,
34 nulls_first,
35 }: OrderByExpr,
36 ) -> Result<BoundOrderByExpr> {
37 let order_type = OrderType::from_bools(asc, nulls_first);
38 let expr = self.bind_expr_inner(expr)?;
39 Ok(BoundOrderByExpr { expr, order_type })
40 }
41}