-
Notifications
You must be signed in to change notification settings - Fork 1
/
bool.go
65 lines (56 loc) · 1.23 KB
/
bool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package value
import (
"errors"
"strconv"
"strings"
"github.com/deepfabric/vectorsql/pkg/vm/types"
)
func NewBool(v bool) *Bool {
if v {
return &ConstTrue
}
return &ConstFalse
}
func (a *Bool) String() string {
return strconv.FormatBool(bool(*a))
}
func (_ *Bool) ResolvedType() types.T {
return types.T_bool
}
func ParseBool(s string) (*Bool, error) {
s = strings.TrimSpace(s)
if len(s) >= 1 {
switch s[0] {
case 't', 'T':
if isCaseInsensitivePrefix(s, "true") {
return &ConstTrue, nil
}
case 'f', 'F':
if isCaseInsensitivePrefix(s, "false") {
return &ConstFalse, nil
}
}
}
return nil, makeParseError(s, types.T_bool, errors.New("invalid bool value"))
}
func (a *Bool) Compare(v Value) int {
b, ok := v.(*Bool)
if !ok {
panic(makeUnsupportedComparisonMessage(a, v))
}
return CompareBool(bool(*a), bool(*b))
}
// CompareBool compare the input bools according to the SQL comparison rules.
func CompareBool(d, v bool) int {
if !d && v {
return -1
}
if d && !v {
return 1
}
return 0
}
func (_ *Bool) Size() int { return 2 }
func (_ *Bool) IsLogical() bool { return true }
func (_ *Bool) IsAndOnly() bool { return true }
func (_ *Bool) Attributes() []string { return []string{} }