github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/expression/column.go (about) 1 // Copyright 2023 zGraph Authors. All rights reserved. 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/vescale/zgraph/datum" 21 "github.com/vescale/zgraph/parser/model" 22 "github.com/vescale/zgraph/stmtctx" 23 "github.com/vescale/zgraph/types" 24 ) 25 26 var _ Expression = &Column{} 27 28 type Column struct { 29 Index int 30 Name model.CIStr 31 Type types.T 32 } 33 34 func (c *Column) String() string { 35 return c.Name.O 36 } 37 38 func (c *Column) ReturnType() types.T { 39 return c.Type 40 } 41 42 func (c *Column) Eval(stmtCtx *stmtctx.Context, input datum.Row) (datum.Datum, error) { 43 if c.Index >= len(input) { 44 return nil, fmt.Errorf("column index %d out of input row length %d", c.Index, len(input)) 45 } 46 return input[c.Index], nil 47 }