Skip to content

Commit b2339a1

Browse files
committed
add tests
1 parent 46fd78c commit b2339a1

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

Diff for: tests/conftest.py

+34
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,40 @@ 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+
pool.retry_operation_sync(create_table)
165+
return table_name
166+
167+
@pytest.fixture()
168+
def column_table_path(database, column_table_name) -> str:
169+
return database + "/" + column_table_name
170+
171+
138172
@pytest.fixture()
139173
def topic_consumer():
140174
return "fixture-consumer"

Diff for: 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

Diff for: ydb/scheme.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def is_table(entry):
4040
def is_any_table(entry):
4141
"""
4242
:param entry: A scheme entry to check
43-
:return: True if scheme entry is table of any type and False otherwise
43+
:return: True if scheme entry is table (independent of table type) and False otherwise
4444
"""
4545
return entry in [SchemeEntryType.TABLE, SchemeEntryType.COLUMN_TABLE]
4646

@@ -128,10 +128,28 @@ def is_directory(self):
128128

129129
def is_table(self):
130130
"""
131-
:return: True if scheme entry is a table and False otherwise
131+
:return: True if scheme entry is a row table and False otherwise (same as is_row_table)
132132
"""
133133
return SchemeEntryType.is_table(self.type)
134134

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

0 commit comments

Comments
 (0)