github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/datum.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 var ( 18 constDBoolTrue DBool = true 19 constDBoolFalse DBool = false 20 21 DBoolTrue = &constDBoolTrue 22 DBoolFalse = &constDBoolFalse 23 24 DNull Datum = &dNull{} 25 ) 26 27 type Datum interface { 28 Expr 29 } 30 31 type DBool bool 32 33 func (node *DBool) Format(ctx *FmtCtx) { 34 ctx.WriteString(node.String()) 35 } 36 37 func (node *DBool) String() string { 38 if *node { 39 return "true" 40 } else { 41 return "false" 42 } 43 } 44 45 func MakeDBool(d bool) *DBool { 46 if d { 47 return DBoolTrue 48 } 49 return DBoolFalse 50 } 51 52 type dNull struct { 53 Datum 54 } 55 56 func (node *dNull) Format(ctx *FmtCtx) { 57 ctx.WriteString("null") 58 }