mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 15:34:09 +00:00
Support drop sequence statement (#673)
* Add ObjectType Sequence * Drop sequence test cases added. * Parser and Drop statement Display updated. * Parser and Drop statement Display updated. * Fix compile errors * add new test case
This commit is contained in:
parent
b42632fa0d
commit
b32cbbd855
4 changed files with 33 additions and 2 deletions
|
@ -1184,6 +1184,9 @@ pub enum Statement {
|
||||||
/// Whether `CASCADE` was specified. This will be `false` when
|
/// Whether `CASCADE` was specified. This will be `false` when
|
||||||
/// `RESTRICT` or no drop behavior at all was specified.
|
/// `RESTRICT` or no drop behavior at all was specified.
|
||||||
cascade: bool,
|
cascade: bool,
|
||||||
|
/// Whether `RESTRICT` was specified. This will be `false` when
|
||||||
|
/// `CASCADE` or no drop behavior at all was specified.
|
||||||
|
restrict: bool,
|
||||||
/// Hive allows you specify whether the table's stored data will be
|
/// Hive allows you specify whether the table's stored data will be
|
||||||
/// deleted along with the dropped table
|
/// deleted along with the dropped table
|
||||||
purge: bool,
|
purge: bool,
|
||||||
|
@ -2143,14 +2146,16 @@ impl fmt::Display for Statement {
|
||||||
if_exists,
|
if_exists,
|
||||||
names,
|
names,
|
||||||
cascade,
|
cascade,
|
||||||
|
restrict,
|
||||||
purge,
|
purge,
|
||||||
} => write!(
|
} => write!(
|
||||||
f,
|
f,
|
||||||
"DROP {}{} {}{}{}",
|
"DROP {}{} {}{}{}{}",
|
||||||
object_type,
|
object_type,
|
||||||
if *if_exists { " IF EXISTS" } else { "" },
|
if *if_exists { " IF EXISTS" } else { "" },
|
||||||
display_comma_separated(names),
|
display_comma_separated(names),
|
||||||
if *cascade { " CASCADE" } else { "" },
|
if *cascade { " CASCADE" } else { "" },
|
||||||
|
if *restrict { " RESTRICT" } else { "" },
|
||||||
if *purge { " PURGE" } else { "" }
|
if *purge { " PURGE" } else { "" }
|
||||||
),
|
),
|
||||||
Statement::Discard { object_type } => {
|
Statement::Discard { object_type } => {
|
||||||
|
@ -2910,6 +2915,7 @@ pub enum ObjectType {
|
||||||
Index,
|
Index,
|
||||||
Schema,
|
Schema,
|
||||||
Role,
|
Role,
|
||||||
|
Sequence,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ObjectType {
|
impl fmt::Display for ObjectType {
|
||||||
|
@ -2920,6 +2926,7 @@ impl fmt::Display for ObjectType {
|
||||||
ObjectType::Index => "INDEX",
|
ObjectType::Index => "INDEX",
|
||||||
ObjectType::Schema => "SCHEMA",
|
ObjectType::Schema => "SCHEMA",
|
||||||
ObjectType::Role => "ROLE",
|
ObjectType::Role => "ROLE",
|
||||||
|
ObjectType::Sequence => "SEQUENCE",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2441,9 +2441,11 @@ impl<'a> Parser<'a> {
|
||||||
ObjectType::Role
|
ObjectType::Role
|
||||||
} else if self.parse_keyword(Keyword::SCHEMA) {
|
} else if self.parse_keyword(Keyword::SCHEMA) {
|
||||||
ObjectType::Schema
|
ObjectType::Schema
|
||||||
|
} else if self.parse_keyword(Keyword::SEQUENCE) {
|
||||||
|
ObjectType::Sequence
|
||||||
} else {
|
} else {
|
||||||
return self.expected(
|
return self.expected(
|
||||||
"TABLE, VIEW, INDEX, ROLE, or SCHEMA after DROP",
|
"TABLE, VIEW, INDEX, ROLE, SCHEMA, or SEQUENCE after DROP",
|
||||||
self.peek_token(),
|
self.peek_token(),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2465,6 +2467,7 @@ impl<'a> Parser<'a> {
|
||||||
if_exists,
|
if_exists,
|
||||||
names,
|
names,
|
||||||
cascade,
|
cascade,
|
||||||
|
restrict,
|
||||||
purge,
|
purge,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4469,6 +4469,7 @@ fn parse_drop_table() {
|
||||||
names,
|
names,
|
||||||
cascade,
|
cascade,
|
||||||
purge: _,
|
purge: _,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
assert!(!if_exists);
|
assert!(!if_exists);
|
||||||
assert_eq!(ObjectType::Table, object_type);
|
assert_eq!(ObjectType::Table, object_type);
|
||||||
|
@ -4489,6 +4490,7 @@ fn parse_drop_table() {
|
||||||
names,
|
names,
|
||||||
cascade,
|
cascade,
|
||||||
purge: _,
|
purge: _,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
assert!(if_exists);
|
assert!(if_exists);
|
||||||
assert_eq!(ObjectType::Table, object_type);
|
assert_eq!(ObjectType::Table, object_type);
|
||||||
|
|
|
@ -22,6 +22,25 @@ use sqlparser::ast::*;
|
||||||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||||
use sqlparser::parser::ParserError;
|
use sqlparser::parser::ParserError;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_drop_sequence() {
|
||||||
|
// SimpleLogger::new().init().unwrap();
|
||||||
|
let sql1 = "DROP SEQUENCE IF EXISTS name0 CASCADE";
|
||||||
|
pg().one_statement_parses_to(sql1, "DROP SEQUENCE IF EXISTS name0 CASCADE");
|
||||||
|
let sql2 = "DROP SEQUENCE IF EXISTS name1 RESTRICT";
|
||||||
|
pg().one_statement_parses_to(sql2, "DROP SEQUENCE IF EXISTS name1 RESTRICT");
|
||||||
|
let sql3 = "DROP SEQUENCE name2 CASCADE";
|
||||||
|
pg().one_statement_parses_to(sql3, "DROP SEQUENCE name2 CASCADE");
|
||||||
|
let sql4 = "DROP SEQUENCE name2";
|
||||||
|
pg().one_statement_parses_to(sql4, "DROP SEQUENCE name2");
|
||||||
|
let sql5 = "DROP SEQUENCE name0 CASCADE";
|
||||||
|
pg().one_statement_parses_to(sql5, "DROP SEQUENCE name0 CASCADE");
|
||||||
|
let sql6 = "DROP SEQUENCE name1 RESTRICT";
|
||||||
|
pg().one_statement_parses_to(sql6, "DROP SEQUENCE name1 RESTRICT");
|
||||||
|
let sql7 = "DROP SEQUENCE name1, name2, name3";
|
||||||
|
pg().one_statement_parses_to(sql7, "DROP SEQUENCE name1, name2, name3");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_table_with_defaults() {
|
fn parse_create_table_with_defaults() {
|
||||||
let sql = "CREATE TABLE public.customer (
|
let sql = "CREATE TABLE public.customer (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue