Skip to content

Commit d492c81

Browse files
authored
Stress test uses map types to values (#14720)
1 parent 1642487 commit d492c81

File tree

1 file changed

+96
-107
lines changed

1 file changed

+96
-107
lines changed

ydb/tests/stress/oltp_workload/workload/__init__.py

Lines changed: 96 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -7,143 +7,132 @@
77

88
ydb.interceptor.monkey_patch_event_handler()
99

10-
supported_pk_types = [
11-
"Int64",
12-
"Uint64",
13-
"Int32",
14-
"Uint32",
15-
"Int16",
16-
"Uint16",
17-
"Int8",
18-
"Uint8",
19-
"Bool",
20-
"Decimal(1,0)",
21-
"Decimal(22,9)",
22-
"Decimal(35,10)",
23-
"DyNumber",
24-
25-
"String",
26-
"Utf8",
27-
"Uuid",
28-
29-
"Date",
30-
"Datetime",
31-
"Timestamp",
32-
"Interval",
33-
"Date32",
34-
"Datetime64",
35-
"Timestamp64",
36-
"Interval64"
37-
]
38-
39-
supported_types = supported_pk_types + [
40-
"Float",
41-
"Double",
42-
"Json",
43-
"JsonDocument",
44-
"Yson"
45-
]
46-
47-
null_types = [
48-
"Int64",
49-
"Decimal(22,9)",
50-
"Decimal(35,10)",
51-
"String",
52-
]
10+
digits = 2 # should be consistent with format string below
11+
pk_types = {
12+
"Int64": "CAST({} AS Int64)",
13+
"Uint64": "CAST({} AS Uint64)",
14+
"Int32": "CAST({} AS Int32)",
15+
"Uint32": "CAST({} AS Uint32)",
16+
"Int16": "CAST({} AS Int16)",
17+
"Uint16": "CAST({} AS Uint16)",
18+
"Int8": "CAST({} AS Int8)",
19+
"Uint8": "CAST({} AS Uint8)",
20+
"Bool": "CAST({} AS Bool)",
21+
"Decimal(15,0)": "CAST('{}.0' AS Decimal(15,0))",
22+
"Decimal(22,9)": "CAST('{}.123' AS Decimal(22,9))",
23+
"Decimal(35,10)": "CAST('{}.123456' AS Decimal(35,10))",
24+
"DyNumber": "CAST('{}E1' AS DyNumber)",
25+
26+
"String": "'String {}'",
27+
"Utf8": "'Uft8 {}'",
28+
"Uuid": "CAST('{:2}345678-e89b-12d3-a456-556642440000' AS UUID)",
29+
30+
"Date": "CAST('20{:02}-01-01' AS Date)",
31+
"Datetime": "CAST('20{:02}-10-02T11:00:00Z' AS Datetime)",
32+
"Timestamp": "CAST(169624{:02}00000000 AS Timestamp)",
33+
"Interval": "CAST({} AS Interval)",
34+
"Date32": "CAST('20{:02}-01-01' AS Date32)",
35+
"Datetime64": "CAST('20{:02}-10-02T11:00:00Z' AS Datetime64)",
36+
"Timestamp64": "CAST(169624{:02}00000000 AS Timestamp64)",
37+
"Interval64": "CAST({} AS Interval64)"
38+
}
39+
40+
non_pk_types = {
41+
"Float": "CAST('{}.1' AS Float)",
42+
"Double": "CAST('{}.2' AS Double)",
43+
"Json": "CAST('{{\"another_key\":{}}}' AS Json)",
44+
"JsonDocument": "CAST('{{\"another_doc_key\":{}}}' AS JsonDocument)",
45+
"Yson": "CAST('[{}]' AS Yson)"
46+
}
47+
48+
null_types = {
49+
"Int64": "CAST({} AS Int64)",
50+
"Decimal(22,9)": "CAST('{}.123' AS Decimal(22,9))",
51+
"Decimal(35,10)": "CAST('{}.123456' AS Decimal(35,10))",
52+
"String": "'{}'",
53+
}
54+
55+
56+
def cleanup_type_name(type_name):
57+
return type_name.replace('(', '').replace(')', '').replace(',', '')
5358

5459

5560
class WorkloadInsertDeleteAllTypes(WorkloadBase):
5661
def __init__(self, client, prefix, stop):
5762
super().__init__(client, prefix, "insert_delete_all_types", stop)
5863
self.inserted = 0
59-
self.current = 0
6064
self.table_name = "table"
6165
self.lock = threading.Lock()
6266

6367
def get_stat(self):
6468
with self.lock:
65-
return f"Inserted: {self.inserted}, Current: {self.current}"
69+
return f"Inserted: {self.inserted}"
6670

6771
def _loop(self):
6872
table_path = self.get_table_path(self.table_name)
6973
create_sql = f"""
7074
CREATE TABLE `{table_path}` (
71-
{", ".join(["pk" + str(i) + " " + supported_pk_types[i] for i in range(len(supported_pk_types))])},
72-
{", ".join(["null_pk" + str(i) + " " + null_types[i] for i in range(len(null_types))])},
73-
{", ".join(["col" + str(i) + " " + supported_types[i] for i in range(len(supported_types))])},
74-
{", ".join(["null_col" + str(i) + " " + null_types[i] for i in range(len(null_types))])},
75+
pk Uint64,
76+
{", ".join(["pk_" + cleanup_type_name(type_name) + " " + type_name for type_name in pk_types.keys()])},
77+
{", ".join(["null_pk_" + cleanup_type_name(type_name) + " " + type_name for type_name in null_types.keys()])},
78+
{", ".join(["col_" + cleanup_type_name(type_name) + " " + type_name for type_name in non_pk_types.keys()])},
79+
{", ".join(["null_col_" + cleanup_type_name(type_name) + " " + type_name for type_name in null_types.keys()])},
7580
PRIMARY KEY(
76-
{", ".join(["pk" + str(i) for i in range(len(supported_pk_types))])},
77-
{", ".join(["null_pk" + str(i) for i in range(len(null_types))])}
81+
{", ".join(["pk_" + cleanup_type_name(type_name) for type_name in pk_types.keys()])},
82+
{", ".join(["null_pk_" + cleanup_type_name(type_name) for type_name in null_types.keys()])}
7883
)
7984
)
8085
"""
81-
# print(create_sql)
8286

8387
self.client.query(create_sql, True,)
84-
i = 1
88+
inflight = 10
89+
i = 0
90+
sum = 0
8591
while not self.is_stop_requested():
92+
value = i % 100
8693
insert_sql = f"""
8794
INSERT INTO `{table_path}` (
88-
{", ".join(["pk" + str(i) for i in range(len(supported_pk_types))])},
89-
{", ".join(["null_pk" + str(i) for i in range(len(null_types))])},
90-
{", ".join(["col" + str(i) for i in range(len(supported_types))])},
91-
{", ".join(["null_col" + str(i) for i in range(len(null_types))])}
95+
pk,
96+
{", ".join(["pk_" + cleanup_type_name(type_name) for type_name in pk_types.keys()])},
97+
{", ".join(["null_pk_" + cleanup_type_name(type_name) for type_name in null_types.keys()])},
98+
{", ".join(["col_" + cleanup_type_name(type_name) for type_name in non_pk_types.keys()])},
99+
{", ".join(["null_col_" + cleanup_type_name(type_name) for type_name in null_types.keys()])}
92100
)
93101
VALUES
94-
({i * 2}, {i * 10},
95-
-2147483648, 0, -32768, 0, -128, 0, false,
96-
CAST('1' AS Decimal(1,0)), CAST('1234567890123456789.000000001' AS Decimal(22,9)), CAST('1234567890123456789123456789.000000001' AS Decimal(35,10)),
97-
CAST('-1.234' AS DyNumber), 'AnotherString', 'AnotherUtf8', CAST('123e4567-e89b-12d3-a456-556642440000' AS Uuid),
98-
CAST('2023-10-02' AS Date), CAST('2023-10-02T11:00:00' AS Datetime), CAST(1696243200000000 AS Timestamp), CAST(-86400 AS Interval),
99-
Date32('998-06-02'), CAST('2023-10-02T11:00:00.654321' AS Datetime64), Timestamp64('0998-06-02T12:30:00.123456Z'),Interval64('PT2S'),
100-
NULL, NULL, NULL, NULL,
101-
-2000000, {i * 10}, -222, 222, -22, 22, -2, 2, true,
102-
CAST('2' AS Decimal(1,0)), CAST('2234567890123456789.000000001' AS Decimal(22,9)), CAST('2234567890123456789123456789.000000001' AS Decimal(35,10)),
103-
CAST('123E4' AS DyNumber), 'SampleString', 'SampleUtf8', CAST('550e8400-e29b-41d4-a716-446655440000' AS Uuid),
104-
CAST('2023-10-01' AS Date), CAST('2023-10-01T10:00:00' AS Datetime), CAST(1696156800000000 AS Timestamp), CAST(3600 AS Interval),
105-
Date32('998-06-01'), CAST('2023-10-01T10:00:00.123456' AS Datetime64), Timestamp64('0998-06-02T12:30:00.678901Z'),Interval64('-PT2S'), 3.14f, 2.71828,
106-
CAST('{{"json_key":"json_value"}}' AS Json), CAST('{{"doc_key":"doc_value"}}' AS JsonDocument), CAST('<yson><key1>value1</key1></yson>' AS Yson),
107-
NULL, NULL, NULL, NULL),
108-
({i * 2 + 1}, {i * 10 + 1},
109-
2147483647, 4294967295, 32767, 65535, 127, 255, true,
110-
CAST('3' AS Decimal(1,0)), CAST('3234567890123456789.000000001' AS Decimal(22,9)), CAST('3234567890123456789123456789.000000001' AS Decimal(35,10)),
111-
CAST('4.567E-3' AS DyNumber), 'ExampleString', 'ExampleUtf8', CAST('00112233-4455-6677-8899-aabbccddeeff' AS Uuid),
112-
CAST('2022-12-31' AS Date), CAST('2022-12-31T23:59:59' AS Datetime), CAST(1672444799000000 AS Timestamp), CAST(172800 AS Interval),
113-
Date32('1000-01-01'), CAST('2022-12-31T23:59:59.999999' AS Datetime64), Timestamp64('1000-01-01T00:00:00.000000Z'), Interval64('PT1440M'),
114-
NULL, NULL, NULL, NULL,
115-
-4000000, {i * 10 + 1}, -444, 444, -44, 44, -4, 4, false,
116-
CAST('4' AS Decimal(1,0)), CAST('4234567890123456789.000000001' AS Decimal(22,9)), CAST('4234567890123456789123456789.000000001' AS Decimal(35,10)),
117-
CAST('-987E-4' AS DyNumber), 'NewString', 'NewUtf8', CAST('01234567-89ab-cdef-0123-456789abcdef' AS Uuid),
118-
CAST('1980-03-15' AS Date), CAST('1980-03-15T08:00:00' AS Datetime), CAST(315532800000000 AS Timestamp), CAST(-31536000 AS Interval),
119-
Date32('2000-02-29'), CAST('1980-03-15T08:00:00.123456' AS Datetime64), Timestamp64('2000-02-29T12:30:00.999999Z'), Interval64('-PT600S'), -0.123f, 2.71828,
120-
CAST('{{"another_key":"another_value"}}' AS Json), CAST('{{"another_doc_key":"another_doc_value"}}' AS JsonDocument), CAST('<yson><key2>value2</key2></yson>' AS Yson),
121-
NULL, NULL, NULL, NULL);
102+
(
103+
{i},
104+
{", ".join([pk_types[type_name].format(value) for type_name in pk_types.keys()])},
105+
{", ".join(['NULL' for type_name in null_types.keys()])},
106+
{", ".join([non_pk_types[type_name].format(value) for type_name in non_pk_types.keys()])},
107+
{", ".join(['NULL' for type_name in null_types.keys()])}
108+
)
109+
;
122110
"""
123-
# print(insert_sql)
124111
self.client.query(insert_sql, False,)
125-
126-
self.client.query(
127-
f"""
128-
DELETE FROM `{table_path}`
129-
WHERE col1 % 2 == 1 AND null_pk0 IS NULL
130-
""",
131-
False,
132-
)
133-
134-
actual = self.client.query(
135-
f"""
136-
SELECT COUNT(*) as cnt, SUM(col1) as vals, SUM(pk0) as ids FROM `{table_path}`
137-
""",
138-
False,
139-
)[0].rows[0]
140-
expected = {"cnt": i, "vals": i * (i + 1) * 5, "ids": i * (i + 1)}
141-
if actual != expected:
142-
raise Exception(f"Incorrect result: expected:{expected}, actual:{actual}")
112+
sum += i
113+
114+
if (i >= inflight):
115+
self.client.query(
116+
f"""
117+
DELETE FROM `{table_path}`
118+
WHERE pk == {i - inflight} AND null_pk_Int64 IS NULL
119+
""",
120+
False,
121+
)
122+
sum -= (i - inflight)
123+
124+
actual = self.client.query(
125+
f"""
126+
SELECT COUNT(*) as cnt, SUM(pk) as sum FROM `{table_path}`
127+
""",
128+
False,
129+
)[0].rows[0]
130+
expected = {"cnt": inflight, "sum": sum}
131+
if actual != expected:
132+
raise Exception(f"Incorrect result: expected:{expected}, actual:{actual}")
143133
i += 1
144134
with self.lock:
145-
self.inserted += 2
146-
self.current = actual["cnt"]
135+
self.inserted += 1
147136

148137
def get_workload_thread_funcs(self):
149138
return [self._loop]
@@ -188,4 +177,4 @@ def run(self):
188177
print("Waiting for stop...")
189178
for w in workloads:
190179
w.join()
191-
print("Waiting for stop... stopped")
180+
print("Stopped")

0 commit comments

Comments
 (0)