Skip to content

Commit e432d9c

Browse files
authored
Sample simple sql test (#12925)
1 parent a5622d4 commit e432d9c

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

ydb/tests/sql/test_sql.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
4+
import ydb
5+
6+
from ydb.tests.library.harness.kikimr_runner import KiKiMR
7+
from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator
8+
from ydb.tests.library.common.types import Erasure
9+
10+
11+
class TestYdbKvWorkload(object):
12+
@classmethod
13+
def setup_class(cls):
14+
cls.cluster = KiKiMR(KikimrConfigGenerator(erasure=Erasure.NONE))
15+
cls.cluster.start()
16+
cls.driver = ydb.Driver(
17+
ydb.DriverConfig(
18+
database='/Root',
19+
endpoint="%s:%s" % (
20+
cls.cluster.nodes[1].host, cls.cluster.nodes[1].port
21+
)
22+
)
23+
)
24+
cls.driver.wait()
25+
cls.pool = ydb.QuerySessionPool(cls.driver)
26+
27+
@classmethod
28+
def teardown_class(cls):
29+
cls.pool.stop()
30+
cls.driver.stop()
31+
cls.cluster.stop()
32+
33+
def setup(self):
34+
current_test_full_name = os.environ.get("PYTEST_CURRENT_TEST")
35+
self.table_path = "table_" + current_test_full_name.replace("::", ".").removesuffix(" (setup)")
36+
print(self.table_path)
37+
38+
def test_minimal_maximal_values(self):
39+
"""
40+
Test verifies correctness of handling minimal and maximal values for types
41+
"""
42+
43+
type_to_values_to_check = {
44+
"Int32": [-2 ** 31, 2 ** 31 - 1],
45+
"Uint32": [0, 2 ** 32 - 1],
46+
"Int64": [-2 ** 63, 2 ** 63 - 1],
47+
"Uint64": [0, 2 ** 64 - 1],
48+
}
49+
50+
for type_, values in type_to_values_to_check.items():
51+
for i, value in enumerate(values):
52+
table_name = table_name = "{}/{}_{}".format(self.table_path, type_, i)
53+
54+
self.pool.execute_with_retries(
55+
f"""
56+
CREATE TABLE `{table_name}` (
57+
id Int64,
58+
value {type_},
59+
PRIMARY KEY (id)
60+
);"""
61+
)
62+
63+
self.pool.execute_with_retries(
64+
f"""
65+
UPSERT INTO `{table_name}` (id, value) VALUES (1, {value});
66+
"""
67+
)
68+
69+
result = self.pool.execute_with_retries(
70+
f"""
71+
SELECT id, value FROM `{table_name}` WHERE id = 1;
72+
"""
73+
)
74+
75+
rows = result[0].rows
76+
assert len(rows) == 1, "Expected one row"
77+
assert rows[0].id == 1, "ID does not match"
78+
assert rows[0].value == value, "Value does not match"

ydb/tests/sql/ya.make

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
PY3TEST()
2+
ENV(YDB_DRIVER_BINARY="ydb/apps/ydbd/ydbd")
3+
4+
TEST_SRCS(
5+
test_sql.py
6+
)
7+
8+
SIZE(MEDIUM)
9+
10+
DEPENDS(
11+
ydb/apps/ydbd
12+
)
13+
14+
PEERDIR(
15+
ydb/tests/library
16+
)
17+
18+
END()

ydb/tests/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ RECURSE(
77
oss
88
perf
99
postgres_integrations
10+
sql
1011
stability
1112
supp
1213
tools

0 commit comments

Comments
 (0)