@@ -113,7 +113,7 @@ def test_restart_query(self, kikimr):
113113 self .init_topics (sourceName , partitions_count = 10 )
114114 self .create_source (kikimr , sourceName , False )
115115
116- name = "query1 "
116+ name = "test_restart_query "
117117 sql = R'''
118118 CREATE STREAMING QUERY `{query_name}` AS
119119 DO BEGIN
@@ -301,7 +301,7 @@ def test_json_errors(self, kikimr):
301301 self .init_topics (sourceName , partitions_count = 10 )
302302 self .create_source (kikimr , sourceName , True )
303303
304- name = "query1 "
304+ name = "test_json_errors "
305305 sql = R'''
306306 CREATE STREAMING QUERY `{query_name}` AS
307307 DO BEGIN
@@ -326,3 +326,61 @@ def test_json_errors(self, kikimr):
326326
327327 expected = ['hello1' , 'hello2' ]
328328 assert self .read_stream (len (expected ), topic_path = self .output_topic ) == expected
329+
330+ def test_restart_query_by_rescaling (self , kikimr ):
331+ sourceName = '' .join (random .choices (string .ascii_letters + string .digits , k = 8 ))
332+ self .init_topics (sourceName , partitions_count = 10 )
333+ self .create_source (kikimr , sourceName , True )
334+
335+ name = "test_restart_query_by_rescaling"
336+ sql = R'''
337+ CREATE STREAMING QUERY `{query_name}` AS
338+ DO BEGIN
339+ PRAGMA ydb.OverridePlanner = @@ [
340+ {{ "tx": 0, "stage": 0, "tasks": 2 }}
341+ ] @@;
342+ $in = SELECT time FROM {source_name}.`{input_topic}`
343+ WITH (
344+ FORMAT="json_each_row",
345+ SCHEMA=(time String NOT NULL))
346+ WHERE time like "%time%";
347+ INSERT INTO `{source_name}`.`{output_topic}` SELECT time FROM $in;
348+ END DO;'''
349+
350+ query_id = "query_id" # TODO
351+ kikimr .YdbClient .query (sql .format (query_name = name , source_name = sourceName , input_topic = self .input_topic , output_topic = self .output_topic ))
352+ self .wait_completed_checkpoints (kikimr , query_id )
353+
354+ message_count = 20
355+ for i in range (message_count ):
356+ self .write_stream (['{"time": "time to do it"}' ], topic_path = None , partition_key = ('' .join (random .choices (string .digits , k = 8 ))))
357+ assert self .read_stream (message_count , topic_path = self .output_topic ) == ["time to do it" for i in range (message_count )]
358+ self .wait_completed_checkpoints (kikimr , query_id )
359+
360+ logging .debug (f"stopping query { name } " )
361+ kikimr .YdbClient .query (f"ALTER STREAMING QUERY `{ name } ` SET (RUN = FALSE);" )
362+
363+ sql = R'''ALTER STREAMING QUERY `{query_name}` SET (
364+ RUN = TRUE,
365+ FORCE = TRUE
366+ ) AS
367+ DO BEGIN
368+ PRAGMA ydb.OverridePlanner = @@ [
369+ {{ "tx": 0, "stage": 0, "tasks": 3 }}
370+ ] @@;
371+ $in = SELECT time FROM {source_name}.`{input_topic}`
372+ WITH (
373+ FORMAT="json_each_row",
374+ SCHEMA=(time String NOT NULL))
375+ WHERE time like "%lunch%";
376+ INSERT INTO `{source_name}`.`{output_topic}` SELECT time FROM $in;
377+ END DO;'''
378+
379+ kikimr .YdbClient .query (sql .format (query_name = name , source_name = sourceName , input_topic = self .input_topic , output_topic = self .output_topic ))
380+
381+ message = '{"time": "time to lunch"}'
382+ for i in range (message_count ):
383+ self .write_stream ([message ], topic_path = None , partition_key = ('' .join (random .choices (string .digits , k = 8 ))))
384+ assert self .read_stream (message_count , topic_path = self .output_topic ) == ["time to lunch" for i in range (message_count )]
385+
386+ kikimr .YdbClient .query (f"ALTER STREAMING QUERY `{ name } ` SET (RUN = FALSE);" )
0 commit comments