github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/run_control.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package tree 12 13 // ControlJobs represents a PAUSE/RESUME/CANCEL JOBS statement. 14 type ControlJobs struct { 15 Jobs *Select 16 Command JobCommand 17 } 18 19 // JobCommand determines which type of action to effect on the selected job(s). 20 type JobCommand int 21 22 // JobCommand values 23 const ( 24 PauseJob JobCommand = iota 25 CancelJob 26 ResumeJob 27 ) 28 29 // JobCommandToStatement translates a job command integer to a statement prefix. 30 var JobCommandToStatement = map[JobCommand]string{ 31 PauseJob: "PAUSE", 32 CancelJob: "CANCEL", 33 ResumeJob: "RESUME", 34 } 35 36 // Format implements the NodeFormatter interface. 37 func (n *ControlJobs) Format(ctx *FmtCtx) { 38 ctx.WriteString(JobCommandToStatement[n.Command]) 39 ctx.WriteString(" JOBS ") 40 ctx.FormatNode(n.Jobs) 41 } 42 43 // CancelQueries represents a CANCEL QUERIES statement. 44 type CancelQueries struct { 45 Queries *Select 46 IfExists bool 47 } 48 49 // Format implements the NodeFormatter interface. 50 func (node *CancelQueries) Format(ctx *FmtCtx) { 51 ctx.WriteString("CANCEL QUERIES ") 52 if node.IfExists { 53 ctx.WriteString("IF EXISTS ") 54 } 55 ctx.FormatNode(node.Queries) 56 } 57 58 // CancelSessions represents a CANCEL SESSIONS statement. 59 type CancelSessions struct { 60 Sessions *Select 61 IfExists bool 62 } 63 64 // Format implements the NodeFormatter interface. 65 func (node *CancelSessions) Format(ctx *FmtCtx) { 66 ctx.WriteString("CANCEL SESSIONS ") 67 if node.IfExists { 68 ctx.WriteString("IF EXISTS ") 69 } 70 ctx.FormatNode(node.Sessions) 71 }