Skip to content

Commit 7da081f

Browse files
authored
Merge pull request #347 Added functions for check column table type table of any type
2 parents 32e7784 + 72807db commit 7da081f

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added functions for check column table type table of any type of scheme entry
2+
13
## 3.4.0 ##
24
* Add to public topic reader api: TopicReaderBatch, wait_message
35

tests/conftest.py

+36
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,42 @@ def table_path(database, table_name) -> str:
135135
return database + "/" + table_name
136136

137137

138+
@pytest.fixture
139+
def column_table_name(driver_sync, database):
140+
table_name = "column_table"
141+
142+
with ydb.SessionPool(driver_sync) as pool:
143+
144+
def create_table(s):
145+
try:
146+
s.drop_table(database + "/" + table_name)
147+
except ydb.SchemeError:
148+
pass
149+
150+
s.execute_scheme(
151+
"""
152+
CREATE TABLE %s (
153+
id Int64 NOT NULL,
154+
i64Val Int64,
155+
PRIMARY KEY(id)
156+
)
157+
PARTITION BY HASH(id)
158+
WITH (
159+
STORE = COLUMN
160+
)
161+
"""
162+
% table_name
163+
)
164+
165+
pool.retry_operation_sync(create_table)
166+
return table_name
167+
168+
169+
@pytest.fixture()
170+
def column_table_path(database, column_table_name) -> str:
171+
return database + "/" + column_table_name
172+
173+
138174
@pytest.fixture()
139175
def topic_consumer():
140176
return "fixture-consumer"

tests/scheme/scheme_test.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import typing
2+
3+
import ydb
4+
5+
6+
class TestSchemeEntryType:
7+
def test_tables(self, driver_sync: ydb.Driver, database: str, table_name: str, column_table_name: str):
8+
dir = driver_sync.scheme_client.list_directory(database) # type: ydb.Directory
9+
children = dir.children # type: typing.List[ydb.SchemeEntry]
10+
11+
has_column_table = False
12+
has_row_table = False
13+
14+
for child in children:
15+
if child.name == table_name:
16+
has_row_table = True
17+
assert child.is_table()
18+
assert child.is_any_table()
19+
assert not child.is_column_table()
20+
if child.name == column_table_name:
21+
has_column_table = True
22+
assert child.is_column_table()
23+
assert child.is_any_table()
24+
assert not child.is_table()
25+
26+
assert has_column_table
27+
assert has_row_table

ydb/scheme.py

+46-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,34 @@ def _missing_(cls, value):
3131
@staticmethod
3232
def is_table(entry):
3333
"""
34+
Deprecated, use is_row_table instead of this.
35+
3436
:param entry: A scheme entry to check
35-
:return: True if scheme entry is a table and False otherwise
37+
:return: True if scheme entry is a row table and False otherwise (same as is_row_table)
38+
"""
39+
return entry == SchemeEntryType.TABLE
40+
41+
@staticmethod
42+
def is_any_table(entry):
43+
"""
44+
:param entry: A scheme entry to check
45+
:return: True if scheme entry is table (independent of table type) and False otherwise
46+
"""
47+
return entry in (SchemeEntryType.TABLE, SchemeEntryType.COLUMN_TABLE)
48+
49+
@staticmethod
50+
def is_column_table(entry):
51+
"""
52+
:param entry: A scheme entry to check
53+
:return: True if scheme entry is a column table and False otherwise
54+
"""
55+
return entry == SchemeEntryType.COLUMN_TABLE
56+
57+
@staticmethod
58+
def is_row_table(entry):
59+
"""
60+
:param entry: A scheme entry to check
61+
:return: True if scheme entry is a row table and False otherwise (same as is_table)
3662
"""
3763
return entry == SchemeEntryType.TABLE
3864

@@ -104,10 +130,28 @@ def is_directory(self):
104130

105131
def is_table(self):
106132
"""
107-
:return: True if scheme entry is a table and False otherwise
133+
:return: True if scheme entry is a row table and False otherwise (same as is_row_table)
108134
"""
109135
return SchemeEntryType.is_table(self.type)
110136

137+
def is_column_table(self):
138+
"""
139+
:return: True if scheme entry is a column table and False otherwise (same as is_row_table)
140+
"""
141+
return SchemeEntryType.is_column_table(self.type)
142+
143+
def is_row_table(self):
144+
"""
145+
:return: True if scheme entry is a row table and False otherwise (same as is_table)
146+
"""
147+
return SchemeEntryType.is_table(self.type)
148+
149+
def is_any_table(self):
150+
"""
151+
:return: True if scheme entry is table (independent of table type) and False otherwise
152+
"""
153+
return SchemeEntryType.is_any_table(self.type)
154+
111155
def is_database(self):
112156
"""
113157
:return: True if scheme entry is a database and False otherwise

0 commit comments

Comments
 (0)