github.com/dolthub/go-mysql-server@v0.18.0/sql/expression/star.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 expression 16 17 import ( 18 "fmt" 19 20 "github.com/dolthub/go-mysql-server/sql" 21 ) 22 23 // Star represents the selection of all available fields. 24 // This is just a placeholder node, it will not actually be evaluated 25 // but converted to a series of GetFields when the query is analyzed. 26 type Star struct { 27 Table string 28 } 29 30 var _ sql.Expression = (*Star)(nil) 31 var _ sql.CollationCoercible = (*Star)(nil) 32 33 // NewStar returns a new Star expression. 34 func NewStar() *Star { 35 return new(Star) 36 } 37 38 // NewQualifiedStar returns a new star expression only for a specific table. 39 func NewQualifiedStar(table string) *Star { 40 return &Star{table} 41 } 42 43 // Resolved implements the Expression interface. 44 func (*Star) Resolved() bool { 45 return false 46 } 47 48 // Children implements the Expression interface. 49 func (*Star) Children() []sql.Expression { 50 return nil 51 } 52 53 // IsNullable implements the Expression interface. 54 func (*Star) IsNullable() bool { 55 return false 56 } 57 58 // Type implements the Expression interface. 59 func (*Star) Type() sql.Type { 60 panic("star is just a placeholder node, but Type was called") 61 } 62 63 // CollationCoercibility implements the interface sql.CollationCoercible. 64 func (*Star) CollationCoercibility(ctx *sql.Context) (collation sql.CollationID, coercibility byte) { 65 return sql.Collation_binary, 7 66 } 67 68 func (s *Star) String() string { 69 if s.Table != "" { 70 return fmt.Sprintf("%s.*", s.Table) 71 } 72 return "*" 73 } 74 75 // Eval implements the Expression interface. 76 func (*Star) Eval(ctx *sql.Context, r sql.Row) (interface{}, error) { 77 panic("star is just a placeholder node, but Eval was called") 78 } 79 80 // WithChildren implements the Expression interface. 81 func (s *Star) WithChildren(children ...sql.Expression) (sql.Expression, error) { 82 if len(children) != 0 { 83 return nil, sql.ErrInvalidChildrenNumber.New(s, len(children), 0) 84 } 85 return s, nil 86 }