Skip to content

Commit

Permalink
show analyzer when show ft index (#5587)
Browse files Browse the repository at this point in the history
* show analyzer when show ft index

* fix tck
  • Loading branch information
cangfengzhs committed Jun 12, 2023
1 parent b3c5086 commit 8a49260
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
7 changes: 6 additions & 1 deletion src/graph/executor/maintain/FTIndexExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ folly::Future<Status> ShowFTIndexesExecutor::execute() {

auto indexes = std::move(resp).value();
DataSet dataSet;
dataSet.colNames = {"Name", "Schema Type", "Schema Name", "Fields"};
dataSet.colNames = {"Name", "Schema Type", "Schema Name", "Fields", "Analyzer"};
for (auto &index : indexes) {
if (index.second.get_space_id() != spaceId) {
continue;
Expand All @@ -92,6 +92,11 @@ folly::Future<Status> ShowFTIndexesExecutor::execute() {
row.values.emplace_back(isEdge ? "Edge" : "Tag");
row.values.emplace_back(std::move(shmNameRet).value());
row.values.emplace_back(std::move(fields));
std::string analyzer = index.second.get_analyzer();
if (analyzer.empty()) {
analyzer = "default";
}
row.values.emplace_back(analyzer);
dataSet.rows.emplace_back(std::move(row));
}
return finish(ResultBuilder()
Expand Down
4 changes: 3 additions & 1 deletion src/meta/processors/BaseProcessor-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ nebula::cpp2::ErrorCode BaseProcessor<RESP>::ftIndexCheck(
const std::vector<cpp2::AlterSchemaItem>& alterItems) {
std::set<std::string> cols;
for (auto& [indexName, index] : ftIndices) {
cols.insert(index.fields_ref()->front());
for (auto& field : *index.fields_ref()) {
cols.insert(field);
}
}
for (const auto& item : alterItems) {
if (*item.op_ref() == nebula::meta::cpp2::AlterSchemaOp::CHANGE ||
Expand Down
5 changes: 5 additions & 0 deletions src/meta/processors/index/FTIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void CreateFTIndexProcessor::process(const cpp2::CreateFTIndexReq& req) {

// verify the columns.
auto schema = MetaKeyUtils::parseSchema(iter->val());
if (schema.get_schema_prop().get_ttl_col() && !schema.get_schema_prop().get_ttl_col()->empty()) {
handleErrorCode(nebula::cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
}
auto columns = schema.get_columns();
for (const auto& col : index.get_fields()) {
auto targetCol = std::find_if(
Expand Down
36 changes: 19 additions & 17 deletions src/meta/processors/schema/AlterTagProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
}

auto indexes = std::move(nebula::value(iCode));

auto existIndex = !indexes.empty();
if (existIndex) {
auto iStatus = indexCheck(indexes, tagItems);
Expand All @@ -81,11 +82,28 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
return;
}
}
// Check fulltext index
auto ftIdxRet = getFTIndex(spaceId, tagId);
bool existFTIndex = false;
if (nebula::ok(ftIdxRet)) {
auto fti = std::move(nebula::value(ftIdxRet));
existFTIndex = !fti.empty();
auto ftStatus = ftIndexCheck(fti, tagItems);
if (ftStatus != nebula::cpp2::ErrorCode::SUCCEEDED) {
handleErrorCode(ftStatus);
onFinished();
return;
}
} else if (nebula::error(ftIdxRet) != nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND) {
handleErrorCode(nebula::error(ftIdxRet));
onFinished();
return;
}

auto& alterSchemaProp = req.get_schema_prop();

// If index exist, could not alter ttl column
if (existIndex) {
if (existIndex || existFTIndex) {
int64_t duration = 0;
if (alterSchemaProp.get_ttl_duration()) {
duration = *alterSchemaProp.get_ttl_duration();
Expand All @@ -102,22 +120,6 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) {
}
}

// Check fulltext index
auto ftIdxRet = getFTIndex(spaceId, tagId);
if (nebula::ok(ftIdxRet)) {
auto fti = std::move(nebula::value(ftIdxRet));
auto ftStatus = ftIndexCheck(fti, tagItems);
if (ftStatus != nebula::cpp2::ErrorCode::SUCCEEDED) {
handleErrorCode(ftStatus);
onFinished();
return;
}
} else if (nebula::error(ftIdxRet) != nebula::cpp2::ErrorCode::E_INDEX_NOT_FOUND) {
handleErrorCode(nebula::error(ftIdxRet));
onFinished();
return;
}

for (auto& tagItem : tagItems) {
auto& cols = tagItem.get_schema().get_columns();
for (auto& col : cols) {
Expand Down
12 changes: 6 additions & 6 deletions tests/tck/features/fulltext_index/FultextIndexDDL.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Feature: FulltextIndexTest
SHOW FULLTEXT INDEXES;
"""
Then the result should be, in any order:
| Name | Schema Type | Schema Name | Fields |
| "nebula_index_ddl_tag_prop1" | "Tag" | "ddl_tag" | "prop1" |
| "nebula_index_ddl_tag_prop2" | "Tag" | "ddl_tag" | "prop2" |
| Name | Schema Type | Schema Name | Fields | Analyzer |
| "nebula_index_ddl_tag_prop1" | "Tag" | "ddl_tag" | "prop1" | "default" |
| "nebula_index_ddl_tag_prop2" | "Tag" | "ddl_tag" | "prop2" | "default" |
When executing query:
"""
DROP FULLTEXT INDEX nebula_index_ddl_tag_prop1;
Expand All @@ -58,7 +58,7 @@ Feature: FulltextIndexTest
SHOW FULLTEXT INDEXES;
"""
Then the result should be, in any order:
| Name | Schema Type | Schema Name | Fields |
| Name | Schema Type | Schema Name | Fields | Analyzer |
When executing query:
"""
CREATE FULLTEXT TAG INDEX nebula_index_ddl_tag_prop1 on ddl_tag(prop2);
Expand All @@ -69,8 +69,8 @@ Feature: FulltextIndexTest
SHOW FULLTEXT INDEXES;
"""
Then the result should be, in any order:
| Name | Schema Type | Schema Name | Fields |
| "nebula_index_ddl_tag_prop1" | "Tag" | "ddl_tag" | "prop2" |
| Name | Schema Type | Schema Name | Fields | Analyzer |
| "nebula_index_ddl_tag_prop1" | "Tag" | "ddl_tag" | "prop2" | "default" |
When executing query:
"""
DROP TAG ddl_tag;
Expand Down

0 comments on commit 8a49260

Please sign in to comment.