Skip to content

Commit

Permalink
Fix python client
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN committed Oct 16, 2024
1 parent 78f7871 commit b820b29
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 15 deletions.
2 changes: 1 addition & 1 deletion python/infinity_sdk/infinity/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, uri):
self.uri = uri

@abstractmethod
def create_database(self, db_name, options=None):
def create_database(self, db_name, options=None, comment: str = None):
pass

@abstractmethod
Expand Down
8 changes: 7 additions & 1 deletion python/infinity_sdk/infinity/remote_thrift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ def reconnect(self):
raise InfinityException(res.error_code, res.error_msg)
self.session_id = res.session_id

def create_database(self, db_name: str, conflict_type: CreateConflict = CreateConflict.Error):
def create_database(self, db_name: str, conflict_type: CreateConflict = CreateConflict.Error, comment: str = None):
db_comment: str
if comment is None:
db_comment = ""
else:
db_comment = comment
return self.client.CreateDatabase(CreateDatabaseRequest(session_id=self.session_id,
db_name=db_name,
db_comment=db_comment,
create_option=CreateOption(conflict_type=conflict_type)))

def drop_database(self, db_name: str, conflict_type: DropConflict = DropConflict.Error):
Expand Down
6 changes: 3 additions & 3 deletions python/infinity_sdk/infinity/remote_thrift/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __del__(self):
self.disconnect()

@name_validity_check("db_name", "DB")
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error):
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.Error, comment: str = None):
create_database_conflict: ttypes.CreateConflict
if conflict_type == ConflictType.Error:
create_database_conflict = ttypes.CreateConflict.Error
Expand All @@ -46,7 +46,7 @@ def create_database(self, db_name: str, conflict_type: ConflictType = ConflictTy
else:
raise InfinityException(ErrorCode.INVALID_CONFLICT_TYPE, "Invalid conflict type")

res = self._client.create_database(db_name=db_name, conflict_type=create_database_conflict)
res = self._client.create_database(db_name=db_name, conflict_type=create_database_conflict, comment=comment)
if res.error_code == ErrorCode.OK:
return RemoteDatabase(self._client, db_name)
else:
Expand Down Expand Up @@ -77,7 +77,7 @@ def drop_database(self, db_name: str, conflict_type: ConflictType = ConflictType
else:
raise InfinityException(ErrorCode.INVALID_CONFLICT_TYPE, "Invalid conflict type")

res = self._client.drop_database(db_name=db_name, conflict_type = drop_database_conflict)
res = self._client.drop_database(db_name=db_name, conflict_type=drop_database_conflict)
if res.error_code == ErrorCode.OK:
return res
else:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main/infinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void Infinity::RemoteDisconnect() {
session_.reset();
}

QueryResult Infinity::CreateDatabase(const String &schema_name, const CreateDatabaseOptions &create_db_options) {
QueryResult Infinity::CreateDatabase(const String &schema_name, const CreateDatabaseOptions &create_db_options, const String &comment) {
UniquePtr<QueryContext> query_context_ptr = GetQueryContext();
UniquePtr<CreateStatement> create_statement = MakeUnique<CreateStatement>();
SharedPtr<CreateSchemaInfo> create_schema_info = MakeShared<CreateSchemaInfo>();
Expand All @@ -141,6 +141,7 @@ QueryResult Infinity::CreateDatabase(const String &schema_name, const CreateData
ToLower(create_schema_info->schema_name_);
create_statement->create_info_ = create_schema_info;
create_statement->create_info_->conflict_type_ = create_db_options.conflict_type_;
create_statement->create_info_->comment_ = comment;
QueryResult query_result = query_context_ptr->QueryStatement(create_statement.get());
return query_result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/infinity.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public:

void LocalDisconnect();

QueryResult CreateDatabase(const String &db_name, const CreateDatabaseOptions &options);
QueryResult CreateDatabase(const String &db_name, const CreateDatabaseOptions &options, const String& db_comment);

QueryResult DropDatabase(const String &db_name, const DropDatabaseOptions &options);

Expand Down
7 changes: 6 additions & 1 deletion src/network/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,13 @@ class CreateDatabaseHandler final : public HttpRequestHandler {
}
}

String db_comment;
if (body_info_json.contains("comment")) {
db_comment = body_info_json["comment"];
}

// create database
auto result = infinity->CreateDatabase(database_name, options);
auto result = infinity->CreateDatabase(database_name, options, db_comment);

if (result.IsOk()) {
json_response["error_code"] = 0;
Expand Down
20 changes: 20 additions & 0 deletions src/network/infinity_thrift/infinity_types.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/network/infinity_thrift/infinity_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/network/infinity_thrift_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void InfinityThriftService::CreateDatabase(infinity_thrift_rpc::CommonResponse &

auto [infinity, status] = GetInfinityBySessionID(request.session_id);
if (status.ok()) {
auto result = infinity->CreateDatabase(request.db_name, create_database_opts);
auto result = infinity->CreateDatabase(request.db_name, create_database_opts, request.db_comment);
ProcessQueryResult(response, result);
} else {
ProcessStatus(response, status);
Expand Down
7 changes: 4 additions & 3 deletions thrift/infinity.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,10 @@ struct GetDatabaseRequest {
}

struct CreateDatabaseRequest {
1: string db_name,
2: i64 session_id,
3: CreateOption create_option,
1: string db_name,
2: i64 session_id,
3: CreateOption create_option,
4: string db_comment,
}

struct DropDatabaseRequest {
Expand Down

0 comments on commit b820b29

Please sign in to comment.