@@ -137,8 +137,9 @@ def join(self):
137137
138138
139139class WorkloadTablesCreateDrop (WorkloadBase ):
140- def __init__ (self , client , prefix , stop ):
140+ def __init__ (self , client , prefix , stop , allow_nullables_in_pk ):
141141 super ().__init__ (client , prefix , "create_drop" , stop )
142+ self .allow_nullables_in_pk = allow_nullables_in_pk
142143 self .created = 0
143144 self .deleted = 0
144145 self .tables = set ()
@@ -166,11 +167,21 @@ def create_table(self, table):
166167 column_n = random .randint (1 , 10000 )
167168 primary_key_column_n = random .randint (1 , column_n )
168169 partition_key_column_n = random .randint (1 , primary_key_column_n )
169- columns = [random .choice (supported_pk_types ) for _ in range (primary_key_column_n )] + [random .choice (supported_types ) for _ in range (column_n - primary_key_column_n )]
170+ column_defs = []
171+ for i in range (column_n ):
172+ if i < primary_key_column_n :
173+ c = random .choice (supported_pk_types )
174+ if not self .allow_nullables_in_pk or random .choice ([False , True ]):
175+ c += " NOT NULL"
176+ else :
177+ c = random .choice (supported_types )
178+ if random .choice ([False , True ]):
179+ c += " NOT NULL"
180+ column_defs .append (c )
170181
171182 stmt = f"""
172183 CREATE TABLE `{ path } ` (
173- { ", " .join (["c" + str (i ) + " " + columns [i ] + " NOT NULL" for i in range (column_n )])} ,
184+ { ", " .join (["c" + str (i ) + " " + column_defs [i ] for i in range (column_n )])} ,
174185 PRIMARY KEY({ ", " .join (["c" + str (i ) for i in range (primary_key_column_n )])} )
175186 )
176187 PARTITION BY HASH({ ", " .join (["c" + str (i ) for i in range (partition_key_column_n )])} )
@@ -273,11 +284,12 @@ def get_workload_thread_funcs(self):
273284
274285
275286class WorkloadRunner :
276- def __init__ (self , client , name , duration ):
287+ def __init__ (self , client , name , duration , allow_nullables_in_pk ):
277288 self .client = client
278- self .name = name
289+ self .name = args . path
279290 self .tables_prefix = "/" .join ([self .client .database , self .name ])
280- self .duration = duration
291+ self .duration = args .duration
292+ self .allow_nullables_in_pk = allow_nullables_in_pk
281293
282294 def __enter__ (self ):
283295 self ._cleanup ()
@@ -294,7 +306,7 @@ def _cleanup(self):
294306 def run (self ):
295307 stop = threading .Event ()
296308 workloads = [
297- WorkloadTablesCreateDrop (self .client , self .name , stop ),
309+ WorkloadTablesCreateDrop (self .client , self .name , stop , self . allow_nullables_in_pk ),
298310 # WorkloadInsertDelete(self.client, self.name, stop), TODO fix https://github.com/ydb-platform/ydb/issues/12871
299311 ]
300312 for w in workloads :
@@ -320,8 +332,9 @@ def run(self):
320332 parser .add_argument ("--database" , default = "Root/test" , help = "A database to connect" )
321333 parser .add_argument ("--path" , default = "olap_workload" , help = "A path prefix for tables" )
322334 parser .add_argument ("--duration" , default = 10 ** 9 , type = lambda x : int (x ), help = "A duration of workload in seconds." )
335+ parser .add_argument ("--allow-nullables-in-pk" , default = False , help = "Allow nullable types for columns in a Primary Key." )
323336 args = parser .parse_args ()
324337 client = YdbClient (args .endpoint , args .database , True )
325338 client .wait_connection ()
326- with WorkloadRunner (client , args .path , args .duration ) as runner :
339+ with WorkloadRunner (client , args .path , args .duration , args . allow_nullables_in_pk ) as runner :
327340 runner .run ()
0 commit comments