@@ -293,6 +293,73 @@ b (2/6 partitions)
293293 require .ElementsMatch (expected , rows )
294294}
295295
296+ // TODO: this was an analyzer test, but we don't have a mock process list for it to use, so it has to be here
297+ func TestTrackProcess (t * testing.T ) {
298+ require := require .New (t )
299+ db := memory .NewDatabase ("db" )
300+ provider := memory .NewDBProvider (db )
301+ a := analyzer .NewDefault (provider )
302+ sess := memory .NewSession (sql .NewBaseSession (), provider )
303+
304+ node := plan .NewInnerJoin (
305+ plan .NewResolvedTable (& nonIndexableTable {memory .NewPartitionedTable (db .BaseDatabase , "foo" , sql.PrimaryKeySchema {}, nil , 2 )}, nil , nil ),
306+ plan .NewResolvedTable (memory .NewPartitionedTable (db .BaseDatabase , "bar" , sql.PrimaryKeySchema {}, nil , 4 ), nil , nil ),
307+ expression .NewLiteral (int64 (1 ), types .Int64 ),
308+ )
309+
310+ pl := sqle .NewProcessList ()
311+
312+ ctx := sql .NewContext (context .Background (), sql .WithPid (1 ), sql .WithProcessList (pl ), sql .WithSession (sess ))
313+ pl .AddConnection (ctx .Session .ID (), "localhost" )
314+ pl .ConnectionReady (ctx .Session )
315+ ctx , err := ctx .ProcessList .BeginQuery (ctx , "SELECT foo" )
316+ require .NoError (err )
317+
318+ rule := getRuleFrom (analyzer .OnceAfterAll , analyzer .TrackProcessId )
319+ result , _ , err := rule .Apply (ctx , a , node , nil , analyzer .DefaultRuleSelector , nil )
320+ require .NoError (err )
321+
322+ processes := ctx .ProcessList .Processes ()
323+ require .Len (processes , 1 )
324+ require .Equal ("SELECT foo" , processes [0 ].Query )
325+ require .Equal (
326+ map [string ]sql.TableProgress {
327+ "foo" : {
328+ Progress : sql.Progress {Name : "foo" , Done : 0 , Total : 2 },
329+ PartitionsProgress : map [string ]sql.PartitionProgress {},
330+ },
331+ "bar" : {
332+ Progress : sql.Progress {Name : "bar" , Done : 0 , Total : 4 },
333+ PartitionsProgress : map [string ]sql.PartitionProgress {},
334+ },
335+ },
336+ processes [0 ].Progress )
337+
338+ join , ok := result .(* plan.JoinNode )
339+ require .True (ok )
340+ require .Equal (join .JoinType (), plan .JoinTypeInner )
341+
342+ lhs , ok := join .Left ().(* plan.ResolvedTable )
343+ require .True (ok )
344+ _ , ok = lhs .Table .(* plan.ProcessTable )
345+ require .True (ok )
346+
347+ rhs , ok := join .Right ().(* plan.ResolvedTable )
348+ require .True (ok )
349+ _ , ok = rhs .Table .(* plan.ProcessTable )
350+ require .True (ok )
351+
352+ iter , err := rowexec .DefaultBuilder .Build (ctx , result , nil )
353+ require .NoError (err )
354+ _ , err = sql .RowIterToRows (ctx , iter )
355+ require .NoError (err )
356+
357+ procs := ctx .ProcessList .Processes ()
358+ require .Len (procs , 1 )
359+ require .Equal (sql .ProcessCommandSleep , procs [0 ].Command )
360+ require .Error (ctx .Err ())
361+ }
362+
296363func TestConcurrentProcessList (t * testing.T ) {
297364 enginetest .TestConcurrentProcessList (t , enginetest .NewDefaultMemoryHarness ())
298365}
0 commit comments