Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: chagelo <changeto104@gmail.com>
  • Loading branch information
chagelo committed Nov 29, 2024
1 parent 805d8ea commit 8f9ae2c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/query/ast/src/parser/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,6 @@ impl<'a, I: Iterator<Item = WithSpan<'a, SetOperationElement>>> PrattParser<I>
if query.offset.is_some() {
return Err("ORDER BY must appear before OFFSET");
}
let order_by = order_by
.into_iter()
.filter(|x| matches!(x.expr, Expr::ColumnRef { .. }))
.collect();
query.order_by = order_by;
}
SetOperationElement::Limit { limit } => {
Expand Down
4 changes: 4 additions & 0 deletions src/query/sql/src/planner/binder/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Binder {
)
.map_err(|e| ErrorCode::SemanticError(e.message()))?;

if let ScalarExpr::ConstantExpr(..) = rewrite_scalar {
continue;
}

let column_binding =
if let ScalarExpr::BoundColumnRef(col) = &rewrite_scalar {
col.column.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,60 @@ SELECT number FROM numbers_mt(10) ORDER BY sum(number)

statement error 1065
SELECT number FROM numbers_mt(10) ORDER BY count(*) + 1

statement ok
CREATE TABLE t1(a int, b int);

statement ok
INSERT INTO t1 VALUES(1, 3),(2, 1), (3, 2)

query I
SELECT * from t1 order by 1;
----
1 3
2 1
3 2

query I
SELECT * from t1 order by 2;
----
2 1
3 2
1 3

statement error 1065
SELECT * from t1 order by 3;

query I
SELECT * from t1 order by t1.a;
----
1 3
2 1
3 2

query I
SELECT * from t1 order by t1.b;
----
2 1
3 2
1 3

statement error 1065
SELECT * from t1 order by t1.1;

query I
SELECT * from t1 order by 'a';
----
1 3
2 1
3 2

query I
SELECT * from t1 order by '1', 1;
----
1 3
2 1
3 2

statement ok
DROP TABLE if EXISTS t1

0 comments on commit 8f9ae2c

Please sign in to comment.