-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tabversion <[email protected]>
- Loading branch information
tabversion
committed
Jul 25, 2024
1 parent
6834de8
commit 18cf195
Showing
5 changed files
with
125 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use pgwire::pg_response::{PgResponse, StatementType}; | ||
use risingwave_connector::bail_invalid_option_error; | ||
use risingwave_connector::source::UPSTREAM_SOURCE_KEY; | ||
use risingwave_sqlparser::ast::{ObjectName, Value, WithProperties}; | ||
|
||
use crate::handler::alter_table_column::fetch_table_catalog_for_alter; | ||
use crate::handler::{HandlerArgs, RwPgResponse}; | ||
|
||
const REQUIRE_CLEAN_STATE: &str = "clean_state"; | ||
|
||
pub fn handle_alter_table_connector_attr( | ||
handler_args: HandlerArgs, | ||
table_name: ObjectName, | ||
mut new_attr: WithProperties, | ||
) -> crate::error::Result<RwPgResponse> { | ||
let session = handler_args.session; | ||
let original_table = fetch_table_catalog_for_alter(session.as_ref(), &table_name)?; | ||
|
||
if original_table.associated_source_id.is_none() { | ||
bail_invalid_option_error!("Cannot alter a table without connector") | ||
} | ||
let clean_state_flag = check_attr(&mut new_attr)?; | ||
|
||
return PgResponse::empty_result(StatementType::ALTER_TABLE); | ||
} | ||
|
||
fn check_attr(attr: &mut WithProperties) -> crate::error::Result<bool> { | ||
// check for REQUIRE_CLEAN_STATE, should be contained in attr | ||
let mut contain_clean_state_flag = false; | ||
let mut clean_state_flag = false; | ||
|
||
// cannot change connector | ||
if attr.0.iter().any(|item| { | ||
item.name | ||
.real_value() | ||
.eq_ignore_ascii_case(UPSTREAM_SOURCE_KEY) | ||
}) { | ||
bail_invalid_option_error!("cannot alter attribute {}", UPSTREAM_SOURCE_KEY); | ||
} | ||
|
||
for idx in 0..attr.0.len() { | ||
if attr.0[idx] | ||
.name | ||
.real_value() | ||
.eq_ignore_ascii_case(REQUIRE_CLEAN_STATE) | ||
{ | ||
contain_clean_state_flag = true; | ||
if let Value::Boolean(b) = &attr.0[idx].value { | ||
clean_state_flag = *b | ||
} else { | ||
bail_invalid_option_error!("{} should be a boolean", REQUIRE_CLEAN_STATE); | ||
} | ||
} | ||
attr.0.remove(idx); | ||
break; | ||
} | ||
if !contain_clean_state_flag { | ||
bail_invalid_option_error!( | ||
"{} should be contained in the WITH clause", | ||
REQUIRE_CLEAN_STATE | ||
) | ||
} | ||
|
||
return Ok(clean_state_flag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,7 @@ define_keywords!( | |
CONNECT, | ||
CONNECTION, | ||
CONNECTIONS, | ||
CONNECTOR, | ||
CONSTRAINT, | ||
CONTAINS, | ||
CONVERT, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters