Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2787,10 +2787,11 @@ impl fmt::Display for Declare {
}

/// Sql options of a `CREATE TABLE` statement.
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub enum CreateTableOptions {
#[default]
None,
/// Options specified using the `WITH` keyword.
/// e.g. `WITH (description = "123")`
Expand Down Expand Up @@ -2819,12 +2820,6 @@ pub enum CreateTableOptions {
TableProperties(Vec<SqlOption>),
}

impl Default for CreateTableOptions {
fn default() -> Self {
Self::None
}
}

impl fmt::Display for CreateTableOptions {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down
14 changes: 7 additions & 7 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ pub mod tests {
#[test]
fn test_join() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(
let test = SpanTest::new(
dialect,
"SELECT id, name FROM users LEFT JOIN companies ON users.company_id = companies.id",
);
Expand All @@ -2396,7 +2396,7 @@ pub mod tests {
#[test]
pub fn test_union() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(
let test = SpanTest::new(
dialect,
"SELECT a FROM postgres.public.source UNION SELECT a FROM postgres.public.source",
);
Expand All @@ -2413,7 +2413,7 @@ pub mod tests {
#[test]
pub fn test_subquery() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(
let test = SpanTest::new(
dialect,
"SELECT a FROM (SELECT a FROM postgres.public.source) AS b",
);
Expand All @@ -2438,7 +2438,7 @@ pub mod tests {
#[test]
pub fn test_cte() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(dialect, "WITH cte_outer AS (SELECT a FROM postgres.public.source), cte_ignored AS (SELECT a FROM cte_outer), cte_inner AS (SELECT a FROM cte_outer) SELECT a FROM cte_inner");
let test = SpanTest::new(dialect, "WITH cte_outer AS (SELECT a FROM postgres.public.source), cte_ignored AS (SELECT a FROM cte_outer), cte_inner AS (SELECT a FROM cte_outer) SELECT a FROM cte_inner");

let query = test.0.parse_query().unwrap();

Expand All @@ -2450,7 +2450,7 @@ pub mod tests {
#[test]
pub fn test_snowflake_lateral_flatten() {
let dialect = &SnowflakeDialect;
let mut test = SpanTest::new(dialect, "SELECT FLATTENED.VALUE:field::TEXT AS FIELD FROM SNOWFLAKE.SCHEMA.SOURCE AS S, LATERAL FLATTEN(INPUT => S.JSON_ARRAY) AS FLATTENED");
let test = SpanTest::new(dialect, "SELECT FLATTENED.VALUE:field::TEXT AS FIELD FROM SNOWFLAKE.SCHEMA.SOURCE AS S, LATERAL FLATTEN(INPUT => S.JSON_ARRAY) AS FLATTENED");

let query = test.0.parse_select().unwrap();

Expand All @@ -2462,7 +2462,7 @@ pub mod tests {
#[test]
pub fn test_wildcard_from_cte() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(
let test = SpanTest::new(
dialect,
"WITH cte AS (SELECT a FROM postgres.public.source) SELECT cte.* FROM cte",
);
Expand All @@ -2488,7 +2488,7 @@ pub mod tests {
#[test]
fn test_case_expr_span() {
let dialect = &GenericDialect;
let mut test = SpanTest::new(dialect, "CASE 1 WHEN 2 THEN 3 ELSE 4 END");
let test = SpanTest::new(dialect, "CASE 1 WHEN 2 THEN 3 ELSE 4 END");
let expr = test.0.parse_expr().unwrap();
let expr_span = expr.span();
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/dialect/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
pub struct BigQueryDialect;

impl Dialect for BigQueryDialect {
fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
fn parse_statement(&self, parser: &Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keyword(Keyword::BEGIN) {
if parser.peek_keyword(Keyword::TRANSACTION)
|| parser.peek_token_ref().token == Token::SemiColon
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Dialect for BigQueryDialect {
true
}

fn is_column_alias(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_column_alias(&self, kw: &Keyword, _parser: &Parser) -> bool {
!RESERVED_FOR_COLUMN_ALIAS.contains(kw)
}

Expand Down
24 changes: 12 additions & 12 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub trait Dialect: Debug + Any {
}

/// Dialect-specific prefix parser override
fn parse_prefix(&self, _parser: &mut Parser) -> Option<Result<Expr, ParserError>> {
fn parse_prefix(&self, _parser: &Parser) -> Option<Result<Expr, ParserError>> {
// return None to fall back to the default behavior
None
}
Expand Down Expand Up @@ -615,7 +615,7 @@ pub trait Dialect: Debug + Any {
/// If `None` is returned, falls back to the default behavior.
fn parse_infix(
&self,
_parser: &mut Parser,
_parser: &Parser,
_expr: &Expr,
_precedence: u8,
) -> Option<Result<Expr, ParserError>> {
Expand Down Expand Up @@ -778,7 +778,7 @@ pub trait Dialect: Debug + Any {
/// This method is called to parse the next statement.
///
/// If `None` is returned, falls back to the default behavior.
fn parse_statement(&self, _parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
fn parse_statement(&self, _parser: &Parser) -> Option<Result<Statement, ParserError>> {
// return None to fall back to the default behavior
None
}
Expand All @@ -790,7 +790,7 @@ pub trait Dialect: Debug + Any {
/// If `None` is returned, falls back to the default behavior.
fn parse_column_option(
&self,
_parser: &mut Parser,
_parser: &Parser,
) -> Result<Option<Result<Option<ColumnOption>, ParserError>>, ParserError> {
// return None to fall back to the default behavior
Ok(None)
Expand Down Expand Up @@ -1021,33 +1021,33 @@ pub trait Dialect: Debug + Any {

/// Returns true if the specified keyword should be parsed as a column identifier.
/// See [keywords::RESERVED_FOR_COLUMN_ALIAS]
fn is_column_alias(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_column_alias(&self, kw: &Keyword, _parser: &Parser) -> bool {
!keywords::RESERVED_FOR_COLUMN_ALIAS.contains(kw)
}

/// Returns true if the specified keyword should be parsed as a select item alias.
/// When explicit is true, the keyword is preceded by an `AS` word. Parser is provided
/// to enable looking ahead if needed.
fn is_select_item_alias(&self, explicit: bool, kw: &Keyword, parser: &mut Parser) -> bool {
fn is_select_item_alias(&self, explicit: bool, kw: &Keyword, parser: &Parser) -> bool {
explicit || self.is_column_alias(kw, parser)
}

/// Returns true if the specified keyword should be parsed as a table factor identifier.
/// See [keywords::RESERVED_FOR_TABLE_FACTOR]
fn is_table_factor(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_table_factor(&self, kw: &Keyword, _parser: &Parser) -> bool {
!keywords::RESERVED_FOR_TABLE_FACTOR.contains(kw)
}

/// Returns true if the specified keyword should be parsed as a table factor alias.
/// See [keywords::RESERVED_FOR_TABLE_ALIAS]
fn is_table_alias(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_table_alias(&self, kw: &Keyword, _parser: &Parser) -> bool {
!keywords::RESERVED_FOR_TABLE_ALIAS.contains(kw)
}

/// Returns true if the specified keyword should be parsed as a table factor alias.
/// When explicit is true, the keyword is preceded by an `AS` word. Parser is provided
/// to enable looking ahead if needed.
fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, parser: &mut Parser) -> bool {
fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, parser: &Parser) -> bool {
explicit || self.is_table_alias(kw, parser)
}

Expand Down Expand Up @@ -1400,14 +1400,14 @@ mod tests {

fn parse_prefix(
&self,
parser: &mut sqlparser::parser::Parser,
parser: &sqlparser::parser::Parser,
) -> Option<Result<Expr, sqlparser::parser::ParserError>> {
self.0.parse_prefix(parser)
}

fn parse_infix(
&self,
parser: &mut sqlparser::parser::Parser,
parser: &sqlparser::parser::Parser,
expr: &Expr,
precedence: u8,
) -> Option<Result<Expr, sqlparser::parser::ParserError>> {
Expand All @@ -1423,7 +1423,7 @@ mod tests {

fn parse_statement(
&self,
parser: &mut sqlparser::parser::Parser,
parser: &sqlparser::parser::Parser,
) -> Option<Result<Statement, sqlparser::parser::ParserError>> {
self.0.parse_statement(parser)
}
Expand Down
10 changes: 5 additions & 5 deletions src/dialect/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ impl Dialect for MsSqlDialect {
&[GranteesType::Public]
}

fn is_column_alias(&self, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_column_alias(&self, kw: &Keyword, _parser: &Parser) -> bool {
!keywords::RESERVED_FOR_COLUMN_ALIAS.contains(kw) && !RESERVED_FOR_COLUMN_ALIAS.contains(kw)
}

fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
fn parse_statement(&self, parser: &Parser) -> Option<Result<Statement, ParserError>> {
if parser.peek_keyword(Keyword::IF) {
Some(self.parse_if_stmt(parser))
} else if parser.parse_keywords(&[Keyword::CREATE, Keyword::TRIGGER]) {
Expand All @@ -157,7 +157,7 @@ impl MsSqlDialect {
/// [ ELSE
/// { sql_statement | statement_block } ]
/// ```
fn parse_if_stmt(&self, parser: &mut Parser) -> Result<Statement, ParserError> {
fn parse_if_stmt(&self, parser: &Parser) -> Result<Statement, ParserError> {
let if_token = parser.expect_keyword(Keyword::IF)?;

let condition = parser.parse_expr()?;
Expand Down Expand Up @@ -240,7 +240,7 @@ impl MsSqlDialect {
/// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql
fn parse_create_trigger(
&self,
parser: &mut Parser,
parser: &Parser,
or_alter: bool,
) -> Result<Statement, ParserError> {
let name = parser.parse_object_name(false)?;
Expand Down Expand Up @@ -279,7 +279,7 @@ impl MsSqlDialect {
/// Stops parsing when reaching EOF or the given keyword.
fn parse_statement_list(
&self,
parser: &mut Parser,
parser: &Parser,
terminal_keyword: Option<Keyword>,
) -> Result<Vec<Statement>, ParserError> {
let mut stmts = Vec::new();
Expand Down
14 changes: 7 additions & 7 deletions src/dialect/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Dialect for MySqlDialect {

fn parse_infix(
&self,
parser: &mut crate::parser::Parser,
parser: &crate::parser::Parser,
expr: &crate::ast::Expr,
_precedence: u8,
) -> Option<Result<crate::ast::Expr, ParserError>> {
Expand All @@ -102,7 +102,7 @@ impl Dialect for MySqlDialect {
}
}

fn parse_statement(&self, parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
fn parse_statement(&self, parser: &Parser) -> Option<Result<Statement, ParserError>> {
if parser.parse_keywords(&[Keyword::LOCK, Keyword::TABLES]) {
Some(parse_lock_tables(parser))
} else if parser.parse_keywords(&[Keyword::UNLOCK, Keyword::TABLES]) {
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Dialect for MySqlDialect {
true
}

fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, _parser: &mut Parser) -> bool {
fn is_table_factor_alias(&self, explicit: bool, kw: &Keyword, _parser: &Parser) -> bool {
explicit
|| (!keywords::RESERVED_FOR_TABLE_ALIAS.contains(kw)
&& !RESERVED_FOR_TABLE_ALIAS_MYSQL.contains(kw))
Expand Down Expand Up @@ -171,13 +171,13 @@ impl Dialect for MySqlDialect {

/// `LOCK TABLES`
/// <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
fn parse_lock_tables(parser: &mut Parser) -> Result<Statement, ParserError> {
fn parse_lock_tables(parser: &Parser) -> Result<Statement, ParserError> {
let tables = parser.parse_comma_separated(parse_lock_table)?;
Ok(Statement::LockTables { tables })
}

// tbl_name [[AS] alias] lock_type
fn parse_lock_table(parser: &mut Parser) -> Result<LockTable, ParserError> {
fn parse_lock_table(parser: &Parser) -> Result<LockTable, ParserError> {
let table = parser.parse_identifier()?;
let alias =
parser.parse_optional_alias(&[Keyword::READ, Keyword::WRITE, Keyword::LOW_PRIORITY])?;
Expand All @@ -191,7 +191,7 @@ fn parse_lock_table(parser: &mut Parser) -> Result<LockTable, ParserError> {
}

// READ [LOCAL] | [LOW_PRIORITY] WRITE
fn parse_lock_tables_type(parser: &mut Parser) -> Result<LockTableType, ParserError> {
fn parse_lock_tables_type(parser: &Parser) -> Result<LockTableType, ParserError> {
if parser.parse_keyword(Keyword::READ) {
if parser.parse_keyword(Keyword::LOCAL) {
Ok(LockTableType::Read { local: true })
Expand All @@ -211,6 +211,6 @@ fn parse_lock_tables_type(parser: &mut Parser) -> Result<LockTableType, ParserEr

/// UNLOCK TABLES
/// <https://dev.mysql.com/doc/refman/8.0/en/lock-tables.html>
fn parse_unlock_tables(_parser: &mut Parser) -> Result<Statement, ParserError> {
fn parse_unlock_tables(_parser: &Parser) -> Result<Statement, ParserError> {
Ok(Statement::UnlockTables)
}
Loading
Loading