@@ -4,14 +4,17 @@ import (
4
4
"testing"
5
5
6
6
"github.com/stretchr/testify/require"
7
+ enumspb "go.temporal.io/api/enums/v1"
7
8
"go.temporal.io/api/serviceerror"
9
+ "go.temporal.io/server/common/dynamicconfig"
8
10
"go.temporal.io/server/common/namespace"
9
11
"go.temporal.io/server/common/persistence/visibility/store/query"
10
12
"go.temporal.io/server/common/searchattribute"
11
13
)
12
14
13
15
const (
14
- testNamespace = namespace .Name ("test-namespace" )
16
+ testNamespace = namespace .Name ("test-namespace" )
17
+ testNamespaceID = namespace .ID ("test-namespace-id" )
15
18
)
16
19
17
20
func TestFieldNameAggInterceptor (t * testing.T ) {
@@ -38,7 +41,62 @@ func TestFieldNameAggInterceptor(t *testing.T) {
38
41
s .Error (err )
39
42
}
40
43
41
- func TestGetQueryFields (t * testing.T ) {
44
+ func TestFieldSaAggInterceptor (t * testing.T ) {
45
+ s := require .New (t )
46
+ saInterceptor := newSaAggInterceptor ()
47
+ intCol := query .NewSAColName (
48
+ "AliasForCustomIntField" ,
49
+ "CustomIntField" ,
50
+ enumspb .INDEXED_VALUE_TYPE_INT ,
51
+ )
52
+ keywordCol := query .NewSAColName (
53
+ "AliasForCustomKeywordField" ,
54
+ "CustomKeywordField" ,
55
+ enumspb .INDEXED_VALUE_TYPE_KEYWORD ,
56
+ )
57
+ startTimeCol := query .NewSAColName (
58
+ searchattribute .StartTime ,
59
+ searchattribute .StartTime ,
60
+ enumspb .INDEXED_VALUE_TYPE_DATETIME ,
61
+ )
62
+
63
+ err := saInterceptor .Intercept (intCol )
64
+ s .NoError (err )
65
+ s .Equal (map [string ]bool {"AliasForCustomIntField" : true }, saInterceptor .names )
66
+
67
+ err = saInterceptor .Intercept (keywordCol )
68
+ s .NoError (err )
69
+ s .Equal (
70
+ map [string ]bool {
71
+ "AliasForCustomIntField" : true ,
72
+ "AliasForCustomKeywordField" : true ,
73
+ },
74
+ saInterceptor .names ,
75
+ )
76
+
77
+ err = saInterceptor .Intercept (intCol )
78
+ s .NoError (err )
79
+ s .Equal (
80
+ map [string ]bool {
81
+ "AliasForCustomIntField" : true ,
82
+ "AliasForCustomKeywordField" : true ,
83
+ },
84
+ saInterceptor .names ,
85
+ )
86
+
87
+ err = saInterceptor .Intercept (startTimeCol )
88
+ s .NoError (err )
89
+ s .Equal (
90
+ map [string ]bool {
91
+ "AliasForCustomIntField" : true ,
92
+ "AliasForCustomKeywordField" : true ,
93
+ searchattribute .StartTime : true ,
94
+ },
95
+ saInterceptor .names ,
96
+ )
97
+ }
98
+
99
+ func TestGetQueryFieldsLegacy (t * testing.T ) {
42
100
testCases := []struct {
43
101
name string
44
102
input string
@@ -101,13 +159,104 @@ func TestGetQueryFields(t *testing.T) {
101
159
},
102
160
}
103
161
162
+ for _ , tc := range testCases {
163
+ t .Run (
164
+ tc .name ,
165
+ func (t * testing.T ) {
166
+ s := require .New (t )
167
+ fields , err := getQueryFieldsLegacy (
168
+ testNamespace ,
169
+ searchattribute .TestNameTypeMap ,
170
+ searchattribute .NewTestMapperProvider (nil ),
171
+ tc .input ,
172
+ )
173
+ if tc .expectedErrMsg == "" {
174
+ s .NoError (err )
175
+ s .Equal (len (tc .expectedFields ), len (fields ))
176
+ for _ , f := range fields {
177
+ s .Contains (tc .expectedFields , f )
178
+ }
179
+ } else {
180
+ var invalidArgErr * serviceerror.InvalidArgument
181
+ s .ErrorAs (err , & invalidArgErr )
182
+ s .ErrorContains (err , tc .expectedErrMsg )
183
+ }
184
+ },
185
+ )
186
+ }
187
+ }
188
+
189
+ func TestGetQueryFields (t * testing.T ) {
190
+ testCases := []struct {
191
+ name string
192
+ input string
193
+ expectedFields []string
194
+ expectedErrMsg string
195
+ }{
196
+ {
197
+ name : "empty query string" ,
198
+ input : "" ,
199
+ expectedFields : []string {},
200
+ expectedErrMsg : "" ,
201
+ },
202
+ {
203
+ name : "filter custom search attribute" ,
204
+ input : "CustomKeywordField = 'foo'" ,
205
+ expectedFields : []string {"CustomKeywordField" },
206
+ expectedErrMsg : "" ,
207
+ },
208
+ {
209
+ name : "filter multiple custom search attribute" ,
210
+ input : "(CustomKeywordField = 'foo' AND CustomIntField = 123) OR CustomKeywordField = 'bar'" ,
211
+ expectedFields : []string {"CustomKeywordField" , "CustomIntField" },
212
+ expectedErrMsg : "" ,
213
+ },
214
+ {
215
+ name : "filter TemporalSchedulePaused" ,
216
+ input : "TemporalSchedulePaused = true" ,
217
+ expectedFields : []string {"TemporalSchedulePaused" },
218
+ expectedErrMsg : "" ,
219
+ },
220
+ {
221
+ name : "filter TemporalSchedulePaused" ,
222
+ input : "TemporalSchedulePaused = true" ,
223
+ expectedFields : []string {"TemporalSchedulePaused" },
224
+ expectedErrMsg : "" ,
225
+ },
226
+ {
227
+ name : "filter TemporalSchedulePaused and custom search attribute" ,
228
+ input : "TemporalSchedulePaused = true AND CustomKeywordField = 'foo'" ,
229
+ expectedFields : []string {"TemporalSchedulePaused" , "CustomKeywordField" },
230
+ expectedErrMsg : "" ,
231
+ },
232
+ {
233
+ name : "filter system search attribute" ,
234
+ input : "ExecutionDuration > '1s'" ,
235
+ expectedFields : []string {"ExecutionDuration" },
236
+ expectedErrMsg : "" ,
237
+ },
238
+ {
239
+ name : "invalid query filter" ,
240
+ input : "CustomKeywordField = foo" ,
241
+ expectedFields : nil ,
242
+ expectedErrMsg : "invalid query" ,
243
+ },
244
+ {
245
+ name : "invalid custom search attribute" ,
246
+ input : "Foo = 'bar'" ,
247
+ expectedFields : nil ,
248
+ expectedErrMsg : "'Foo' is not a valid search attribute" ,
249
+ },
250
+ }
251
+
104
252
for _ , tc := range testCases {
105
253
t .Run (
106
254
tc .name ,
107
255
func (t * testing.T ) {
108
256
s := require .New (t )
109
257
fields , err := getQueryFields (
110
258
testNamespace ,
259
+ testNamespaceID ,
111
260
searchattribute .TestNameTypeMap ,
112
261
searchattribute .NewTestMapperProvider (nil ),
113
262
tc .input ,
@@ -177,7 +326,7 @@ func TestValidateVisibilityQuery(t *testing.T) {
177
326
{
178
327
name : "invalid custom search attribute" ,
179
328
input : "Foo = foo" ,
180
- expectedErrMsg : "invalid search attribute: Foo " ,
329
+ expectedErrMsg : "'Foo' is not a valid search attribute" ,
181
330
},
182
331
}
183
332
@@ -188,8 +337,10 @@ func TestValidateVisibilityQuery(t *testing.T) {
188
337
s := require .New (t )
189
338
err := ValidateVisibilityQuery (
190
339
testNamespace ,
340
+ testNamespaceID ,
191
341
searchattribute .TestNameTypeMap ,
192
342
searchattribute .NewTestMapperProvider (nil ),
343
+ dynamicconfig .GetBoolPropertyFn (true ),
193
344
tc .input ,
194
345
)
195
346
if tc .expectedErrMsg == "" {
0 commit comments