github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/union.go (about) 1 // Copyright 2021 Matrix Origin 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 "fmt" 18 19 // the UNION statement 20 type UnionClause struct { 21 SelectStatement 22 Type UnionType 23 //Left, Right *Select 24 Left, Right SelectStatement 25 All bool 26 Distinct bool 27 } 28 29 func (node *UnionClause) Format(ctx *FmtCtx) { 30 node.Left.Format(ctx) 31 ctx.WriteByte(' ') 32 ctx.WriteString(node.Type.String()) 33 if node.All { 34 ctx.WriteString(" all") 35 } 36 if node.Distinct { 37 ctx.WriteString(" distinct") 38 } 39 ctx.WriteByte(' ') 40 node.Right.Format(ctx) 41 } 42 43 type UnionTypeRecord struct { 44 Type UnionType 45 All bool 46 Distinct bool 47 } 48 49 // UnionType set operations 50 type UnionType int 51 52 const ( 53 UNION UnionType = iota 54 INTERSECT 55 EXCEPT 56 UT_MINUS 57 ) 58 59 var unionTypeName = [...]string{ 60 UNION: "union", 61 INTERSECT: "intersect", 62 EXCEPT: "except", 63 UT_MINUS: "minus", 64 } 65 66 func (i UnionType) String() string { 67 if i < 0 || i > UnionType(len(unionTypeName)-1) { 68 return fmt.Sprintf("UnionType(%d)", i) 69 } 70 return unionTypeName[i] 71 } 72 73 // func NewUnionClause(t UnionType,l,r *Select,a bool)*UnionClause{ 74 func NewUnionClause(t UnionType, l, r SelectStatement, a bool) *UnionClause { 75 return &UnionClause{ 76 Type: t, 77 Left: l, 78 Right: r, 79 All: a, 80 } 81 }