3
3
import time
4
4
import threading
5
5
6
- from ydb .tests .stress .common .common import WorkloadBase
6
+ from ydb .tests .stress .oltp_workload .workload .type .vector_index import WorkloadVectorIndex
7
+ from ydb .tests .stress .oltp_workload .workload .type .insert_delete_all_types import WorkloadInsertDeleteAllTypes
7
8
8
9
ydb .interceptor .monkey_patch_event_handler ()
9
10
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 (',' , '' )
58
-
59
-
60
- class WorkloadInsertDeleteAllTypes (WorkloadBase ):
61
- def __init__ (self , client , prefix , stop ):
62
- super ().__init__ (client , prefix , "insert_delete_all_types" , stop )
63
- self .inserted = 0
64
- self .table_name = "table"
65
- self .lock = threading .Lock ()
66
-
67
- def get_stat (self ):
68
- with self .lock :
69
- return f"Inserted: { self .inserted } "
70
-
71
- def _loop (self ):
72
- table_path = self .get_table_path (self .table_name )
73
- create_sql = f"""
74
- CREATE TABLE `{ table_path } ` (
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 ()])} ,
80
- PRIMARY KEY(
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 ()])}
83
- )
84
- )
85
- """
86
-
87
- self .client .query (create_sql , True ,)
88
- inflight = 10
89
- i = 0
90
- sum = 0
91
- while not self .is_stop_requested ():
92
- value = i % 100
93
- insert_sql = f"""
94
- INSERT INTO `{ table_path } ` (
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 ()])}
100
- )
101
- VALUES
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
- ;
110
- """
111
- self .client .query (insert_sql , False ,)
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 } " )
133
- i += 1
134
- with self .lock :
135
- self .inserted += 1
136
-
137
- def get_workload_thread_funcs (self ):
138
- return [self ._loop ]
139
-
140
11
141
12
class WorkloadRunner :
142
13
def __init__ (self , client , path , duration ):
@@ -160,9 +31,9 @@ def _cleanup(self):
160
31
161
32
def run (self ):
162
33
stop = threading .Event ()
163
-
164
34
workloads = [
165
35
WorkloadInsertDeleteAllTypes (self .client , self .name , stop ),
36
+ WorkloadVectorIndex (self .client , self .name , stop )
166
37
]
167
38
168
39
for w in workloads :
0 commit comments