Skip to content

Commit 29f8f7b

Browse files
authored
Add delete all rows after several inserts test (#20063)
1 parent 1f2bd60 commit 29f8f7b

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from .base import DeleteTestBase
2+
import pytest
3+
import random
4+
5+
6+
class TestDeleteAllAfterInserts(DeleteTestBase):
7+
test_name = "delete_by_explicit_row_id"
8+
MAX_ID = 2**32 // 2 - 1
9+
10+
@classmethod
11+
def setup_class(cls):
12+
super(TestDeleteAllAfterInserts, cls).setup_class()
13+
14+
def _get_test_dir(self):
15+
return f"{self.ydb_client.database}/{self.test_name}"
16+
17+
def _get_row_count(self, table_path):
18+
return self.ydb_client.query(f"SELECT count(*) as Rows from `{table_path}`")[0].rows[0]["Rows"]
19+
20+
def _test_two_columns_pk(self, rows_to_insert, insert_iterations):
21+
table_path = f"{self._get_test_dir()}/testTableAllDeleted"
22+
self.ydb_client.query(f"DROP TABLE IF EXISTS `{table_path}`;")
23+
self.ydb_client.query(
24+
f"""
25+
CREATE TABLE `{table_path}` (
26+
id1 Int32 NOT NULL,
27+
id2 Int32 NOT NULL,
28+
value Int64,
29+
PRIMARY KEY(id1, id2),
30+
)
31+
WITH (
32+
STORE = COLUMN
33+
)
34+
"""
35+
)
36+
37+
all_rows_ids = random.sample(range(self.MAX_ID), rows_to_insert * insert_iterations)
38+
rows_in_table = 0
39+
for it in range(0, len(all_rows_ids), rows_to_insert):
40+
rows_ids = all_rows_ids[it : it + rows_to_insert]
41+
42+
insert_query = f"INSERT INTO `{table_path}` (id1, id2, value) VALUES "
43+
for i in rows_ids:
44+
insert_query += f"({i}, {i}, {i}), "
45+
insert_query = insert_query[:-2] + ";"
46+
self.ydb_client.query(insert_query)
47+
48+
rows_in_table += rows_to_insert
49+
assert self._get_row_count(table_path) == rows_in_table
50+
51+
self.ydb_client.query(f"DELETE FROM `{table_path}`")
52+
53+
assert self._get_row_count(table_path) == 0
54+
55+
# passes
56+
assert len(self.ydb_client.query(
57+
f"""
58+
SELECT id1 as id1, id2 as id2 FROM `{table_path}` WHERE id1 != 10000000 ORDER by id1, id2 LIMIT 100;
59+
"""
60+
)[0].rows) == 0
61+
62+
# passes
63+
assert len(self.ydb_client.query(
64+
f"""
65+
SELECT id1 as id1, id2 as id2 FROM `{table_path}` WHERE id1 != 10000000 ORDER by id1 DESC, id2 DESC;
66+
"""
67+
)[0].rows) == 0
68+
69+
# passes
70+
assert len(self.ydb_client.query(
71+
f"""
72+
SELECT id1 as id1, id2 as id2 FROM `{table_path}` WHERE id1 != 10000000 LIMIT 100;
73+
"""
74+
)[0].rows) == 0
75+
76+
# passes
77+
assert len(self.ydb_client.query(
78+
f"""
79+
SELECT id1 as id1, id2 as id2 FROM `{table_path}` WHERE id1 != 10000000;
80+
"""
81+
)[0].rows) == 0
82+
83+
# fails
84+
assert len(self.ydb_client.query(
85+
f"""
86+
SELECT id1 as id1, id2 as id2 FROM `{table_path}` WHERE id1 != 10000000 ORDER by id1 DESC, id2 DESC LIMIT 100;
87+
"""
88+
)[0].rows) == 0
89+
90+
@pytest.mark.skip(reason="https://github.com/ydb-platform/ydb/issues/20098")
91+
def test_delete_all_rows_after_several_inserts(self):
92+
# IMPORTANT note: tests passes with 1 insert_iterations
93+
self._test_two_columns_pk(rows_to_insert=1000, insert_iterations=2)

ydb/tests/olap/delete/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PY3TEST()
66
TEST_SRCS(
77
base.py
88
test_delete_by_explicit_row_id.py
9+
test_delete_all_after_inserts.py
910
)
1011

1112
SIZE(MEDIUM)

0 commit comments

Comments
 (0)