Skip to content

Commit

Permalink
fix(sqlparser): fix order by followed by scalar (#16967)
Browse files Browse the repository at this point in the history
* fix(sqlparser): fix order by followed by scalar

Signed-off-by: chagelo <[email protected]>

* fix

Signed-off-by: chagelo <[email protected]>

---------

Signed-off-by: chagelo <[email protected]>
  • Loading branch information
chagelo authored Dec 2, 2024
1 parent c496fce commit 35c1c24
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
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 35c1c24

Please sign in to comment.