aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-12-24 13:54:55 +0000
committerGitHub <noreply@github.com>2024-12-24 16:54:55 +0300
commite432d9c27edb3c270328481e7bd3e8448da9ffc1 (patch)
treee3ccd94b1f5be68f338b82c34596d5732764f009
parenta5622d4fabbfd03de7006f28395f5e36446c9f3b (diff)
downloadydb-e432d9c27edb3c270328481e7bd3e8448da9ffc1.tar.gz
Sample simple sql test (#12925)
-rw-r--r--ydb/tests/sql/test_sql.py78
-rw-r--r--ydb/tests/sql/ya.make18
-rw-r--r--ydb/tests/ya.make1
3 files changed, 97 insertions, 0 deletions
diff --git a/ydb/tests/sql/test_sql.py b/ydb/tests/sql/test_sql.py
new file mode 100644
index 0000000000..9a0347bcdb
--- /dev/null
+++ b/ydb/tests/sql/test_sql.py
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+import os
+
+import ydb
+
+from ydb.tests.library.harness.kikimr_runner import KiKiMR
+from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator
+from ydb.tests.library.common.types import Erasure
+
+
+class TestYdbKvWorkload(object):
+ @classmethod
+ def setup_class(cls):
+ cls.cluster = KiKiMR(KikimrConfigGenerator(erasure=Erasure.NONE))
+ cls.cluster.start()
+ cls.driver = ydb.Driver(
+ ydb.DriverConfig(
+ database='/Root',
+ endpoint="%s:%s" % (
+ cls.cluster.nodes[1].host, cls.cluster.nodes[1].port
+ )
+ )
+ )
+ cls.driver.wait()
+ cls.pool = ydb.QuerySessionPool(cls.driver)
+
+ @classmethod
+ def teardown_class(cls):
+ cls.pool.stop()
+ cls.driver.stop()
+ cls.cluster.stop()
+
+ def setup(self):
+ current_test_full_name = os.environ.get("PYTEST_CURRENT_TEST")
+ self.table_path = "table_" + current_test_full_name.replace("::", ".").removesuffix(" (setup)")
+ print(self.table_path)
+
+ def test_minimal_maximal_values(self):
+ """
+ Test verifies correctness of handling minimal and maximal values for types
+ """
+
+ type_to_values_to_check = {
+ "Int32": [-2 ** 31, 2 ** 31 - 1],
+ "Uint32": [0, 2 ** 32 - 1],
+ "Int64": [-2 ** 63, 2 ** 63 - 1],
+ "Uint64": [0, 2 ** 64 - 1],
+ }
+
+ for type_, values in type_to_values_to_check.items():
+ for i, value in enumerate(values):
+ table_name = table_name = "{}/{}_{}".format(self.table_path, type_, i)
+
+ self.pool.execute_with_retries(
+ f"""
+ CREATE TABLE `{table_name}` (
+ id Int64,
+ value {type_},
+ PRIMARY KEY (id)
+ );"""
+ )
+
+ self.pool.execute_with_retries(
+ f"""
+ UPSERT INTO `{table_name}` (id, value) VALUES (1, {value});
+ """
+ )
+
+ result = self.pool.execute_with_retries(
+ f"""
+ SELECT id, value FROM `{table_name}` WHERE id = 1;
+ """
+ )
+
+ rows = result[0].rows
+ assert len(rows) == 1, "Expected one row"
+ assert rows[0].id == 1, "ID does not match"
+ assert rows[0].value == value, "Value does not match"
diff --git a/ydb/tests/sql/ya.make b/ydb/tests/sql/ya.make
new file mode 100644
index 0000000000..3091729c9a
--- /dev/null
+++ b/ydb/tests/sql/ya.make
@@ -0,0 +1,18 @@
+PY3TEST()
+ENV(YDB_DRIVER_BINARY="ydb/apps/ydbd/ydbd")
+
+TEST_SRCS(
+ test_sql.py
+)
+
+SIZE(MEDIUM)
+
+DEPENDS(
+ ydb/apps/ydbd
+)
+
+PEERDIR(
+ ydb/tests/library
+)
+
+END()
diff --git a/ydb/tests/ya.make b/ydb/tests/ya.make
index 4f2f38461c..7dcbd4e2bb 100644
--- a/ydb/tests/ya.make
+++ b/ydb/tests/ya.make
@@ -7,6 +7,7 @@ RECURSE(
oss
perf
postgres_integrations
+ sql
stability
supp
tools