Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functions for check column table type table of any type of sche… #347

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
36 changes: 36 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions tests/scheme/scheme_test.py
Original file line number Diff line number Diff line change
@@ -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
48 changes: 46 additions & 2 deletions ydb/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use is with enums

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In near places used =


@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

Expand Down Expand Up @@ -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
Expand Down
Loading