Skip to content

Commit

Permalink
fix http api bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ami11111 committed Aug 7, 2024
1 parent 5b7b95f commit 8526a56
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion python/test_pysdk/common/common_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
23 changes: 13 additions & 10 deletions python/test_pysdk/http_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}"

Expand Down
16 changes: 4 additions & 12 deletions python/test_pysdk/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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([]),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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([]),
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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([]),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
42 changes: 24 additions & 18 deletions src/network/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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());
}
Expand All @@ -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")) {
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 8526a56

Please sign in to comment.