Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/frontend/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ pub async fn handle(
name,
operation: AlterTableOperation::AddColumn { column_def },
} => alter_table::handle_add_column(handler_args, name, column_def).await,
Statement::AlterSystem { param: _, value: _ } => todo!(),
// Ignore `StartTransaction` and `BEGIN`,`Abort`,`Rollback`,`Commit`temporarily.Its not
// final implementation.
// 1. Fully support transaction is too hard and gives few benefits to us.
Expand Down
14 changes: 14 additions & 0 deletions src/sqlparser/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ pub enum Statement {
CreateUser(CreateUserStatement),
/// ALTER USER
AlterUser(AlterUserStatement),
/// ALTER SYSTEM SET configuration_parameter { TO | = } { value | 'value' | DEFAULT }
AlterSystem {
param: Ident,
value: SetVariableValue,
},
/// FLUSH the current barrier.
///
/// Note: RisingWave specific statement.
Expand Down Expand Up @@ -1512,6 +1517,13 @@ impl fmt::Display for Statement {
Statement::AlterUser(statement) => {
write!(f, "ALTER USER {}", statement)
}
Statement::AlterSystem{param, value} => {
f.write_str("ALTER SYSTEM SET ")?;
write!(
f,
"{param} = {value}",
)
}
Statement::Flush => {
write!(f, "FLUSH")
}
Expand Down Expand Up @@ -2184,6 +2196,7 @@ impl fmt::Display for CreateFunctionBody {
pub enum SetVariableValue {
Ident(Ident),
Literal(Value),
Default,
}

impl fmt::Display for SetVariableValue {
Expand All @@ -2192,6 +2205,7 @@ impl fmt::Display for SetVariableValue {
match self {
Ident(ident) => write!(f, "{}", ident),
Literal(literal) => write!(f, "{}", literal),
Default => write!(f, "DEFAULT"),
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ impl Parser {
self.parse_alter_table()
} else if self.parse_keyword(Keyword::USER) {
self.parse_alter_user()
} else if self.parse_keyword(Keyword::SYSTEM) {
self.parse_alter_system()
} else {
self.expected("TABLE or USER after ALTER", self.peek_token())
}
Expand Down Expand Up @@ -2347,6 +2349,16 @@ impl Parser {
})
}

pub fn parse_alter_system(&mut self) -> Result<Statement, ParserError> {
self.expect_keyword(Keyword::SET)?;
let param = self.parse_identifier()?;
if self.expect_keyword(Keyword::TO).is_err() && self.expect_token(&Token::Eq).is_err() {
return self.expected("TO or = after ALTER SYSTEM SET", self.peek_token());
}
let value = self.parse_set_variable()?;
Ok(Statement::AlterSystem { param, value })
}

/// Parse a copy statement
pub fn parse_copy(&mut self) -> Result<Statement, ParserError> {
let table_name = self.parse_object_name()?;
Expand Down Expand Up @@ -2421,6 +2433,21 @@ impl Parser {
}
}

fn parse_set_variable(&mut self) -> Result<SetVariableValue, ParserError> {
let token = self.peek_token();
match (self.parse_value(), token) {
(Ok(value), _) => Ok(SetVariableValue::Literal(value)),
(Err(_), Token::Word(ident)) => {
if ident.keyword == Keyword::DEFAULT {
Ok(SetVariableValue::Default)
} else {
Ok(SetVariableValue::Ident(ident.to_ident()))
}
}
(Err(_), unexpected) => self.expected("variable value", unexpected),
}
}

pub fn parse_number_value(&mut self) -> Result<String, ParserError> {
match self.parse_value()? {
Value::Number(v) => Ok(v),
Expand Down Expand Up @@ -3147,12 +3174,7 @@ impl Parser {
if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
let mut values = vec![];
loop {
let token = self.peek_token();
let value = match (self.parse_value(), token) {
(Ok(value), _) => SetVariableValue::Literal(value),
(Err(_), Token::Word(ident)) => SetVariableValue::Ident(ident.to_ident()),
(Err(_), unexpected) => self.expected("variable value", unexpected)?,
};
let value = self.parse_set_variable()?;
values.push(value);
if self.consume_token(&Token::Comma) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ fn parse_set() {
Statement::SetVariable {
local: false,
variable: "a".into(),
value: vec![SetVariableValue::Ident("DEFAULT".into())],
value: vec![SetVariableValue::Default],
}
);

Expand Down
11 changes: 11 additions & 0 deletions src/sqlparser/tests/testdata/alter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- input: ALTER USER user WITH SUPERUSER CREATEDB PASSWORD 'password'
formatted_sql: ALTER USER user WITH SUPERUSER CREATEDB PASSWORD 'password'

- input: ALTER USER user RENAME TO another
formatted_sql: ALTER USER user RENAME TO another

- input: ALTER SYSTEM SET a = 'abc'
formatted_sql: ALTER SYSTEM SET a = 'abc'

- input: ALTER SYSTEM SET a = DEFAULT
formatted_sql: ALTER SYSTEM SET a = DEFAULT
6 changes: 0 additions & 6 deletions src/sqlparser/tests/testdata/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
- input: CREATE USER user WITH SUPERUSER CREATEDB PASSWORD 'password'
formatted_sql: CREATE USER user WITH SUPERUSER CREATEDB PASSWORD 'password'

- input: ALTER USER user WITH SUPERUSER CREATEDB PASSWORD 'password'
formatted_sql: ALTER USER user WITH SUPERUSER CREATEDB PASSWORD 'password'

- input: ALTER USER user RENAME TO another
formatted_sql: ALTER USER user RENAME TO another

- input: CREATE SINK snk
error_msg: |
sql parser error: Expected FROM or AS after CREATE SINK sink_name, found: EOF
Expand Down