@@ -16,6 +16,7 @@ import (
16
16
"time"
17
17
18
18
"github.com/cockroachdb/cockroach/pkg/build"
19
+ "github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
19
20
"github.com/cockroachdb/cockroach/pkg/keys"
20
21
"github.com/cockroachdb/cockroach/pkg/kv"
21
22
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
@@ -633,6 +634,19 @@ The output can be used to recreate a database.'
633
634
volatility .Volatile ,
634
635
),
635
636
),
637
+ "crdb_internal.session_pending_jobs" : makeBuiltin (
638
+ tree.FunctionProperties {
639
+ Category : builtinconstants .CategorySystemInfo ,
640
+ DistsqlBlocklist : true , // applicable only on the gateway
641
+ },
642
+ makeGeneratorOverload (
643
+ tree.ParamTypes {},
644
+ sessionPendingJobsType ,
645
+ makeSessionPendingJobsGenerator ,
646
+ `Returns rows of information about all pending jobs created in the session txn.` ,
647
+ volatility .Volatile ,
648
+ ),
649
+ ),
636
650
"crdb_internal.decode_plan_gist" : makeBuiltin (
637
651
tree.FunctionProperties {
638
652
Category : builtinconstants .CategorySystemInfo ,
@@ -2875,6 +2889,10 @@ var showCreateAllTriggersGeneratorType = types.String
2875
2889
var showCreateAllTypesGeneratorType = types .String
2876
2890
var showCreateAllTablesGeneratorType = types .String
2877
2891
var showCreateAllRoutinesGeneratorType = types .String
2892
+ var sessionPendingJobsType = types .MakeLabeledTuple (
2893
+ []* types.T {types .Int , types .String , types .String , types .String },
2894
+ []string {"job_id" , "job_type" , "description" , "user_name" },
2895
+ )
2878
2896
2879
2897
// Phase is used to determine if CREATE statements or ALTER statements
2880
2898
// are being generated for showCreateAllTables.
@@ -3372,6 +3390,53 @@ func makeShowCreateAllRoutinesGenerator(
3372
3390
}, nil
3373
3391
}
3374
3392
3393
+ func makeSessionPendingJobsGenerator (
3394
+ ctx context.Context , evalCtx * eval.Context , args tree.Datums ,
3395
+ ) (eval.ValueGenerator , error ) {
3396
+ records := []jobspb.PendingJob {{}} // Next() always pops first, so pad a zero.
3397
+ if err := evalCtx .SessionAccessor .ForEachSessionPendingJob (func (r jobspb.PendingJob ) error {
3398
+ records = append (records , r )
3399
+ return nil
3400
+ }); err != nil {
3401
+ return nil , err
3402
+ }
3403
+ return & sessionPendingJobsGenerator {
3404
+ jobs : records ,
3405
+ }, nil
3406
+ }
3407
+
3408
+ type sessionPendingJobsGenerator struct {
3409
+ jobs []jobspb.PendingJob
3410
+ }
3411
+
3412
+ // ResolvedType implements the eval.ValueGenerator interface.
3413
+ func (s * sessionPendingJobsGenerator ) ResolvedType () * types.T {
3414
+ return sessionPendingJobsType
3415
+ }
3416
+
3417
+ // Start implements the eval.ValueGenerator interface.
3418
+ func (s * sessionPendingJobsGenerator ) Start (ctx context.Context , txn * kv.Txn ) error {
3419
+ return nil
3420
+ }
3421
+
3422
+ func (s * sessionPendingJobsGenerator ) Next (ctx context.Context ) (bool , error ) {
3423
+ s .jobs = s .jobs [1 :]
3424
+ return len (s .jobs ) > 0 , nil
3425
+ }
3426
+
3427
+ // Values implements the eval.ValueGenerator interface.
3428
+ func (s * sessionPendingJobsGenerator ) Values () (tree.Datums , error ) {
3429
+ return tree.Datums {tree .NewDInt (tree .DInt (s .jobs [0 ].JobID )),
3430
+ tree .NewDString (s .jobs [0 ].Type .String ()),
3431
+ tree .NewDString (s .jobs [0 ].Description ),
3432
+ tree .NewDString (s .jobs [0 ].Username .Normalized ()),
3433
+ }, nil
3434
+ }
3435
+
3436
+ // Close implements the eval.ValueGenerator interface.
3437
+ func (s * sessionPendingJobsGenerator ) Close (ctx context.Context ) {
3438
+ }
3439
+
3375
3440
// identGenerator supports the execution of
3376
3441
// crdb_internal.gen_rand_ident().
3377
3442
type identGenerator struct {
0 commit comments