github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/sql/tree/LogicalBinaryExpression.go (about) 1 // Copyright (c) 2017-2018 Uber Technologies, 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 tree 16 17 import ( 18 "fmt" 19 20 "github.com/uber/aresdb/query/sql/util" 21 ) 22 23 // LogicalBinaryExpression is IExpression 24 type LogicalBinaryExpression struct { 25 IExpression 26 LogicType LogicalBinaryExpType 27 Left IExpression 28 Right IExpression 29 } 30 31 // LogicalBinaryExpType is logical binary exp type 32 type LogicalBinaryExpType int 33 34 const ( 35 // AND is logic 36 AND LogicalBinaryExpType = iota 37 // OR is logic 38 OR 39 // NOOP is logic 40 NOOP 41 ) 42 43 // LogicalBinaryExpTypes is logical binary exp type strings 44 var LogicalBinaryExpTypes = [...]string{ 45 "AND", 46 "OR", 47 "NOOP", 48 } 49 50 // NewLogicalBinaryExpression creates LogicalBinaryExpression 51 func NewLogicalBinaryExpression(location *NodeLocation, logicType LogicalBinaryExpType, 52 left, right IExpression) *LogicalBinaryExpression { 53 errMsg := fmt.Sprintf("type is null at (line:%d, col:%d)", location.Line, location.CharPosition) 54 util.RequireNonNull(logicType, errMsg) 55 errMsg = fmt.Sprintf("left is null at (line:%d, col:%d)", location.Line, location.CharPosition) 56 util.RequireNonNull(left, errMsg) 57 errMsg = fmt.Sprintf("right is null at (line:%d, col:%d)", location.Line, location.CharPosition) 58 util.RequireNonNull(right, errMsg) 59 60 return &LogicalBinaryExpression{ 61 NewExpression(location), 62 logicType, 63 left, 64 right, 65 } 66 } 67 68 // Accept accepts visitor 69 func (e *LogicalBinaryExpression) Accept(visitor AstVisitor, ctx interface{}) interface{} { 70 return visitor.VisitLogicalBinaryExpression(e, ctx) 71 }