Skip to content

Commit ec7a850

Browse files
committed
feat: pick #6416 to release/0.15
Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
1 parent f712c1b commit ec7a850

40 files changed

Lines changed: 962 additions & 409 deletions

Cargo.lock

Lines changed: 4 additions & 4 deletions
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
@@ -134,7 +134,7 @@ etcd-client = "0.14"
134134
fst = "0.4.7"
135135
futures = "0.3"
136136
futures-util = "0.3"
137-
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", rev = "82fe5c6282f623c185b86f03e898ee8952e50cf9" }
137+
greptime-proto = { git = "https://github.com/GreptimeTeam/greptime-proto.git", branch = "zhongzc/pick-index-options" }
138138
hex = "0.4"
139139
http = "1"
140140
humantime = "2.1"

src/api/src/v1/column_def.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,20 @@ mod tests {
226226
assert!(options.is_none());
227227

228228
let mut schema = ColumnSchema::new("test", ConcreteDataType::string_datatype(), true)
229-
.with_fulltext_options(FulltextOptions {
230-
enable: true,
231-
analyzer: FulltextAnalyzer::English,
232-
case_sensitive: false,
233-
backend: FulltextBackend::Bloom,
234-
})
229+
.with_fulltext_options(FulltextOptions::new_unchecked(
230+
true,
231+
FulltextAnalyzer::English,
232+
false,
233+
FulltextBackend::Bloom,
234+
10240,
235+
0.01,
236+
))
235237
.unwrap();
236238
schema.set_inverted_index(true);
237239
let options = options_from_column_schema(&schema).unwrap();
238240
assert_eq!(
239241
options.options.get(FULLTEXT_GRPC_KEY).unwrap(),
240-
"{\"enable\":true,\"analyzer\":\"English\",\"case-sensitive\":false,\"backend\":\"bloom\"}"
242+
"{\"enable\":true,\"analyzer\":\"English\",\"case-sensitive\":false,\"backend\":\"bloom\",\"granularity\":10240,\"false-positive-rate-in-10000\":100}"
241243
);
242244
assert_eq!(
243245
options.options.get(INVERTED_INDEX_GRPC_KEY).unwrap(),
@@ -247,16 +249,18 @@ mod tests {
247249

248250
#[test]
249251
fn test_options_with_fulltext() {
250-
let fulltext = FulltextOptions {
251-
enable: true,
252-
analyzer: FulltextAnalyzer::English,
253-
case_sensitive: false,
254-
backend: FulltextBackend::Bloom,
255-
};
252+
let fulltext = FulltextOptions::new_unchecked(
253+
true,
254+
FulltextAnalyzer::English,
255+
false,
256+
FulltextBackend::Bloom,
257+
10240,
258+
0.01,
259+
);
256260
let options = options_from_fulltext(&fulltext).unwrap().unwrap();
257261
assert_eq!(
258262
options.options.get(FULLTEXT_GRPC_KEY).unwrap(),
259-
"{\"enable\":true,\"analyzer\":\"English\",\"case-sensitive\":false,\"backend\":\"bloom\"}"
263+
"{\"enable\":true,\"analyzer\":\"English\",\"case-sensitive\":false,\"backend\":\"bloom\",\"granularity\":10240,\"false-positive-rate-in-10000\":100}"
260264
);
261265
}
262266

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use table::requests::{
3434
};
3535

3636
use crate::error::{
37-
InvalidColumnDefSnafu, InvalidSetFulltextOptionRequestSnafu,
37+
InvalidColumnDefSnafu, InvalidIndexOptionSnafu, InvalidSetFulltextOptionRequestSnafu,
3838
InvalidSetSkippingIndexOptionRequestSnafu, InvalidSetTableOptionRequestSnafu,
3939
InvalidUnsetTableOptionRequestSnafu, MissingAlterIndexOptionSnafu, MissingFieldSnafu,
4040
MissingTimestampColumnSnafu, Result, UnknownLocationTypeSnafu,
@@ -126,18 +126,21 @@ pub fn alter_expr_to_request(table_id: TableId, expr: AlterTableExpr) -> Result<
126126
api::v1::set_index::Options::Fulltext(f) => AlterKind::SetIndex {
127127
options: SetIndexOptions::Fulltext {
128128
column_name: f.column_name.clone(),
129-
options: FulltextOptions {
130-
enable: f.enable,
131-
analyzer: as_fulltext_option_analyzer(
129+
options: FulltextOptions::new(
130+
f.enable,
131+
as_fulltext_option_analyzer(
132132
Analyzer::try_from(f.analyzer)
133133
.context(InvalidSetFulltextOptionRequestSnafu)?,
134134
),
135-
case_sensitive: f.case_sensitive,
136-
backend: as_fulltext_option_backend(
135+
f.case_sensitive,
136+
as_fulltext_option_backend(
137137
PbFulltextBackend::try_from(f.backend)
138138
.context(InvalidSetFulltextOptionRequestSnafu)?,
139139
),
140-
},
140+
f.granularity as u32,
141+
f.false_positive_rate,
142+
)
143+
.context(InvalidIndexOptionSnafu)?,
141144
},
142145
},
143146
api::v1::set_index::Options::Inverted(i) => AlterKind::SetIndex {
@@ -148,13 +151,15 @@ pub fn alter_expr_to_request(table_id: TableId, expr: AlterTableExpr) -> Result<
148151
api::v1::set_index::Options::Skipping(s) => AlterKind::SetIndex {
149152
options: SetIndexOptions::Skipping {
150153
column_name: s.column_name,
151-
options: SkippingIndexOptions {
152-
granularity: s.granularity as u32,
153-
index_type: as_skipping_index_type(
154+
options: SkippingIndexOptions::new(
155+
s.granularity as u32,
156+
s.false_positive_rate,
157+
as_skipping_index_type(
154158
PbSkippingIndexType::try_from(s.skipping_index_type)
155159
.context(InvalidSetSkippingIndexOptionRequestSnafu)?,
156160
),
157-
},
161+
)
162+
.context(InvalidIndexOptionSnafu)?,
158163
},
159164
},
160165
},

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ pub enum Error {
153153
#[snafu(implicit)]
154154
location: Location,
155155
},
156+
157+
#[snafu(display("Invalid index option"))]
158+
InvalidIndexOption {
159+
#[snafu(implicit)]
160+
location: Location,
161+
#[snafu(source)]
162+
error: datatypes::error::Error,
163+
},
156164
}
157165

158166
pub type Result<T> = std::result::Result<T, Error>;
@@ -180,7 +188,8 @@ impl ErrorExt for Error {
180188
| Error::InvalidUnsetTableOptionRequest { .. }
181189
| Error::InvalidSetFulltextOptionRequest { .. }
182190
| Error::InvalidSetSkippingIndexOptionRequest { .. }
183-
| Error::MissingAlterIndexOption { .. } => StatusCode::InvalidArguments,
191+
| Error::MissingAlterIndexOption { .. }
192+
| Error::InvalidIndexOption { .. } => StatusCode::InvalidArguments,
184193
}
185194
}
186195

src/datatypes/src/schema.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ pub use crate::schema::column_schema::{
3131
ColumnSchema, FulltextAnalyzer, FulltextBackend, FulltextOptions, Metadata,
3232
SkippingIndexOptions, SkippingIndexType, COLUMN_FULLTEXT_CHANGE_OPT_KEY_ENABLE,
3333
COLUMN_FULLTEXT_OPT_KEY_ANALYZER, COLUMN_FULLTEXT_OPT_KEY_BACKEND,
34-
COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, COLUMN_SKIPPING_INDEX_OPT_KEY_GRANULARITY,
35-
COLUMN_SKIPPING_INDEX_OPT_KEY_TYPE, COMMENT_KEY, FULLTEXT_KEY, INVERTED_INDEX_KEY,
36-
SKIPPING_INDEX_KEY, TIME_INDEX_KEY,
34+
COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE, COLUMN_FULLTEXT_OPT_KEY_FALSE_POSITIVE_RATE,
35+
COLUMN_FULLTEXT_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_FALSE_POSITIVE_RATE,
36+
COLUMN_SKIPPING_INDEX_OPT_KEY_GRANULARITY, COLUMN_SKIPPING_INDEX_OPT_KEY_TYPE, COMMENT_KEY,
37+
FULLTEXT_KEY, INVERTED_INDEX_KEY, SKIPPING_INDEX_KEY, TIME_INDEX_KEY,
3738
};
3839
pub use crate::schema::constraint::ColumnDefaultConstraint;
3940
pub use crate::schema::raw::RawSchema;

0 commit comments

Comments
 (0)