github.com/dolthub/go-mysql-server@v0.18.0/sql/analyzer/resolve_orderby.go (about) 1 // Copyright 2020-2021 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 analyzer 16 17 import ( 18 errors "gopkg.in/src-d/go-errors.v1" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 ) 22 23 var ( 24 // ErrOrderByColumnIndex is returned when in an order clause there is a 25 // column that is unknown. 26 ErrOrderByColumnIndex = errors.NewKind("unknown column %d in order by clause") 27 ) 28 29 // findFirstProjectorNode returns the first sql.Projector node found, starting the search from the specified node. 30 // If the specified node is a sql.Projector, it will be returned, otherwise its children will be searched for the first 31 // Projector until one is found. If no Projector is found, nil is returned. 32 func findFirstProjectorNode(node sql.Node) sql.Projector { 33 children := []sql.Node{node} 34 35 for { 36 if len(children) == 0 { 37 return nil 38 } 39 40 currentChild := children[0] 41 children = children[1:] 42 43 if projector, ok := currentChild.(sql.Projector); ok { 44 return projector 45 } 46 47 children = append(children, currentChild.Children()...) 48 } 49 }