Skip to content

Commit

Permalink
Add comment for database creation (infiniflow#2050)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Add comment for database creation - 0.5.0

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
  • Loading branch information
JinHai-CN authored and vsian committed Oct 18, 2024
1 parent 2f5297b commit 7c7fbc7
Show file tree
Hide file tree
Showing 61 changed files with 3,802 additions and 3,412 deletions.
2 changes: 1 addition & 1 deletion benchmark/local_infinity/fulltext/fulltext_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ SharedPtr<Infinity> CreateDbAndTable(const String &db_name, const String &table_
SharedPtr<Infinity> infinity = Infinity::LocalConnect();
CreateDatabaseOptions create_db_options;
create_db_options.conflict_type_ = ConflictType::kIgnore;
infinity->CreateDatabase(db_name, std::move(create_db_options));
infinity->CreateDatabase(db_name, std::move(create_db_options), "");

DropTableOptions drop_tb_options;
drop_tb_options.conflict_type_ = ConflictType::kIgnore;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/local_infinity/infinity_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int main() {
CreateDatabaseOptions create_db_opts;
auto tims_costing_second =
Measurement("Create Database", thread_num, total_times, [&](SizeT i, SharedPtr<Infinity> infinity, std::thread::id thread_id) {
__attribute__((unused)) auto ignored = infinity->CreateDatabase(std::to_string(i), create_db_opts);
__attribute__((unused)) auto ignored = infinity->CreateDatabase(std::to_string(i), create_db_opts, "");
});
results.push_back(fmt::format("-> Create Database QPS: {}", total_times / tims_costing_second));
}
Expand Down Expand Up @@ -366,7 +366,7 @@ int main() {
std::shared_ptr<Infinity> infinity = Infinity::LocalConnect();
CreateDatabaseOptions create_db_options;
create_db_options.conflict_type_ = ConflictType::kIgnore;
auto r1 = infinity->CreateDatabase(db_name, std::move(create_db_options));
auto r1 = infinity->CreateDatabase(db_name, std::move(create_db_options), "");

CreateTableOptions create_tb_options;
create_tb_options.conflict_type_ = ConflictType::kIgnore;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/local_infinity/knn/knn_import_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
std::shared_ptr<Infinity> infinity = Infinity::LocalConnect();
CreateDatabaseOptions create_db_options;
create_db_options.conflict_type_ = ConflictType::kIgnore;
auto r1 = infinity->CreateDatabase(db_name, std::move(create_db_options));
auto r1 = infinity->CreateDatabase(db_name, std::move(create_db_options), "");

// auto [ data_base, status1 ] = infinity->GetDatabase(db_name);
CreateTableOptions create_tb_options;
Expand Down
2 changes: 1 addition & 1 deletion python/infinity_embedded/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
14 changes: 10 additions & 4 deletions python/infinity_embedded/local_infinity/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class LocalQueryResult:
def __init__(self, error_code: PyErrorCode, error_msg: str, db_names=None, table_names=None, index_names=None,
column_defs=None, column_fields=None, database_name=None, store_dir=None, table_count=None):
column_defs=None, column_fields=None, database_name=None, store_dir=None, table_count=None, comment=None):
self.error_code = error_code
self.error_msg = error_msg
self.db_names = db_names
Expand All @@ -32,6 +32,7 @@ def __init__(self, error_code: PyErrorCode, error_msg: str, db_names=None, table
self.database_name = database_name
self.store_dir = store_dir
self.table_count = table_count
self.comment = comment


class LocalInfinityClient:
Expand Down Expand Up @@ -64,15 +65,20 @@ def convert_res(self, res, has_db_names=False, has_table_names=False, has_result
column_fields=res.column_fields)
if has_db_name:
return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg, database_name=res.database_name,
store_dir=res.store_dir, table_count=res.table_count)
store_dir=res.store_dir, table_count=res.table_count, comment=res.comment)
if has_index_names:
return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg, index_names=res.names)
return LocalQueryResult(PyErrorCode(res.error_code.value), res.error_msg)

def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError):
def create_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError, comment: str = None):
create_database_options = CreateDatabaseOptions()
create_database_options.conflict_type = conflict_type
return self.convert_res(self.client.CreateDatabase(db_name, create_database_options))
db_comment: str = None
if comment is None:
db_comment = ""
else:
db_comment = comment
return self.convert_res(self.client.CreateDatabase(db_name, create_database_options, db_comment))

def drop_database(self, db_name: str, conflict_type: ConflictType = ConflictType.kError):
drop_database_options = DropDatabaseOptions()
Expand Down
3 changes: 2 additions & 1 deletion python/infinity_embedded/local_infinity/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@


class LocalDatabase(Database, ABC):
def __init__(self, conn, name: str):
def __init__(self, conn, name: str, comment: str = None):
self._conn = conn
self._db_name = name
self._db_comment = comment

def create_table(self, table_name: str, columns_definition,
conflict_type: ConflictType = ConflictType.Error):
Expand Down
4 changes: 2 additions & 2 deletions python/infinity_embedded/local_infinity/infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def check_connect(self):
raise Exception("Local infinity is not connected")

@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):
self.check_connect()
create_database_conflict: LocalConflictType
if conflict_type == ConflictType.Error:
Expand All @@ -50,7 +50,7 @@ def create_database(self, db_name: str, conflict_type: ConflictType = ConflictTy
create_database_conflict = LocalConflictType.kReplace
else:
raise InfinityException(ErrorCode.INVALID_CONFLICT_TYPE, "Invalid conflict type")
res = self._client.create_database(db_name, create_database_conflict)
res = self._client.create_database(db_name, create_database_conflict, comment)

if res.error_code == ErrorCode.OK:
return LocalDatabase(self._client, db_name)
Expand Down
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.

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

Loading

0 comments on commit 7c7fbc7

Please sign in to comment.