github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/expression/expression.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 type Expression interface { 27 fmt.Stringer 28 ReturnType() types.T 29 Eval(stmtCtx *stmtctx.Context, input datum.Row) (datum.Datum, error) 30 } 31 32 // Assignment represents an assignment in INSERT/UPDATE statements. 33 // 34 // e.g: 35 // INSERT VERTEX x LABELS ( Male ) PROPERTIES ( x.age = 22 ) 36 // UPDATE x SET ( x.age = 42 ) FROM MATCH (x:Person) WHERE x.name = 'John' 37 type Assignment struct { 38 VariableRef *VariableRef 39 PropertyRef *PropertyRef 40 Expr Expression 41 } 42 43 // VariableRef represents a variable referenced by other scope. 44 // 45 // e.g: 46 // INSERT VERTEX x LABELS ( Male ) PROPERTIES ( x.age = 22 ) 47 // --------------^------------------------------^---------- 48 type VariableRef struct { 49 Name model.CIStr 50 } 51 52 func (v *VariableRef) String() string { 53 return v.Name.O 54 } 55 56 // PropertyRef represents the accessor of vertex/edge's property. 57 type PropertyRef struct { 58 Property *model.PropertyInfo 59 } 60 61 func (f *PropertyRef) Clone() *PropertyRef { 62 fc := *f 63 return &fc 64 } 65 66 // String implements the fmt.Stringer interface 67 func (f *PropertyRef) String() string { 68 return f.Property.Name.O 69 }