Skip to content

Commit

Permalink
revert changes for fetch and add test cases for limit
Browse files Browse the repository at this point in the history
  • Loading branch information
lmatz committed Dec 18, 2024
1 parent e428769 commit 27d2592
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
28 changes: 28 additions & 0 deletions e2e_test/batch/order/negative_offset.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ SELECT * FROM generate_series(0,10,1) LIMIT -3;
statement error
SELECT * FROM generate_series(0,10,1) LIMIT -1%;

statement ok
SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1+2;
----
0
1
2


statement ok
SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1.5*2;
---
0
1
2


statement ok
SELECT * FROM generate_series(0,10,1) as t(v) order by v limit -3+4;
---
0

statement ok
SELECT * FROM generate_series(0,10,1) as t(v) order by v limit 1.5*2 OFFSET 2;
---
2
3
4

statement ok
CREATE TABLE integers(k int);

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/binder/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Binder {
) => {
with_ties = fetch_with_ties;
match quantity {
Some(v) => Some(v),
Some(v) => Some(Expr::Value(Value::Number(v))),
None => Some(Expr::Value(Value::Number("1".to_owned()))),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl fmt::Display for OrderByExpr {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Fetch {
pub with_ties: bool,
pub quantity: Option<Expr>,
pub quantity: Option<String>,
}

impl fmt::Display for Fetch {
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5362,7 +5362,7 @@ impl Parser<'_> {
{
None
} else {
let quantity = self.parse_expr()?;
let quantity = self.parse_number_value()?;
self.expect_one_of_keywords(&[Keyword::ROW, Keyword::ROWS])?;
Some(quantity)
};
Expand Down
4 changes: 2 additions & 2 deletions src/sqlparser/tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3551,7 +3551,7 @@ fn parse_fetch() {
let fetch_first_two_rows_only = Some(Fetch {
with_ties: false,

quantity: Some(Expr::Value(Value::Number("2".to_owned()))),
quantity: Some("2".to_owned()),
});
let ast = verified_query("SELECT foo FROM bar FETCH FIRST 2 ROWS ONLY");
assert_eq!(ast.fetch, fetch_first_two_rows_only);
Expand All @@ -3576,7 +3576,7 @@ fn parse_fetch() {
ast.fetch,
Some(Fetch {
with_ties: true,
quantity: Some(Expr::Value(Value::Number("2".to_owned()))),
quantity: Some("2".to_owned()),
})
);
let ast = verified_query(
Expand Down

0 comments on commit 27d2592

Please sign in to comment.