Skip to content

Commit

Permalink
chore: rename change to modify (#5000)
Browse files Browse the repository at this point in the history
* chore: rename change to modify

* chore: proto rev
  • Loading branch information
CookiePieWw authored Nov 15, 2024
1 parent cdba7b4 commit a2852af
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ etcd-client = "0.13"
fst = "0.4.7"
futures = "0.3"
futures-util = "0.3"
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "e1070ad3e7ad3d89f8dd1e20756b0c0cc26f3365" }
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "fb4e2146b1ea8816148304f1f258e7a73736a905" }
hex = "0.4"
humantime = "2.1"
humantime-serde = "1.1"
Expand Down
36 changes: 18 additions & 18 deletions src/common/grpc-expr/src/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use api::v1::add_column_location::LocationType;
use api::v1::alter_expr::Kind;
use api::v1::column_def::as_fulltext_option;
use api::v1::{
column_def, AddColumnLocation as Location, AlterExpr, Analyzer, ChangeColumnTypes,
CreateTableExpr, DropColumns, RenameTable, SemanticType,
column_def, AddColumnLocation as Location, AlterExpr, Analyzer, CreateTableExpr, DropColumns,
ModifyColumnTypes, RenameTable, SemanticType,
};
use common_query::AddColumnLocation;
use datatypes::schema::{ColumnSchema, FulltextOptions, RawSchema};
use snafu::{ensure, OptionExt, ResultExt};
use store_api::region_request::ChangeOption;
use table::metadata::TableId;
use table::requests::{AddColumnRequest, AlterKind, AlterTableRequest, ChangeColumnTypeRequest};
use table::requests::{AddColumnRequest, AlterKind, AlterTableRequest, ModifyColumnTypeRequest};

use crate::error::{
InvalidChangeFulltextOptionRequestSnafu, InvalidChangeTableOptionRequestSnafu,
Expand Down Expand Up @@ -68,25 +68,25 @@ pub fn alter_expr_to_request(table_id: TableId, expr: AlterExpr) -> Result<Alter
columns: add_column_requests,
}
}
Kind::ChangeColumnTypes(ChangeColumnTypes {
change_column_types,
Kind::ModifyColumnTypes(ModifyColumnTypes {
modify_column_types,
}) => {
let change_column_type_requests = change_column_types
let modify_column_type_requests = modify_column_types
.into_iter()
.map(|cct| {
let target_type =
ColumnDataTypeWrapper::new(cct.target_type(), cct.target_type_extension)
.into();

Ok(ChangeColumnTypeRequest {
Ok(ModifyColumnTypeRequest {
column_name: cct.column_name,
target_type,
})
})
.collect::<Result<Vec<_>>>()?;

AlterKind::ChangeColumnTypes {
columns: change_column_type_requests,
AlterKind::ModifyColumnTypes {
columns: modify_column_type_requests,
}
}
Kind::DropColumns(DropColumns { drop_columns }) => AlterKind::DropColumns {
Expand Down Expand Up @@ -183,7 +183,7 @@ fn parse_location(location: Option<Location>) -> Result<Option<AddColumnLocation
#[cfg(test)]
mod tests {
use api::v1::{
AddColumn, AddColumns, ChangeColumnType, ColumnDataType, ColumnDef, DropColumn,
AddColumn, AddColumns, ColumnDataType, ColumnDef, DropColumn, ModifyColumnType,
SemanticType,
};
use datatypes::prelude::ConcreteDataType;
Expand Down Expand Up @@ -309,14 +309,14 @@ mod tests {
}

#[test]
fn test_change_column_type_expr() {
fn test_modify_column_type_expr() {
let expr = AlterExpr {
catalog_name: "test_catalog".to_string(),
schema_name: "test_schema".to_string(),
table_name: "monitor".to_string(),

kind: Some(Kind::ChangeColumnTypes(ChangeColumnTypes {
change_column_types: vec![ChangeColumnType {
kind: Some(Kind::ModifyColumnTypes(ModifyColumnTypes {
modify_column_types: vec![ModifyColumnType {
column_name: "mem_usage".to_string(),
target_type: ColumnDataType::String as i32,
target_type_extension: None,
Expand All @@ -329,16 +329,16 @@ mod tests {
assert_eq!(alter_request.schema_name, "test_schema");
assert_eq!("monitor".to_string(), alter_request.table_name);

let mut change_column_types = match alter_request.alter_kind {
AlterKind::ChangeColumnTypes { columns } => columns,
let mut modify_column_types = match alter_request.alter_kind {
AlterKind::ModifyColumnTypes { columns } => columns,
_ => unreachable!(),
};

let change_column_type = change_column_types.pop().unwrap();
assert_eq!("mem_usage", change_column_type.column_name);
let modify_column_type = modify_column_types.pop().unwrap();
assert_eq!("mem_usage", modify_column_type.column_name);
assert_eq!(
ConcreteDataType::string_datatype(),
change_column_type.target_type
modify_column_type.target_type
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/common/meta/src/ddl/alter_table/region_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn create_proto_alter_kind(
add_columns,
})))
}
Kind::ChangeColumnTypes(x) => Ok(Some(alter_request::Kind::ChangeColumnTypes(x.clone()))),
Kind::ModifyColumnTypes(x) => Ok(Some(alter_request::Kind::ModifyColumnTypes(x.clone()))),
Kind::DropColumns(x) => {
let drop_columns = x
.drop_columns
Expand Down Expand Up @@ -123,8 +123,8 @@ mod tests {
use api::v1::region::region_request::Body;
use api::v1::region::RegionColumnDef;
use api::v1::{
region, AddColumn, AddColumnLocation, AddColumns, AlterExpr, ChangeColumnType,
ChangeColumnTypes, ColumnDataType, ColumnDef as PbColumnDef, SemanticType,
region, AddColumn, AddColumnLocation, AddColumns, AlterExpr, ColumnDataType,
ColumnDef as PbColumnDef, ModifyColumnType, ModifyColumnTypes, SemanticType,
};
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
use store_api::storage::{RegionId, TableId};
Expand Down Expand Up @@ -284,8 +284,8 @@ mod tests {
catalog_name: DEFAULT_CATALOG_NAME.to_string(),
schema_name: DEFAULT_SCHEMA_NAME.to_string(),
table_name,
kind: Some(Kind::ChangeColumnTypes(ChangeColumnTypes {
change_column_types: vec![ChangeColumnType {
kind: Some(Kind::ModifyColumnTypes(ModifyColumnTypes {
modify_column_types: vec![ModifyColumnType {
column_name: "cpu".to_string(),
target_type: ColumnDataType::String as i32,
target_type_extension: None,
Expand All @@ -306,9 +306,9 @@ mod tests {
assert_eq!(alter_region_request.schema_version, 1);
assert_eq!(
alter_region_request.kind,
Some(region::alter_request::Kind::ChangeColumnTypes(
ChangeColumnTypes {
change_column_types: vec![ChangeColumnType {
Some(region::alter_request::Kind::ModifyColumnTypes(
ModifyColumnTypes {
modify_column_types: vec![ModifyColumnType {
column_name: "cpu".to_string(),
target_type: ColumnDataType::String as i32,
target_type_extension: None,
Expand Down
2 changes: 1 addition & 1 deletion src/common/meta/src/ddl/alter_table/update_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl AlterTableProcedure {
new_info.name = new_table_name.to_string();
}
AlterKind::DropColumns { .. }
| AlterKind::ChangeColumnTypes { .. }
| AlterKind::ModifyColumnTypes { .. }
| AlterKind::ChangeTableOptions { .. }
| AlterKind::ChangeColumnFulltext { .. } => {}
}
Expand Down
28 changes: 14 additions & 14 deletions src/operator/src/expr_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use api::helper::ColumnDataTypeWrapper;
use api::v1::alter_expr::Kind;
use api::v1::column_def::options_from_column_schema;
use api::v1::{
AddColumn, AddColumns, AlterExpr, Analyzer, ChangeColumnFulltext, ChangeColumnType,
ChangeColumnTypes, ChangeTableOptions, ColumnDataType, ColumnDataTypeExtension, CreateFlowExpr,
CreateTableExpr, CreateViewExpr, DropColumn, DropColumns, ExpireAfter, RenameTable,
AddColumn, AddColumns, AlterExpr, Analyzer, ChangeColumnFulltext, ChangeTableOptions,
ColumnDataType, ColumnDataTypeExtension, CreateFlowExpr, CreateTableExpr, CreateViewExpr,
DropColumn, DropColumns, ExpireAfter, ModifyColumnType, ModifyColumnTypes, RenameTable,
SemanticType, TableName,
};
use common_error::ext::BoxedError;
Expand Down Expand Up @@ -501,7 +501,7 @@ pub(crate) fn to_alter_expr(
location: location.as_ref().map(From::from),
}],
}),
AlterTableOperation::ChangeColumnType {
AlterTableOperation::ModifyColumnType {
column_name,
target_type,
} => {
Expand All @@ -510,8 +510,8 @@ pub(crate) fn to_alter_expr(
let (target_type, target_type_extension) = ColumnDataTypeWrapper::try_from(target_type)
.map(|w| w.to_parts())
.context(ColumnDataTypeSnafu)?;
Kind::ChangeColumnTypes(ChangeColumnTypes {
change_column_types: vec![ChangeColumnType {
Kind::ModifyColumnTypes(ModifyColumnTypes {
modify_column_types: vec![ModifyColumnType {
column_name: column_name.value,
target_type: target_type as i32,
target_type_extension,
Expand Down Expand Up @@ -803,7 +803,7 @@ mod tests {
}

#[test]
fn test_to_alter_change_column_type_expr() {
fn test_to_alter_modify_column_type_expr() {
let sql = "ALTER TABLE monitor MODIFY COLUMN mem_usage STRING;";
let stmt =
ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default())
Expand All @@ -819,22 +819,22 @@ mod tests {
let expr = to_alter_expr(alter_table.clone(), &QueryContext::arc()).unwrap();
let kind = expr.kind.unwrap();

let Kind::ChangeColumnTypes(ChangeColumnTypes {
change_column_types,
let Kind::ModifyColumnTypes(ModifyColumnTypes {
modify_column_types,
}) = kind
else {
unreachable!()
};

assert_eq!(1, change_column_types.len());
let change_column_type = &change_column_types[0];
assert_eq!(1, modify_column_types.len());
let modify_column_type = &modify_column_types[0];

assert_eq!("mem_usage", change_column_type.column_name);
assert_eq!("mem_usage", modify_column_type.column_name);
assert_eq!(
ColumnDataType::String as i32,
change_column_type.target_type
modify_column_type.target_type
);
assert!(change_column_type.target_type_extension.is_none());
assert!(modify_column_type.target_type_extension.is_none());
}

fn new_test_table_names() -> Vec<TableName> {
Expand Down
16 changes: 8 additions & 8 deletions src/sql/src/parsers/alter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ParserContext<'_> {
self.parse_alter_column_fulltext(column_name)
} else {
let data_type = self.parser.parse_data_type().context(error::SyntaxSnafu)?;
Ok(AlterTableOperation::ChangeColumnType {
Ok(AlterTableOperation::ModifyColumnType {
column_name,
target_type: data_type,
})
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {
}

#[test]
fn test_parse_alter_change_column_type() {
fn test_parse_alter_modify_column_type() {
let sql_1 = "ALTER TABLE my_metric_1 MODIFY COLUMN a STRING";
let result_1 = ParserContext::create_with_dialect(
sql_1,
Expand Down Expand Up @@ -427,10 +427,10 @@ mod tests {
let alter_operation = alter_table.alter_operation();
assert_matches!(
alter_operation,
AlterTableOperation::ChangeColumnType { .. }
AlterTableOperation::ModifyColumnType { .. }
);
match alter_operation {
AlterTableOperation::ChangeColumnType {
AlterTableOperation::ModifyColumnType {
column_name,
target_type,
} => {
Expand Down Expand Up @@ -461,10 +461,10 @@ mod tests {
let alter_operation = alter_table.alter_operation();
assert_matches!(
alter_operation,
AlterTableOperation::ChangeColumnType { .. }
AlterTableOperation::ModifyColumnType { .. }
);
match alter_operation {
AlterTableOperation::ChangeColumnType {
AlterTableOperation::ModifyColumnType {
column_name,
target_type,
} => {
Expand Down Expand Up @@ -492,10 +492,10 @@ mod tests {
let alter_operation = alter_table.alter_operation();
assert_matches!(
alter_operation,
AlterTableOperation::ChangeColumnType { .. }
AlterTableOperation::ModifyColumnType { .. }
);
match alter_operation {
AlterTableOperation::ChangeColumnType {
AlterTableOperation::ModifyColumnType {
column_name,
target_type,
} => {
Expand Down
4 changes: 2 additions & 2 deletions src/sql/src/statements/alter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub enum AlterTableOperation {
location: Option<AddColumnLocation>,
},
/// `MODIFY <column_name> [target_type]`
ChangeColumnType {
ModifyColumnType {
column_name: Ident,
target_type: DataType,
},
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Display for AlterTableOperation {
AlterTableOperation::RenameTable { new_table_name } => {
write!(f, r#"RENAME {new_table_name}"#)
}
AlterTableOperation::ChangeColumnType {
AlterTableOperation::ModifyColumnType {
column_name,
target_type,
} => {
Expand Down
2 changes: 1 addition & 1 deletion src/sql/src/statements/transform/type_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TransformRule for TypeAliasTransformRule {
.for_each(|column| replace_type_alias(column.mut_data_type()));
}
Statement::Alter(alter_table) => {
if let AlterTableOperation::ChangeColumnType { target_type, .. } =
if let AlterTableOperation::ModifyColumnType { target_type, .. } =
alter_table.alter_operation_mut()
{
replace_type_alias(target_type)
Expand Down
12 changes: 6 additions & 6 deletions src/store-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize};
use snafu::{ensure, Location, OptionExt, ResultExt, Snafu};

use crate::region_request::{AddColumn, AddColumnLocation, AlterKind, ChangeColumnType};
use crate::region_request::{AddColumn, AddColumnLocation, AlterKind, ModifyColumnType};
use crate::storage::consts::is_internal_column;
use crate::storage::{ColumnId, RegionId};

Expand Down Expand Up @@ -552,7 +552,7 @@ impl RegionMetadataBuilder {
match kind {
AlterKind::AddColumns { columns } => self.add_columns(columns)?,
AlterKind::DropColumns { names } => self.drop_columns(&names),
AlterKind::ChangeColumnTypes { columns } => self.change_column_types(columns),
AlterKind::ModifyColumnTypes { columns } => self.modify_column_types(columns),
AlterKind::ChangeColumnFulltext {
column_name,
options,
Expand Down Expand Up @@ -642,11 +642,11 @@ impl RegionMetadataBuilder {
}

/// Changes columns type to the metadata if exist.
fn change_column_types(&mut self, columns: Vec<ChangeColumnType>) {
fn modify_column_types(&mut self, columns: Vec<ModifyColumnType>) {
let mut change_type_map: HashMap<_, _> = columns
.into_iter()
.map(
|ChangeColumnType {
|ModifyColumnType {
column_name,
target_type,
}| (column_name, target_type),
Expand Down Expand Up @@ -1265,8 +1265,8 @@ mod test {

let mut builder = RegionMetadataBuilder::from_existing(metadata);
builder
.alter(AlterKind::ChangeColumnTypes {
columns: vec![ChangeColumnType {
.alter(AlterKind::ModifyColumnTypes {
columns: vec![ModifyColumnType {
column_name: "b".to_string(),
target_type: ConcreteDataType::string_datatype(),
}],
Expand Down
Loading

0 comments on commit a2852af

Please sign in to comment.