Skip to content

Commit 84aa5b7

Browse files
CookiePieWwirenjj
andauthored
feat: alter fulltext options (GreptimeTeam#4952)
* feat(WIP): alter fulltext index Co-Authored-By: irenjj <[email protected]> * feat: alter column fulltext option Co-Authored-By: irenjj <[email protected]> * chore: fmt * test: add unit and integration tests Co-Authored-By: irenjj <[email protected]> * test: update sqlness test * chore: new line * chore: lock file update * chore: apply review comments * test: update sqlness test * test: update sqlness test * fix: convert * chore: apply review comments * fix: toml fmt * fix: tests * test: add test for mito * chore: error message * fix: test * fix: test * fix: wrong comment * chore: change proto rev * chore: apply review comments * chore: apply review comments * chore: fmt --------- Co-authored-by: irenjj <[email protected]>
1 parent cbf21e5 commit 84aa5b7

File tree

30 files changed

+1043
-122
lines changed

30 files changed

+1043
-122
lines changed

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ etcd-client = { version = "0.13" }
121121
fst = "0.4.7"
122122
futures = "0.3"
123123
futures-util = "0.3"
124-
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "255f87a3318ace3f88a67f76995a0e14910983f4" }
124+
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "67bb1d52bc1241972c368657e658592b1be7ead3" }
125125
humantime = "2.1"
126126
humantime-serde = "1.1"
127127
itertools = "0.10"

src/api/src/v1/column_def.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
use std::collections::HashMap;
1616

1717
use datatypes::schema::{
18-
ColumnDefaultConstraint, ColumnSchema, FulltextOptions, COMMENT_KEY, FULLTEXT_KEY,
19-
INVERTED_INDEX_KEY,
18+
ColumnDefaultConstraint, ColumnSchema, FulltextAnalyzer, FulltextOptions, COMMENT_KEY,
19+
FULLTEXT_KEY, INVERTED_INDEX_KEY,
2020
};
21+
use greptime_proto::v1::Analyzer;
2122
use snafu::ResultExt;
2223

2324
use crate::error::{self, Result};
@@ -104,6 +105,14 @@ pub fn options_from_fulltext(fulltext: &FulltextOptions) -> Result<Option<Column
104105
Ok((!options.options.is_empty()).then_some(options))
105106
}
106107

108+
/// Tries to construct a `FulltextAnalyzer` from the given analyzer.
109+
pub fn as_fulltext_option(analyzer: Analyzer) -> FulltextAnalyzer {
110+
match analyzer {
111+
Analyzer::English => FulltextAnalyzer::English,
112+
Analyzer::Chinese => FulltextAnalyzer::Chinese,
113+
}
114+
}
115+
107116
#[cfg(test)]
108117
mod tests {
109118

src/common/grpc-expr/src/alter.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
use api::helper::ColumnDataTypeWrapper;
1616
use api::v1::add_column_location::LocationType;
1717
use api::v1::alter_expr::Kind;
18+
use api::v1::column_def::as_fulltext_option;
1819
use api::v1::{
19-
column_def, AddColumnLocation as Location, AlterExpr, ChangeColumnTypes, CreateTableExpr,
20-
DropColumns, RenameTable, SemanticType,
20+
column_def, AddColumnLocation as Location, AlterExpr, Analyzer, ChangeColumnTypes,
21+
CreateTableExpr, DropColumns, RenameTable, SemanticType,
2122
};
2223
use common_query::AddColumnLocation;
23-
use datatypes::schema::{ColumnSchema, RawSchema};
24+
use datatypes::schema::{ColumnSchema, FulltextOptions, RawSchema};
2425
use snafu::{ensure, OptionExt, ResultExt};
2526
use store_api::region_request::ChangeOption;
2627
use table::metadata::TableId;
2728
use table::requests::{AddColumnRequest, AlterKind, AlterTableRequest, ChangeColumnTypeRequest};
2829

2930
use crate::error::{
30-
InvalidChangeTableOptionRequestSnafu, InvalidColumnDefSnafu, MissingFieldSnafu,
31-
MissingTimestampColumnSnafu, Result, UnknownLocationTypeSnafu,
31+
InvalidChangeFulltextOptionRequestSnafu, InvalidChangeTableOptionRequestSnafu,
32+
InvalidColumnDefSnafu, MissingFieldSnafu, MissingTimestampColumnSnafu, Result,
33+
UnknownLocationTypeSnafu,
3234
};
3335

3436
const LOCATION_TYPE_FIRST: i32 = LocationType::First as i32;
@@ -102,6 +104,17 @@ pub fn alter_expr_to_request(table_id: TableId, expr: AlterExpr) -> Result<Alter
102104
.collect::<std::result::Result<Vec<_>, _>>()
103105
.context(InvalidChangeTableOptionRequestSnafu)?,
104106
},
107+
Kind::ChangeColumnFulltext(c) => AlterKind::ChangeColumnFulltext {
108+
column_name: c.column_name,
109+
options: FulltextOptions {
110+
enable: c.enable,
111+
analyzer: as_fulltext_option(
112+
Analyzer::try_from(c.analyzer)
113+
.context(InvalidChangeFulltextOptionRequestSnafu)?,
114+
),
115+
case_sensitive: c.case_sensitive,
116+
},
117+
},
105118
};
106119

107120
let request = AlterTableRequest {

src/common/grpc-expr/src/error.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ pub enum Error {
125125
#[snafu(source)]
126126
error: MetadataError,
127127
},
128+
129+
#[snafu(display("Invalid change fulltext option request"))]
130+
InvalidChangeFulltextOptionRequest {
131+
#[snafu(implicit)]
132+
location: Location,
133+
#[snafu(source)]
134+
error: prost::DecodeError,
135+
},
128136
}
129137

130138
pub type Result<T> = std::result::Result<T, Error>;
@@ -148,7 +156,8 @@ impl ErrorExt for Error {
148156
Error::UnknownColumnDataType { .. } | Error::InvalidFulltextColumnType { .. } => {
149157
StatusCode::InvalidArguments
150158
}
151-
Error::InvalidChangeTableOptionRequest { .. } => StatusCode::InvalidArguments,
159+
Error::InvalidChangeTableOptionRequest { .. }
160+
| Error::InvalidChangeFulltextOptionRequest { .. } => StatusCode::InvalidArguments,
152161
}
153162
}
154163

src/common/meta/src/ddl/alter_table/region_request.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ fn create_proto_alter_kind(
107107
}
108108
Kind::RenameTable(_) => Ok(None),
109109
Kind::ChangeTableOptions(v) => Ok(Some(alter_request::Kind::ChangeTableOptions(v.clone()))),
110+
Kind::ChangeColumnFulltext(v) => {
111+
Ok(Some(alter_request::Kind::ChangeColumnFulltext(v.clone())))
112+
}
110113
}
111114
}
112115

src/common/meta/src/ddl/alter_table/update_metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ impl AlterTableProcedure {
5353
}
5454
AlterKind::DropColumns { .. }
5555
| AlterKind::ChangeColumnTypes { .. }
56-
| AlterKind::ChangeTableOptions { .. } => {}
56+
| AlterKind::ChangeTableOptions { .. }
57+
| AlterKind::ChangeColumnFulltext { .. } => {}
5758
}
5859

5960
Ok(new_info)

src/datatypes/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ paste = "1.0"
3333
serde.workspace = true
3434
serde_json.workspace = true
3535
snafu.workspace = true
36+
sqlparser.workspace = true
37+
sqlparser_derive = "0.1"

src/datatypes/src/error.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ pub enum Error {
212212
#[snafu(implicit)]
213213
location: Location,
214214
},
215+
216+
#[snafu(display("Invalid fulltext option: {}", msg))]
217+
InvalidFulltextOption {
218+
msg: String,
219+
#[snafu(implicit)]
220+
location: Location,
221+
},
215222
}
216223

217224
impl ErrorExt for Error {
@@ -230,7 +237,8 @@ impl ErrorExt for Error {
230237
| DuplicateMeta { .. }
231238
| InvalidTimestampPrecision { .. }
232239
| InvalidPrecisionOrScale { .. }
233-
| InvalidJson { .. } => StatusCode::InvalidArguments,
240+
| InvalidJson { .. }
241+
| InvalidFulltextOption { .. } => StatusCode::InvalidArguments,
234242

235243
ValueExceedsPrecision { .. }
236244
| CastType { .. }

src/datatypes/src/schema.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ use snafu::{ensure, ResultExt};
2727
use crate::error::{self, DuplicateColumnSnafu, Error, ProjectArrowSchemaSnafu, Result};
2828
use crate::prelude::DataType;
2929
pub use crate::schema::column_schema::{
30-
ColumnSchema, FulltextAnalyzer, FulltextOptions, Metadata, COMMENT_KEY, FULLTEXT_KEY,
31-
INVERTED_INDEX_KEY, TIME_INDEX_KEY,
30+
ColumnSchema, FulltextAnalyzer, FulltextOptions, Metadata,
31+
COLUMN_FULLTEXT_CHANGE_OPT_KEY_ENABLE, COLUMN_FULLTEXT_OPT_KEY_ANALYZER,
32+
COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, COMMENT_KEY, FULLTEXT_KEY, INVERTED_INDEX_KEY,
33+
TIME_INDEX_KEY,
3234
};
3335
pub use crate::schema::constraint::ColumnDefaultConstraint;
3436
pub use crate::schema::raw::RawSchema;

0 commit comments

Comments
 (0)