github.com/dolthub/go-mysql-server@v0.18.0/sql/planbuilder/process.go (about) 1 // Copyright 2023 Dolthub, Inc. 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 planbuilder 16 17 import ( 18 ast "github.com/dolthub/vitess/go/vt/sqlparser" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 "github.com/dolthub/go-mysql-server/sql/expression" 22 "github.com/dolthub/go-mysql-server/sql/plan" 23 "github.com/dolthub/go-mysql-server/sql/types" 24 ) 25 26 func (b *Builder) buildKill(inScope *scope, kill *ast.Kill) (outScope *scope) { 27 outScope = inScope.push() 28 connID64 := b.getInt64Value(inScope, kill.ConnID, "Error parsing KILL, expected int literal") 29 connID32 := uint32(connID64) 30 if int64(connID32) != connID64 { 31 err := sql.ErrUnsupportedFeature.New("int literal is not unsigned 32-bit.") 32 b.handleErr(err) 33 } 34 if kill.Connection { 35 outScope.node = plan.NewKill(plan.KillType_Connection, connID32) 36 } else { 37 outScope.node = plan.NewKill(plan.KillType_Query, connID32) 38 } 39 return outScope 40 } 41 42 // getInt64Value returns the int64 literal value in the expression given, or an error with the errStr given if it 43 // cannot. 44 func (b *Builder) getInt64Value(inScope *scope, expr ast.Expr, errStr string) int64 { 45 ie := b.getInt64Literal(inScope, expr, errStr) 46 47 i, err := ie.Eval(b.ctx, nil) 48 if err != nil { 49 b.handleErr(err) 50 } 51 52 return i.(int64) 53 } 54 55 // getInt64Literal returns an int64 *expression.Literal for the value given, or an unsupported error with the string 56 // given if the expression doesn't represent an integer literal. 57 func (b *Builder) getInt64Literal(inScope *scope, expr ast.Expr, errStr string) *expression.Literal { 58 e := b.buildScalar(inScope, expr) 59 60 switch e := e.(type) { 61 case *expression.Literal: 62 if !types.IsInteger(e.Type()) { 63 err := sql.ErrUnsupportedFeature.New(errStr) 64 b.handleErr(err) 65 } 66 } 67 nl, ok := e.(*expression.Literal) 68 if !ok || !types.IsInteger(nl.Type()) { 69 err := sql.ErrUnsupportedFeature.New(errStr) 70 b.handleErr(err) 71 } else { 72 i64, _, err := types.Int64.Convert(nl.Value()) 73 if err != nil { 74 err := sql.ErrUnsupportedFeature.New(errStr) 75 b.handleErr(err) 76 } 77 return expression.NewLiteral(i64, types.Int64) 78 } 79 80 return nl 81 }