github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/sql/tree/Join.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 // Join is Join 24 type Join struct { 25 // IRelation is interface 26 IRelation 27 // Type is join type 28 Type JoinType 29 // Left is IRelation 30 Left IRelation 31 // Right is IRelation 32 Right IRelation 33 // Criteria is on condition 34 Criteria IJoinCriteria 35 } 36 37 // JoinType is join type 38 type JoinType int 39 40 const ( 41 // CROSS is CROSS 42 CROSS JoinType = iota 43 // INNER is INNER 44 INNER 45 // LEFT is LEFT 46 LEFT 47 // RIGHT is RIGHT 48 RIGHT 49 // FULL is FULL 50 FULL 51 // IMPLICIT is IMPLICIT 52 IMPLICIT 53 ) 54 55 // JoinTypes is join type strings 56 var JoinTypes = [...]string{ 57 "CROSS", 58 "INNER", 59 "LEFT", 60 "RIGHT", 61 "FULL", 62 "IMPLICIT", 63 } 64 65 // NewJoin creates Join 66 func NewJoin(location *NodeLocation, joinType JoinType, left, right IRelation, criteria IJoinCriteria) *Join { 67 errMsg := fmt.Sprintf("left is null at (line:%d, col:%d)", location.Line, location.CharPosition) 68 util.RequireNonNull(left, errMsg) 69 errMsg = fmt.Sprintf("right is null at (line:%d, col:%d)", location.Line, location.CharPosition) 70 util.RequireNonNull(right, errMsg) 71 72 if joinType != LEFT { 73 panic(fmt.Errorf("only support left join at (line:%d, col:%d)", location.Line, location.CharPosition)) 74 } 75 76 return &Join{ 77 NewRelation(location), 78 joinType, 79 left, 80 right, 81 criteria, 82 } 83 } 84 85 // Accept accepts visitor 86 func (e *Join) Accept(visitor AstVisitor, ctx interface{}) interface{} { 87 return visitor.VisitJoin(e, ctx) 88 }