Skip to content

Commit

Permalink
feat: add create or replace user support
Browse files Browse the repository at this point in the history
  • Loading branch information
lichuang committed Feb 3, 2024
2 parents 68d12c9 + 0e64c72 commit 7902811
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
18 changes: 7 additions & 11 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,11 +1735,7 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
table_id,
new_table: tb_id_seq == 0,
spec_vec: if let Some((spec_vec, mut_share_table_info)) = opt.0 {
if spec_vec.is_empty() {
None
} else {
Some((spec_vec, mut_share_table_info))
}
Some((spec_vec, mut_share_table_info))
} else {
None
},
Expand Down Expand Up @@ -2483,11 +2479,7 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
if succ {
return Ok(DropTableReply {
spec_vec: if let Some((spec_vec, mut_share_table_info)) = opt.0 {
if spec_vec.is_empty() {
None
} else {
Some((spec_vec, mut_share_table_info))
}
Some((spec_vec, mut_share_table_info))
} else {
None
},
Expand Down Expand Up @@ -3981,7 +3973,11 @@ async fn drop_table_by_id(
));
}
}
Ok((Some((spec_vec, mut_share_table_info)), tb_id_seq))
if spec_vec.is_empty() {
Ok((None, tb_id_seq))
} else {
Ok((Some((spec_vec, mut_share_table_info)), tb_id_seq))
}
}

async fn drop_database_meta(
Expand Down
2 changes: 1 addition & 1 deletion src/query/ast/tests/it/testdata/statement-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ error:
1 | create user 'test-e'@'localhost' identified by 'password';
| ------ ^^^^^^^^^^^ unexpected `'localhost'`, expecting `'%'` or `IDENTIFIED`
| |
| while parsing `CREATE USER [IF NOT EXISTS] '<username>'@'hostname' IDENTIFIED [WITH <auth_type>] [BY <password>] [WITH <user_option>, ...]`
| while parsing `CREATE [OR REPLACE] USER [IF NOT EXISTS] '<username>'@'hostname' IDENTIFIED [WITH <auth_type>] [BY <password>] [WITH <user_option>, ...]`


---------- Input ----------
Expand Down
14 changes: 7 additions & 7 deletions src/query/ast/tests/it/testdata/statement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14576,9 +14576,6 @@ CREATE CONNECTION IF NOT EXISTS my_conn STORAGE_TYPE = s3
---------- AST ------------
CreateConnection(
CreateConnectionStmt {
create_option: CreateIfNotExists(
true,
),
name: Identifier {
name: "my_conn",
quote: None,
Expand All @@ -14588,6 +14585,9 @@ CreateConnection(
},
storage_type: "s3",
storage_params: {},
create_option: CreateIfNotExists(
true,
),
},
)

Expand All @@ -14599,9 +14599,6 @@ CREATE CONNECTION IF NOT EXISTS my_conn STORAGE_TYPE = s3 any_arg = ******lue
---------- AST ------------
CreateConnection(
CreateConnectionStmt {
create_option: CreateIfNotExists(
true,
),
name: Identifier {
name: "my_conn",
quote: None,
Expand All @@ -14613,6 +14610,9 @@ CreateConnection(
storage_params: {
"any_arg": "any_value",
},
create_option: CreateIfNotExists(
true,
),
},
)

Expand All @@ -14624,7 +14624,6 @@ CREATE OR REPLACE CONNECTION my_conn STORAGE_TYPE = s3 any_arg = ******lue
---------- AST ------------
CreateConnection(
CreateConnectionStmt {
create_option: CreateOrReplace,
name: Identifier {
name: "my_conn",
quote: None,
Expand All @@ -14636,6 +14635,7 @@ CreateConnection(
storage_params: {
"any_arg": "any_value",
},
create_option: CreateOrReplace,
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,12 @@ impl<Method: HashMethodBounds> AccumulatingTransform for TransformPartialAggrega
Ok(vec![])
}

fn on_finish(&mut self, _output: bool) -> Result<Vec<DataBlock>> {
fn on_finish(&mut self, output: bool) -> Result<Vec<DataBlock>> {
Ok(match std::mem::take(&mut self.hash_table) {
HashTable::MovedOut => unreachable!(),
HashTable::MovedOut => match !output && std::thread::panicking() {
true => vec![],
false => unreachable!(),
},
HashTable::HashTable(v) => match v.hashtable.len() == 0 {
true => vec![],
false => vec![DataBlock::empty_with_meta(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,12 @@ impl<Method: HashMethodBounds> AccumulatingTransform for TransformPartialGroupBy
Ok(vec![])
}

fn on_finish(&mut self, _output: bool) -> Result<Vec<DataBlock>> {
fn on_finish(&mut self, output: bool) -> Result<Vec<DataBlock>> {
Ok(match std::mem::take(&mut self.hash_table) {
HashTable::MovedOut => unreachable!(),
HashTable::MovedOut => match !output && std::thread::panicking() {
true => vec![],
false => unreachable!(),
},
HashTable::HashTable(cell) => match cell.hashtable.len() == 0 {
true => vec![],
false => vec![DataBlock::empty_with_meta(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ query TTT
SHOW CONNECTIONS
----

statement ok
DROP CONNECTION IF EXISTS test_replace_conn

statement error 1005
CREATE OR REPLACE CONNECTION IF NOT EXISTS test_replace_conn STORAGE_TYPE='azblob' ENDPOINT_URL='http://s3.amazonaws.com';

statement ok
CREATE OR REPLACE CONNECTION test_replace_conn STORAGE_TYPE='azblob' ENDPOINT_URL='http://s3.amazonaws.com';

statement ok
CREATE OR REPLACE CONNECTION test_replace_conn STORAGE_TYPE='azblob2' ENDPOINT_URL='http://s3.amazonaws.com';
CREATE OR REPLACE CONNECTION test_replace_conn STORAGE_TYPE='S3';

statement ok
DROP CONNECTION IF EXISTS test_replace_conn

0 comments on commit 7902811

Please sign in to comment.