-
Notifications
You must be signed in to change notification settings - Fork 664
Expand handling of LIMIT 1, 2
handling to include sqlite
#1447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8715,7 +8715,7 @@ impl<'a> Parser<'a> { | |
offset = Some(self.parse_offset()?) | ||
} | ||
|
||
if dialect_of!(self is GenericDialect | MySqlDialect | ClickHouseDialect) | ||
if dialect_of!(self is GenericDialect | MySqlDialect | ClickHouseDialect | SQLiteDialect) | ||
|
||
&& limit.is_some() | ||
&& offset.is_none() | ||
&& self.consume_token(&Token::Comma) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,22 +211,27 @@ impl TestedDialects { | |
|
||
/// Returns all available dialects. | ||
pub fn all_dialects() -> TestedDialects { | ||
let all_dialects = vec![ | ||
Box::new(GenericDialect {}) as Box<dyn Dialect>, | ||
Box::new(PostgreSqlDialect {}) as Box<dyn Dialect>, | ||
Box::new(MsSqlDialect {}) as Box<dyn Dialect>, | ||
Box::new(AnsiDialect {}) as Box<dyn Dialect>, | ||
Box::new(SnowflakeDialect {}) as Box<dyn Dialect>, | ||
Box::new(HiveDialect {}) as Box<dyn Dialect>, | ||
Box::new(RedshiftSqlDialect {}) as Box<dyn Dialect>, | ||
Box::new(MySqlDialect {}) as Box<dyn Dialect>, | ||
Box::new(BigQueryDialect {}) as Box<dyn Dialect>, | ||
Box::new(SQLiteDialect {}) as Box<dyn Dialect>, | ||
Box::new(DuckDbDialect {}) as Box<dyn Dialect>, | ||
Box::new(DatabricksDialect {}) as Box<dyn Dialect>, | ||
]; | ||
specific_dialects(vec![ | ||
|
||
Box::new(GenericDialect {}), | ||
Box::new(PostgreSqlDialect {}), | ||
Box::new(MsSqlDialect {}), | ||
Box::new(AnsiDialect {}), | ||
Box::new(SnowflakeDialect {}), | ||
Box::new(HiveDialect {}), | ||
Box::new(RedshiftSqlDialect {}), | ||
Box::new(MySqlDialect {}), | ||
Box::new(BigQueryDialect {}), | ||
Box::new(SQLiteDialect {}), | ||
Box::new(DuckDbDialect {}), | ||
Box::new(DatabricksDialect {}), | ||
Box::new(ClickHouseDialect {}), | ||
]) | ||
} | ||
|
||
/// Returns a specific set of dialects. | ||
pub fn specific_dialects(dialects: Vec<Box<dyn Dialect>>) -> TestedDialects { | ||
|
||
TestedDialects { | ||
dialects: all_dialects, | ||
dialects, | ||
options: None, | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ use sqlparser::parser::{Parser, ParserError, ParserOptions}; | |
use sqlparser::tokenizer::Tokenizer; | ||
use test_utils::{ | ||
all_dialects, all_dialects_where, alter_table_op, assert_eq_vec, call, expr_from_projection, | ||
join, number, only, table, table_alias, TestedDialects, | ||
join, number, only, specific_dialects, table, table_alias, TestedDialects, | ||
}; | ||
|
||
#[macro_use] | ||
|
@@ -6795,7 +6795,8 @@ fn parse_create_view_with_options() { | |
#[test] | ||
fn parse_create_view_with_columns() { | ||
let sql = "CREATE VIEW v (has, cols) AS SELECT 1, 2"; | ||
match verified_stmt(sql) { | ||
// TODO: why does this fail for ClickHouseDialect? | ||
|
||
match all_dialects_except(|d| d.is::<ClickHouseDialect>()).verified_stmt(sql) { | ||
Statement::CreateView { | ||
name, | ||
columns, | ||
|
@@ -8587,17 +8588,26 @@ fn verified_expr(query: &str) -> Expr { | |
|
||
#[test] | ||
fn parse_offset_and_limit() { | ||
let sql = "SELECT foo FROM bar LIMIT 2 OFFSET 2"; | ||
let sql = "SELECT foo FROM bar LIMIT 1 OFFSET 2"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 that is a good change |
||
let expect = Some(Offset { | ||
value: Expr::Value(number("2")), | ||
rows: OffsetRows::None, | ||
}); | ||
let ast = verified_query(sql); | ||
assert_eq!(ast.offset, expect); | ||
assert_eq!(ast.limit, Some(Expr::Value(number("2")))); | ||
assert_eq!(ast.limit, Some(Expr::Value(number("1")))); | ||
|
||
// different order is OK | ||
one_statement_parses_to("SELECT foo FROM bar OFFSET 2 LIMIT 2", sql); | ||
one_statement_parses_to("SELECT foo FROM bar OFFSET 2 LIMIT 1", sql); | ||
|
||
// mysql syntax is ok for some dialects | ||
specific_dialects(vec![ | ||
Box::new(GenericDialect {}), | ||
Box::new(MySqlDialect {}), | ||
Box::new(SQLiteDialect {}), | ||
Box::new(ClickHouseDialect {}), | ||
]) | ||
.one_statement_parses_to("SELECT foo FROM bar LIMIT 2, 1", sql); | ||
|
||
// expressions are allowed | ||
let sql = "SELECT foo FROM bar LIMIT 1 + 2 OFFSET 3 * 4"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️