-
Notifications
You must be signed in to change notification settings - Fork 675
/
conditions.go
119 lines (105 loc) · 4.38 KB
/
conditions.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* _ _
*__ _____ __ ___ ___ __ _| |_ ___
*\ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
* \ V V / __/ (_| |\ V /| | (_| | || __/
* \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
*
* Copyright © 2016 - 2019 Weaviate. All rights reserved.
* LICENSE: https://github.com/creativesoftwarefdn/weaviate/blob/develop/LICENSE.md
* DESIGN & CONCEPT: Bob van Luijt (@bobvanluijt)
* CONTACT: hello@creativesoftwarefdn.org
*/package fetch
import (
"fmt"
"time"
"github.com/creativesoftwarefdn/weaviate/database/schema"
"github.com/creativesoftwarefdn/weaviate/graphqlapi/local/common_filters"
"github.com/creativesoftwarefdn/weaviate/graphqlapi/local/fetch"
"github.com/creativesoftwarefdn/weaviate/gremlin"
)
func (b *Query) conditionQuery(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Value.Type {
case schema.DataTypeString:
return b.stringCondition(match)
case schema.DataTypeText:
return nil, fmt.Errorf("indexing/searching not allowed on prop type text")
case schema.DataTypeBoolean:
return b.boolCondition(match)
case schema.DataTypeInt:
return b.intCondition(match)
case schema.DataTypeNumber:
return b.numberCondition(match)
case schema.DataTypeDate:
return b.dateCondition(match)
}
return nil, fmt.Errorf("unsupported combination of operator and value")
}
func (b *Query) stringCondition(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Operator {
case common_filters.OperatorEqual:
return gremlin.EqString(match.Value.Value.(string)), nil
case common_filters.OperatorNotEqual:
return gremlin.NeqString(match.Value.Value.(string)), nil
}
return nil, fmt.Errorf("unsupported combination of operator and string value")
}
func (b *Query) boolCondition(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Operator {
case common_filters.OperatorEqual:
return gremlin.EqBool(match.Value.Value.(bool)), nil
case common_filters.OperatorNotEqual:
return gremlin.NeqBool(match.Value.Value.(bool)), nil
}
return nil, fmt.Errorf("unsupported combination of operator and boolean value")
}
func (b *Query) intCondition(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Operator {
case common_filters.OperatorEqual:
return gremlin.EqInt(match.Value.Value.(int)), nil
case common_filters.OperatorNotEqual:
return gremlin.NeqInt(match.Value.Value.(int)), nil
case common_filters.OperatorLessThan:
return gremlin.LtInt(match.Value.Value.(int)), nil
case common_filters.OperatorGreaterThan:
return gremlin.GtInt(match.Value.Value.(int)), nil
case common_filters.OperatorLessThanEqual:
return gremlin.LteInt(match.Value.Value.(int)), nil
case common_filters.OperatorGreaterThanEqual:
return gremlin.GteInt(match.Value.Value.(int)), nil
}
return nil, fmt.Errorf("unsupported combination of operator and int value")
}
func (b *Query) numberCondition(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Operator {
case common_filters.OperatorEqual:
return gremlin.EqFloat(match.Value.Value.(float64)), nil
case common_filters.OperatorNotEqual:
return gremlin.NeqFloat(match.Value.Value.(float64)), nil
case common_filters.OperatorLessThan:
return gremlin.LtFloat(match.Value.Value.(float64)), nil
case common_filters.OperatorGreaterThan:
return gremlin.GtFloat(match.Value.Value.(float64)), nil
case common_filters.OperatorLessThanEqual:
return gremlin.LteFloat(match.Value.Value.(float64)), nil
case common_filters.OperatorGreaterThanEqual:
return gremlin.GteFloat(match.Value.Value.(float64)), nil
}
return nil, fmt.Errorf("unsupported combination of operator and number value")
}
func (b *Query) dateCondition(match fetch.PropertyMatch) (*gremlin.Query, error) {
switch match.Operator {
case common_filters.OperatorEqual:
return gremlin.EqDate(match.Value.Value.(time.Time)), nil
case common_filters.OperatorNotEqual:
return gremlin.NeqDate(match.Value.Value.(time.Time)), nil
case common_filters.OperatorLessThan:
return gremlin.LtDate(match.Value.Value.(time.Time)), nil
case common_filters.OperatorGreaterThan:
return gremlin.GtDate(match.Value.Value.(time.Time)), nil
case common_filters.OperatorLessThanEqual:
return gremlin.LteDate(match.Value.Value.(time.Time)), nil
case common_filters.OperatorGreaterThanEqual:
return gremlin.GteDate(match.Value.Value.(time.Time)), nil
}
return nil, fmt.Errorf("unsupported combination of operator and date value")
}