github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/kill.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tree 16 17 import "fmt" 18 19 type KillType int 20 21 const ( 22 KillTypeConnection KillType = iota 23 KillTypeQuery 24 ) 25 26 func (k KillType) String() string { 27 switch k { 28 case KillTypeConnection: 29 return "connection" 30 case KillTypeQuery: 31 return "query" 32 default: 33 return "" 34 } 35 } 36 37 type KillOption struct { 38 Exist bool 39 Typ KillType 40 } 41 42 func (ko KillOption) Format(ctx *FmtCtx) { 43 if ko.Exist { 44 ctx.WriteString(ko.Typ.String()) 45 } 46 } 47 48 type StatementOption struct { 49 Exist bool 50 StatementId string 51 } 52 53 func (so StatementOption) Format(ctx *FmtCtx) { 54 if so.Exist { 55 ctx.WriteString(so.StatementId) 56 } 57 } 58 59 type Kill struct { 60 statementImpl 61 Option KillOption 62 ConnectionId uint64 63 StmtOption StatementOption 64 } 65 66 func (k *Kill) Format(ctx *FmtCtx) { 67 ctx.WriteString("kill") 68 if k.Option.Exist { 69 ctx.WriteByte(' ') 70 k.Option.Format(ctx) 71 } 72 ctx.WriteByte(' ') 73 ctx.WriteString(fmt.Sprintf("%d", k.ConnectionId)) 74 if k.StmtOption.Exist { 75 ctx.WriteByte(' ') 76 ctx.WriteByte('"') 77 ctx.WriteString(k.StmtOption.StatementId) 78 ctx.WriteByte('"') 79 } 80 } 81 82 func (k *Kill) GetStatementType() string { return "kill" } 83 func (k *Kill) GetQueryType() string { return QueryTypeOth }