Skip to content

Commit

Permalink
forbid string index length <= 0, ent issue 1685 (vesoft-inc#2024)
Browse files Browse the repository at this point in the history
Co-authored-by: Doodle <13706157+critical27@users.noreply.github.com>
  • Loading branch information
nebula-bots and critical27 authored Dec 28, 2022
1 parent 4ceb23d commit b2b0d85
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/meta/processors/index/CreateEdgeIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) {
return;
}
if (col.type.get_type() == nebula::cpp2::PropertyType::FIXED_STRING) {
if (*col.type.get_type_length() > MAX_INDEX_TYPE_LENGTH) {
LOG(INFO) << "Unsupported index type lengths greater than " << MAX_INDEX_TYPE_LENGTH
<< " : " << field.get_name();
if (field.get_type_length() != nullptr) {
LOG(INFO) << "Length should not be specified of fixed_string index :" << field.get_name();
handleErrorCode(nebula::cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
Expand All @@ -167,6 +166,12 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) {
onFinished();
return;
}
if (*field.get_type_length() <= 0) {
LOG(INFO) << "Unsupported index type length <= 0: " << field.get_name();
handleErrorCode(nebula::cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
}
col.type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING;
col.type.type_length_ref() = *field.get_type_length();
} else if (field.type_length_ref().has_value()) {
Expand Down
11 changes: 8 additions & 3 deletions src/meta/processors/index/CreateTagIndexProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) {
return;
}
if (col.type.get_type() == nebula::cpp2::PropertyType::FIXED_STRING) {
if (*col.type.get_type_length() > MAX_INDEX_TYPE_LENGTH) {
LOG(INFO) << "Unsupported index type lengths greater than " << MAX_INDEX_TYPE_LENGTH
<< " : " << field.get_name();
if (field.get_type_length() != nullptr) {
LOG(INFO) << "Length should not be specified of fixed_string index :" << field.get_name();
handleErrorCode(nebula::cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
Expand All @@ -166,6 +165,12 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) {
onFinished();
return;
}
if (*field.get_type_length() <= 0) {
LOG(INFO) << "Unsupported index type length <= 0 : " << field.get_name();
handleErrorCode(nebula::cpp2::ErrorCode::E_UNSUPPORTED);
onFinished();
return;
}
col.type.type_ref() = nebula::cpp2::PropertyType::FIXED_STRING;
col.type.type_length_ref() = *field.get_type_length();
} else if (field.type_length_ref().has_value()) {
Expand Down
30 changes: 30 additions & 0 deletions tests/tck/features/index/Index.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,16 @@ Feature: IndexTest_Vid_String
CREATE EDGE INDEX string_index_with_no_length ON e1(col4);
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE TAG INDEX string_index_with_length_0 ON t1(col4(0));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE EDGE INDEX string_index_with_length_0 ON e1(col4(0));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE TAG INDEX string_index_too_long ON t1(col4(257));
Expand All @@ -2187,6 +2197,26 @@ Feature: IndexTest_Vid_String
CREATE EDGE INDEX string_index_too_long ON e1(col4(257));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE TAG INDEX fixed_string_index_with_length_0 ON t1(col8(0));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE EDGE INDEX fixed_string_index_with_length_0 ON e1(col8(0));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE TAG INDEX fixed_string_index_with_length_10 ON t1(col8(10));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE EDGE INDEX fixed_string_index_with_length_10 ON e1(col8(10));
"""
Then a ExecutionError should be raised at runtime:
When executing query:
"""
CREATE TAG INDEX index_with_too_many_properties ON t1(col1, col2, col3, col4(10), col5, col6, col7, col8, col9, col10, col11, col12, col13, col14, col15, col16, col17, col18);
Expand Down

0 comments on commit b2b0d85

Please sign in to comment.