diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fd2dc88..285df89a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Added functions for check column table type table of any type of scheme entry + ## 3.4.0 ## * Add to public topic reader api: TopicReaderBatch, wait_message diff --git a/tests/conftest.py b/tests/conftest.py index b1de747d..51b265d7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -135,6 +135,42 @@ def table_path(database, table_name) -> str: return database + "/" + table_name +@pytest.fixture +def column_table_name(driver_sync, database): + table_name = "column_table" + + with ydb.SessionPool(driver_sync) as pool: + + def create_table(s): + try: + s.drop_table(database + "/" + table_name) + except ydb.SchemeError: + pass + + s.execute_scheme( + """ +CREATE TABLE %s ( +id Int64 NOT NULL, +i64Val Int64, +PRIMARY KEY(id) +) +PARTITION BY HASH(id) +WITH ( + STORE = COLUMN +) +""" + % table_name + ) + + pool.retry_operation_sync(create_table) + return table_name + + +@pytest.fixture() +def column_table_path(database, column_table_name) -> str: + return database + "/" + column_table_name + + @pytest.fixture() def topic_consumer(): return "fixture-consumer" diff --git a/tests/scheme/scheme_test.py b/tests/scheme/scheme_test.py new file mode 100644 index 00000000..29526cb2 --- /dev/null +++ b/tests/scheme/scheme_test.py @@ -0,0 +1,27 @@ +import typing + +import ydb + + +class TestSchemeEntryType: + def test_tables(self, driver_sync: ydb.Driver, database: str, table_name: str, column_table_name: str): + dir = driver_sync.scheme_client.list_directory(database) # type: ydb.Directory + children = dir.children # type: typing.List[ydb.SchemeEntry] + + has_column_table = False + has_row_table = False + + for child in children: + if child.name == table_name: + has_row_table = True + assert child.is_table() + assert child.is_any_table() + assert not child.is_column_table() + if child.name == column_table_name: + has_column_table = True + assert child.is_column_table() + assert child.is_any_table() + assert not child.is_table() + + assert has_column_table + assert has_row_table diff --git a/ydb/scheme.py b/ydb/scheme.py index 66437ae3..6019c763 100644 --- a/ydb/scheme.py +++ b/ydb/scheme.py @@ -31,8 +31,34 @@ def _missing_(cls, value): @staticmethod def is_table(entry): """ + Deprecated, use is_row_table instead of this. + :param entry: A scheme entry to check - :return: True if scheme entry is a table and False otherwise + :return: True if scheme entry is a row table and False otherwise (same as is_row_table) + """ + return entry == SchemeEntryType.TABLE + + @staticmethod + def is_any_table(entry): + """ + :param entry: A scheme entry to check + :return: True if scheme entry is table (independent of table type) and False otherwise + """ + return entry in (SchemeEntryType.TABLE, SchemeEntryType.COLUMN_TABLE) + + @staticmethod + def is_column_table(entry): + """ + :param entry: A scheme entry to check + :return: True if scheme entry is a column table and False otherwise + """ + return entry == SchemeEntryType.COLUMN_TABLE + + @staticmethod + def is_row_table(entry): + """ + :param entry: A scheme entry to check + :return: True if scheme entry is a row table and False otherwise (same as is_table) """ return entry == SchemeEntryType.TABLE @@ -104,10 +130,28 @@ def is_directory(self): def is_table(self): """ - :return: True if scheme entry is a table and False otherwise + :return: True if scheme entry is a row table and False otherwise (same as is_row_table) """ return SchemeEntryType.is_table(self.type) + def is_column_table(self): + """ + :return: True if scheme entry is a column table and False otherwise (same as is_row_table) + """ + return SchemeEntryType.is_column_table(self.type) + + def is_row_table(self): + """ + :return: True if scheme entry is a row table and False otherwise (same as is_table) + """ + return SchemeEntryType.is_table(self.type) + + def is_any_table(self): + """ + :return: True if scheme entry is table (independent of table type) and False otherwise + """ + return SchemeEntryType.is_any_table(self.type) + def is_database(self): """ :return: True if scheme entry is a database and False otherwise