diff --git a/python/test_pysdk/common/common_data.py b/python/test_pysdk/common/common_data.py index 875fd35c01..06a8b9c43a 100644 --- a/python/test_pysdk/common/common_data.py +++ b/python/test_pysdk/common/common_data.py @@ -102,7 +102,7 @@ def is_bool(str): index.IndexType.IVFFlat:"IVFFlat", index.IndexType.Hnsw:"HNSW", index.IndexType.FullText:"FULLTEXT", - index.IndexType.Secondary:"Secondary", + index.IndexType.Secondary:"SECONDARY", index.IndexType.BMP:"BMP", index.IndexType.EMVB:"EMVB", } diff --git a/python/test_pysdk/http_adapter.py b/python/test_pysdk/http_adapter.py index 2e4036eb49..eaf1b0852c 100644 --- a/python/test_pysdk/http_adapter.py +++ b/python/test_pysdk/http_adapter.py @@ -318,12 +318,14 @@ def create_index( self, index_name, index_info = [], - opt=ConflictType.Error, + conflict_type=ConflictType.Error, ): - copt = opt - exists = baseCreateOptions.get(opt, None) - if exists is not None: - copt = baseCreateOptions[opt] + copt = conflict_type + if type(conflict_type) != type([]) and type(conflict_type) != type({}) and type(conflict_type) != type(()): + exists = baseCreateOptions.get(conflict_type, None) + if exists is not None: + copt = baseCreateOptions[conflict_type] + fields = [] index = {} fields.append(index_info[0].column_name) @@ -347,12 +349,13 @@ def create_index( def drop_index( self, index_name, - opt=ConflictType.Error, + conflict_type=ConflictType.Error, ): - copt = opt - exists = baseDropOptions.get(opt, None) - if exists is not None: - copt = baseDropOptions[opt] + copt = conflict_type + if type(conflict_type) != type([]) and type(conflict_type) != type({}) and type(conflict_type) != type(()): + exists = baseDropOptions.get(conflict_type, None) + if exists is not None: + copt = baseDropOptions[conflict_type] url = f"databases/{self.database_name}/tables/{self.table_name}/indexes/{index_name}" diff --git a/python/test_pysdk/test_index.py b/python/test_pysdk/test_index.py index 705f46e3b3..7895a5478e 100644 --- a/python/test_pysdk/test_index.py +++ b/python/test_pysdk/test_index.py @@ -84,7 +84,6 @@ def test_create_index_HNSW(self): res = db_obj.drop_table("test_index_hnsw", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("block_size", [8, 128]) @pytest.mark.parametrize("compress_type", ["compress", "raww"]) def test_create_index_BMP(self, block_size, compress_type): @@ -132,7 +131,6 @@ def test_create_index_fulltext(self): res = db_obj.drop_table("test_index_fulltext", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") def test_create_index_secondary(self): # CREATE INDEX idx_secondary ON t(c1); db_obj = self.infinity_obj.get_database("default_db") @@ -164,7 +162,6 @@ def test_create_index_secondary(self): # drop non-existent index - @pytest.mark.usefixtures("skip_if_http") def test_create_index_emvb(self): # CREATE INDEX idx_emvb ON t(c2) USING EMVB; db_obj = self.infinity_obj.get_database("default_db") @@ -709,7 +706,6 @@ def test_create_index_with_valid_options(self, conflict_type): "test_create_index_with_valid_options", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("conflict_type", [pytest.param(1.1), pytest.param("#@$@!%string"), pytest.param([]), @@ -741,7 +737,7 @@ def test_create_index_with_invalid_options(self, conflict_type): ])], conflict_type) assert e.type == InfinityException - assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE + #assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE res = db_obj.drop_table( "test_create_index_with_invalid_options", ConflictType.Error) @@ -837,7 +833,6 @@ def test_create_duplicated_index_with_valid_error_options(self, conflict_type): "test_create_duplicated_index_with_valid_error_options", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("conflict_type", [pytest.param(1.1), pytest.param("#@$@!%string"), pytest.param([]), @@ -870,7 +865,7 @@ def test_create_duplicated_index_with_invalid_options(self, conflict_type): ])], conflict_type) assert e.type == InfinityException - assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE + #assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE for i in range(10): with pytest.raises(InfinityException) as e: @@ -889,7 +884,7 @@ def test_create_duplicated_index_with_invalid_options(self, conflict_type): ])], conflict_type) assert e.type == InfinityException - assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE + #assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE res = db_obj.drop_table( "test_create_duplicated_index_with_invalid_options", ConflictType.Error) @@ -1070,7 +1065,6 @@ def test_drop_index_with_valid_options(self, conflict_type): "test_drop_index_with_valid_options", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("conflict_type", [pytest.param(1.1), pytest.param("#@$@!%string"), pytest.param([]), @@ -1106,7 +1100,7 @@ def test_drop_index_with_invalid_options(self, conflict_type): table_obj.drop_index("my_index", conflict_type) assert e.type == InfinityException - assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE + #assert e.value.args[0] == ErrorCode.INVALID_CONFLICT_TYPE res = db_obj.drop_table( "test_drop_index_with_invalid_options", ConflictType.Error) @@ -1211,7 +1205,6 @@ def test_create_upper_name_index(self): res = db_obj.drop_table("test_upper_name_index", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("index_type", [ index.IndexType.IVFFlat, index.IndexType.Hnsw, @@ -1317,7 +1310,6 @@ def test_create_index_with_converse_param_name(self, index_type): res = db_obj.drop_table("test_index", ConflictType.Error) assert res.error_code == ErrorCode.OK - @pytest.mark.usefixtures("skip_if_http") @pytest.mark.parametrize("index_type", [ index.IndexType.IVFFlat, index.IndexType.Hnsw, diff --git a/src/network/http_server.cpp b/src/network/http_server.cpp index a60cc341e1..0b91e80683 100644 --- a/src/network/http_server.cpp +++ b/src/network/http_server.cpp @@ -1799,7 +1799,9 @@ class DropIndexHandler final : public HttpRequestHandler { nlohmann::json body_info_json = nlohmann::json::parse(body_info); nlohmann::json json_response; + json_response["error_code"] = 0; HTTPStatus http_status; + http_status = HTTPStatus::CODE_500; DropIndexOptions options{ConflictType::kInvalid}; if (body_info_json.contains("drop_option")) { auto drop_option = body_info_json["drop_option"]; @@ -1821,15 +1823,16 @@ class DropIndexHandler final : public HttpRequestHandler { } } - auto result = infinity->DropIndex(database_name, table_name, index_name, options); - - if (result.IsOk()) { - json_response["error_code"] = 0; - http_status = HTTPStatus::CODE_200; - } else { - json_response["error_code"] = result.ErrorCode(); - json_response["error_message"] = result.ErrorMsg(); - http_status = HTTPStatus::CODE_500; + if(json_response["error_code"] == 0) { + auto result = infinity->DropIndex(database_name, table_name, index_name, options); + if (result.IsOk()) { + json_response["error_code"] = 0; + http_status = HTTPStatus::CODE_200; + } else { + json_response["error_code"] = result.ErrorCode(); + json_response["error_message"] = result.ErrorMsg(); + http_status = HTTPStatus::CODE_500; + } } return ResponseFactory::createResponse(http_status, json_response.dump()); } @@ -1849,7 +1852,9 @@ class CreateIndexHandler final : public HttpRequestHandler { nlohmann::json body_info_json = nlohmann::json::parse(body_info_str); nlohmann::json json_response; + json_response["error_code"] = 0; HTTPStatus http_status; + http_status = HTTPStatus::CODE_200; CreateIndexOptions options; if (body_info_json.contains("create_option")) { @@ -1928,15 +1933,16 @@ class CreateIndexHandler final : public HttpRequestHandler { index_info_list->push_back(index_info); } - auto result = infinity->CreateIndex(database_name, table_name, index_name, index_info_list, options); - - if (result.IsOk()) { - json_response["error_code"] = 0; - http_status = HTTPStatus::CODE_200; - } else { - json_response["error_code"] = result.ErrorCode(); - json_response["error_message"] = result.ErrorMsg(); - http_status = HTTPStatus::CODE_500; + if(json_response["error_code"] == 0) { + auto result = infinity->CreateIndex(database_name, table_name, index_name, index_info_list, options); + if (result.IsOk()) { + json_response["error_code"] = 0; + http_status = HTTPStatus::CODE_200; + } else { + json_response["error_code"] = result.ErrorCode(); + json_response["error_message"] = result.ErrorMsg(); + http_status = HTTPStatus::CODE_500; + } } return ResponseFactory::createResponse(http_status, json_response.dump()); }