/
unparsed_query.go
679 lines (615 loc) · 19.9 KB
/
unparsed_query.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
package query
import (
"errors"
"fmt"
"strings"
"time"
"github.com/xichen2020/eventdb/calculation"
"github.com/xichen2020/eventdb/document/field"
"github.com/xichen2020/eventdb/filter"
"github.com/xichen2020/eventdb/generated/proto/servicepb"
"github.com/xichen2020/eventdb/x/bytes"
"github.com/xichen2020/eventdb/x/convert"
"github.com/xichen2020/eventdb/x/hash"
protoconvert "github.com/xichen2020/eventdb/x/proto/convert"
"github.com/xichen2020/eventdb/x/safe"
xtime "github.com/xichen2020/eventdb/x/time"
m3xtime "github.com/m3db/m3/src/x/time"
)
const (
defaultTimeUnit = xtime.Unit(m3xtime.Second)
defaultFilterCombinator = filter.And
defaultRawQuerySizeLimit = 100
defaultGroupedQuerySizeLimit = 10
defaultOrderBySortOrder = Ascending
maxGranularityRangeScaleFactor = 10
minGranularityRangeScaleFactor = 1000
)
var (
errNoNamespaceInQuery = errors.New("no namespace provided in query")
errStartAndEndRequiredWithNoRange = errors.New("both start time and end time required when no time range is specified")
errNoFieldInFilter = errors.New("no field specified in query filter")
errNoFieldInOrderByForRawQuery = errors.New("no field specified for raw query")
errNoFieldOrOpInOrderByForGroupedQuery = errors.New("no field or op specified in order by for grouped query")
errTimeGranularityWithGroupBy = errors.New("both time granularity and group by clauses are specified in the query")
errTimeGranularityWithCalculations = errors.New("both time granularity and calculation clauses are specified in the query")
errTimeGranularityWithOrderBy = errors.New("both time granularity and order by clauses are specified in the query")
errCalculationsWithNoGroups = errors.New("calculations provided with no groups")
errNoTimeGranularityInTimeBucketQuery = errors.New("no time granularity in time bucket query")
)
// TODO(xichen): Use different types for raw/grouped/bucket queries.
// Define different type aliases for now.
// UnparsedRawQuery is an unparsed raw query.
type UnparsedRawQuery UnparsedQuery
// Parse parses an unparsed raw query into a parsed raw query.
func (q *UnparsedRawQuery) Parse(opts ParseOptions) (ParsedRawQuery, error) {
parsed, err := ((*UnparsedQuery)(q)).Parse(opts)
if err != nil {
return ParsedRawQuery{}, err
}
return parsed.RawQuery()
}
// ToProto converts an unparsed raw query to an unparsed raw query protobuf message.
func (q *UnparsedRawQuery) ToProto() (*servicepb.RawQuery, error) {
tu, err := q.TimeUnit.ToProto()
if err != nil {
return nil, err
}
filterLists, err := q.Filters.ToProto()
if err != nil {
return nil, err
}
orderByList, err := q.OrderBy.ToProto()
if err != nil {
return nil, err
}
return &servicepb.RawQuery{
Namespace: q.Namespace,
StartTime: protoconvert.Int64PtrToOptionalInt64(q.StartTime),
EndTime: protoconvert.Int64PtrToOptionalInt64(q.EndTime),
TimeUnit: tu,
TimeRangeInNanos: protoconvert.DurationPtrToOptionalInt64(q.TimeRange),
Filters: filterLists,
OrderBy: orderByList,
Limit: protoconvert.IntPtrToOptionalInt64(q.Limit),
}, nil
}
// UnparsedGroupedQuery is an unparsed grouped query.
type UnparsedGroupedQuery UnparsedQuery
// Parse parses an unparsed grouped query into a parsed grouped query.
func (q *UnparsedGroupedQuery) Parse(opts ParseOptions) (ParsedGroupedQuery, error) {
parsed, err := ((*UnparsedQuery)(q)).Parse(opts)
if err != nil {
return ParsedGroupedQuery{}, err
}
return parsed.GroupedQuery()
}
// ToProto converts an unparsed grouped query to an unparsed grouped query protobuf message.
func (q *UnparsedGroupedQuery) ToProto() (*servicepb.GroupedQuery, error) {
tu, err := q.TimeUnit.ToProto()
if err != nil {
return nil, err
}
filterLists, err := q.Filters.ToProto()
if err != nil {
return nil, err
}
calculations, err := q.Calculations.ToProto()
if err != nil {
return nil, err
}
orderByList, err := q.OrderBy.ToProto()
if err != nil {
return nil, err
}
return &servicepb.GroupedQuery{
Namespace: q.Namespace,
StartTime: protoconvert.Int64PtrToOptionalInt64(q.StartTime),
EndTime: protoconvert.Int64PtrToOptionalInt64(q.EndTime),
TimeUnit: tu,
TimeRangeInNanos: protoconvert.DurationPtrToOptionalInt64(q.TimeRange),
Filters: filterLists,
GroupBy: q.GroupBy,
Calculations: calculations,
OrderBy: orderByList,
Limit: protoconvert.IntPtrToOptionalInt64(q.Limit),
}, nil
}
// UnparsedTimeBucketQuery is an unparsed time bucket query.
type UnparsedTimeBucketQuery UnparsedQuery
// Parse parses an unparsed grouped query into a parsed grouped query.
func (q *UnparsedTimeBucketQuery) Parse(opts ParseOptions) (ParsedTimeBucketQuery, error) {
parsed, err := ((*UnparsedQuery)(q)).Parse(opts)
if err != nil {
return ParsedTimeBucketQuery{}, err
}
return parsed.TimeBucketQuery()
}
// ToProto converts an unparsed time bucket query to an unparsed time bucket query protobuf message.
func (q *UnparsedTimeBucketQuery) ToProto() (*servicepb.TimeBucketQuery, error) {
if q.TimeGranularity == nil {
return nil, errNoTimeGranularityInTimeBucketQuery
}
tu, err := q.TimeUnit.ToProto()
if err != nil {
return nil, err
}
filterLists, err := q.Filters.ToProto()
if err != nil {
return nil, err
}
return &servicepb.TimeBucketQuery{
Namespace: q.Namespace,
StartTime: protoconvert.Int64PtrToOptionalInt64(q.StartTime),
EndTime: protoconvert.Int64PtrToOptionalInt64(q.EndTime),
TimeUnit: tu,
TimeRangeInNanos: protoconvert.DurationPtrToOptionalInt64(q.TimeRange),
TimeGranularityInNanos: (time.Duration)(*q.TimeGranularity).Nanoseconds(),
Filters: filterLists,
}, nil
}
// UnparsedQuery represents an unparsed document query useful for serializing/deserializing in JSON.
type UnparsedQuery struct {
// Namespace the query will be executed against.
// NB: This does not allow cross-namespace searches, but fine for now.
Namespace string `json:"namespace"`
// Time range portion of the query.
StartTime *int64 `json:"start_time"`
EndTime *int64 `json:"end_time"`
TimeUnit *xtime.Unit `json:"time_unit"`
TimeRange *xtime.Duration `json:"time_range"`
TimeGranularity *xtime.Duration `json:"time_granularity"`
// Filters.
Filters RawFilterLists `json:"filters"`
// A list of fields to group the results by.
GroupBy []string `json:"group_by"`
// A list of calculations to perform within each group.
// If no groups are specified, the calculations are performed against
// the entire group.
Calculations RawCalculations `json:"calculations"`
// A list of criteria to order the results by. Each criteria must appear
// either in the group by list or in the calculations list.
OrderBy RawOrderBys `json:"order_by"`
// Maximum number of results returned.
Limit *int `json:"limit"`
}
// RawCalculations is a list of raw calculations.
type RawCalculations []RawCalculation
// ToProto converts a list of raw calculation clauses to a list of calculation protobuf messages.
func (calcs RawCalculations) ToProto() ([]servicepb.Calculation, error) {
if len(calcs) == 0 {
return nil, nil
}
res := make([]servicepb.Calculation, 0, len(calcs))
for _, calc := range calcs {
pbCalculation, err := calc.ToProto()
if err != nil {
return nil, err
}
res = append(res, pbCalculation)
}
return res, nil
}
// RawCalculation represents a raw calculation object.
type RawCalculation struct {
Field *string `json:"field"`
Op calculation.Op `json:"op"`
}
// ToProto converts a raw calculation to a calculation protobuf message.
func (calc RawCalculation) ToProto() (servicepb.Calculation, error) {
pbOp, err := calc.Op.ToProto()
if err != nil {
return servicepb.Calculation{}, err
}
return servicepb.Calculation{
Field: protoconvert.StringPtrToOptionalString(calc.Field),
Op: pbOp,
}, nil
}
// RawOrderBys is a list of raw order by clauses.
type RawOrderBys []RawOrderBy
// ToProto converts a list of raw order by clauses to a list of order by protobuf messages.
func (obs RawOrderBys) ToProto() ([]servicepb.OrderBy, error) {
if len(obs) == 0 {
return nil, nil
}
res := make([]servicepb.OrderBy, 0, len(obs))
for _, ob := range obs {
pbOrderBy, err := ob.ToProto()
if err != nil {
return nil, err
}
res = append(res, pbOrderBy)
}
return res, nil
}
// RawOrderBy represents a list of criteria for ordering results.
type RawOrderBy struct {
Field *string `json:"field"`
Op *calculation.Op `json:"op"`
Order *SortOrder `json:"order"`
}
// ToProto converts an order by clause to an order by protobuf message.
func (ob RawOrderBy) ToProto() (servicepb.OrderBy, error) {
pbOp, err := ob.Op.ToOptionalProto()
if err != nil {
return servicepb.OrderBy{}, err
}
pbOrder, err := ob.Order.ToProto()
if err != nil {
return servicepb.OrderBy{}, err
}
return servicepb.OrderBy{
Field: protoconvert.StringPtrToOptionalString(ob.Field),
Op: pbOp,
Order: pbOrder,
}, nil
}
// ParseOptions provide a set of options for parsing a raw query.
type ParseOptions struct {
FieldPathSeparator byte
FieldHashFn hash.StringArrayHashFn
TimestampFieldPath []string
RawDocSourceFieldPath []string
}
// Parse parses the raw query, returning any errors encountered.
func (q *UnparsedQuery) Parse(opts ParseOptions) (ParsedQuery, error) {
sq := ParsedQuery{opts: opts}
ns, err := q.parseNamespace()
if err != nil {
return sq, err
}
sq.Namespace = ns
startNanos, endNanos, granularity, err := q.parseTime()
if err != nil {
return sq, err
}
sq.StartTimeNanos = startNanos
sq.EndTimeNanos = endNanos
sq.TimeGranularity = granularity
filters, err := q.parseFilters(opts)
if err != nil {
return sq, err
}
sq.Filters = filters
groupBy, err := q.parseGroupBy(opts)
if err != nil {
return sq, err
}
sq.GroupBy = groupBy
calculations, err := q.parseCalculations(opts)
if err != nil {
return sq, err
}
sq.Calculations = calculations
orderBy, err := q.parseOrderByList(sq.GroupBy, sq.Calculations, opts)
if err != nil {
return sq, err
}
sq.OrderBy = orderBy
limit, err := q.parseLimit()
if err != nil {
return sq, err
}
sq.Limit = limit
err = sq.computeDerived()
return sq, err
}
func (q *UnparsedQuery) parseNamespace() (string, error) {
if err := q.validateNamespace(); err != nil {
return "", err
}
return q.Namespace, nil
}
func (q *UnparsedQuery) validateNamespace() error {
if len(q.Namespace) == 0 {
return errNoNamespaceInQuery
}
return nil
}
func (q *UnparsedQuery) parseTime() (
startNanos, endNanos int64,
granularity *time.Duration,
err error,
) {
if err := q.validateTime(); err != nil {
return 0, 0, nil, err
}
timeUnit := defaultTimeUnit
if q.TimeUnit != nil {
timeUnit = *q.TimeUnit
}
unitDurationNanos := int64(timeUnit.MustValue())
if q.TimeRange == nil {
startNanos = *q.StartTime * unitDurationNanos
endNanos = *q.EndTime * unitDurationNanos
} else if q.StartTime != nil {
startNanos = *q.StartTime * unitDurationNanos
endNanos = startNanos + time.Duration(*q.TimeRange).Nanoseconds()
} else {
if q.EndTime != nil {
endNanos = *q.EndTime * unitDurationNanos
} else {
endNanos = time.Now().UnixNano()
}
startNanos = endNanos - time.Duration(*q.TimeRange).Nanoseconds()
}
if q.TimeGranularity == nil {
return startNanos, endNanos, nil, nil
}
// Further validation on query granularity.
var (
timeGranularity = time.Duration(*q.TimeGranularity)
rangeInNanos = endNanos - startNanos
maxGranularityAllowed = rangeInNanos / maxGranularityRangeScaleFactor
minGranularityAllowed = rangeInNanos / minGranularityRangeScaleFactor
)
if timeGranularity.Nanoseconds() > maxGranularityAllowed {
return 0, 0, nil, fmt.Errorf("query granularity %v is above maximum allowed %v", timeGranularity, time.Duration(maxGranularityAllowed))
}
if timeGranularity.Nanoseconds() < minGranularityAllowed {
return 0, 0, nil, fmt.Errorf("query granularity %v is below minimum allowed %v", timeGranularity, time.Duration(minGranularityAllowed))
}
return startNanos, endNanos, &timeGranularity, nil
}
func (q *UnparsedQuery) validateTime() error {
if q.StartTime != nil && *q.StartTime < 0 {
return fmt.Errorf("invalid query start time: %d", *q.StartTime)
}
if q.EndTime != nil && *q.EndTime < 0 {
return fmt.Errorf("invalid query end time: %d", *q.EndTime)
}
if q.TimeRange == nil && (q.StartTime == nil || q.EndTime == nil) {
return errStartAndEndRequiredWithNoRange
}
if q.TimeRange != nil && *q.TimeRange <= 0 {
return fmt.Errorf("invalid query time range: %v", q.TimeRange.String())
}
if q.TimeRange != nil && q.StartTime != nil && q.EndTime != nil {
return fmt.Errorf("query start time %d, end time %d, and time range %v are specified but only two should be included", *q.StartTime, *q.EndTime, *q.TimeRange)
}
if q.TimeGranularity == nil {
return nil
}
if *q.TimeGranularity <= 0 {
return fmt.Errorf("invalid query time granularity: %v", q.TimeGranularity.String())
}
return nil
}
func (q *UnparsedQuery) parseFilters(opts ParseOptions) ([]FilterList, error) {
if err := q.validateFilters(); err != nil {
return nil, err
}
flArray := make([]FilterList, 0, len(q.Filters))
for _, rfl := range q.Filters {
fts := make([]Filter, 0, len(rfl.Filters))
for _, rf := range rfl.Filters {
var f Filter
f.FieldPath = parseField(rf.Field, opts.FieldPathSeparator)
f.Op = rf.Op
if rf.Value != nil {
switch value := rf.Value.(type) {
case bool:
f.Value = &field.ValueUnion{Type: field.BoolType, BoolVal: value}
case float64:
if intval, ok := convert.TryAsInt(value); ok {
f.Value = &field.ValueUnion{Type: field.IntType, IntVal: intval}
} else {
f.Value = &field.ValueUnion{Type: field.DoubleType, DoubleVal: value}
}
case []byte:
f.Value = &field.ValueUnion{
Type: field.BytesType,
BytesVal: bytes.NewImmutableBytes(value),
}
case string:
f.Value = &field.ValueUnion{
Type: field.BytesType,
BytesVal: bytes.NewImmutableBytes(safe.ToBytes(value)),
}
default:
return nil, fmt.Errorf("unknown value type %T", rf.Value)
}
}
fts = append(fts, f)
}
fc := defaultFilterCombinator
if rfl.FilterCombinator != nil {
fc = *rfl.FilterCombinator
}
fl := FilterList{Filters: fts, FilterCombinator: fc}
flArray = append(flArray, fl)
}
return flArray, nil
}
func (q *UnparsedQuery) validateFilters() error {
for _, f := range q.Filters {
if err := q.validateFilterList(f.Filters); err != nil {
return err
}
}
return nil
}
func (q *UnparsedQuery) validateFilterList(filters []RawFilter) error {
for _, f := range filters {
if len(f.Field) == 0 {
return errNoFieldInFilter
}
switch f.Op {
case filter.Exists, filter.DoesNotExist, filter.IsNull, filter.IsNotNull:
if f.Value != nil {
return fmt.Errorf("non-empty filter value %v for op %s", f.Value, f.Op.String())
}
default:
if f.Value == nil {
return fmt.Errorf("empty filter value for op %s", f.Op.String())
}
}
}
return nil
}
func (q *UnparsedQuery) parseGroupBy(opts ParseOptions) ([][]string, error) {
if len(q.GroupBy) == 0 {
return nil, nil
}
if err := q.validateGroupBy(); err != nil {
return nil, err
}
groupByFieldPaths := make([][]string, 0, len(q.GroupBy))
for _, gb := range q.GroupBy {
fieldPaths := parseField(gb, opts.FieldPathSeparator)
groupByFieldPaths = append(groupByFieldPaths, fieldPaths)
}
return groupByFieldPaths, nil
}
func (q *UnparsedQuery) validateGroupBy() error {
if q.TimeGranularity != nil {
return errTimeGranularityWithGroupBy
}
return nil
}
func (q *UnparsedQuery) parseCalculations(opts ParseOptions) ([]Calculation, error) {
if len(q.Calculations) == 0 {
return nil, nil
}
if err := q.validateCalculations(); err != nil {
return nil, err
}
calculations := make([]Calculation, 0, len(q.Calculations))
for _, rawCalc := range q.Calculations {
var calc Calculation
if rawCalc.Field != nil {
calc.FieldPath = parseField(*rawCalc.Field, opts.FieldPathSeparator)
}
calc.Op = rawCalc.Op
calculations = append(calculations, calc)
}
return calculations, nil
}
func (q *UnparsedQuery) validateCalculations() error {
if q.TimeGranularity != nil {
return errTimeGranularityWithCalculations
}
if len(q.GroupBy) == 0 {
return errCalculationsWithNoGroups
}
// If the calculation operation is count, the field should be omitted,
// in which case the number of events containing the corresponding group key
// is returned. All other operations require the field be specified.
for _, calc := range q.Calculations {
if calc.Field != nil && !calc.Op.RequiresField() {
return fmt.Errorf("field %v cannot be specified for calculation op %v that does not require a field", *calc.Field, calc.Op)
}
if calc.Field == nil && calc.Op.RequiresField() {
return fmt.Errorf("no field specified for calculation op %v", calc.Op)
}
}
return nil
}
func (q *UnparsedQuery) parseOrderByList(
groupBy [][]string,
calculations []Calculation,
opts ParseOptions,
) ([]OrderBy, error) {
if len(q.OrderBy) == 0 {
return nil, nil
}
if q.TimeGranularity != nil {
return nil, errTimeGranularityWithOrderBy
}
obArray := make([]OrderBy, 0, len(q.OrderBy))
for _, rob := range q.OrderBy {
ob, err := q.parseOrderBy(rob, groupBy, calculations, opts)
if err != nil {
return nil, err
}
obArray = append(obArray, ob)
}
return obArray, nil
}
func (q *UnparsedQuery) parseOrderBy(
rob RawOrderBy,
groupBy [][]string,
calculations []Calculation,
opts ParseOptions,
) (OrderBy, error) {
var ob OrderBy
ob.SortOrder = defaultOrderBySortOrder
if rob.Order != nil {
ob.SortOrder = *rob.Order
}
if len(q.GroupBy) == 0 {
// This is a raw document query.
if rob.Field == nil {
return ob, errNoFieldInOrderByForRawQuery
}
ob.FieldType = RawField
ob.FieldPath = parseField(*rob.Field, opts.FieldPathSeparator)
return ob, nil
}
// Otherwise this is a grouped query.
if rob.Field == nil || rob.Op != nil {
if rob.Field == nil && rob.Op == nil {
return ob, errNoFieldOrOpInOrderByForGroupedQuery
}
if rob.Field != nil && !rob.Op.RequiresField() {
return ob, fmt.Errorf("field specified %s for order by op %v", *rob.Field, *rob.Op)
}
if rob.Field == nil && rob.Op.RequiresField() {
return ob, fmt.Errorf("no field specified for order by op %v", *rob.Op)
}
for idx, calc := range q.Calculations {
if calc.Field == nil && rob.Field != nil {
continue
}
if calc.Field != nil && rob.Field == nil {
continue
}
if calc.Field != nil && rob.Field != nil && *calc.Field != *rob.Field {
continue
}
if calc.Op == *rob.Op {
ob.FieldType = CalculationField
ob.FieldIndex = idx
ob.FieldPath = calculations[idx].FieldPath
return ob, nil
}
}
return ob, fmt.Errorf("invalid order by clause: %v", rob)
}
// Now try to find the field in the group by list.
for idx, f := range q.GroupBy {
if *rob.Field == f {
ob.FieldType = GroupByField
ob.FieldIndex = idx
ob.FieldPath = groupBy[idx]
return ob, nil
}
}
return ob, fmt.Errorf("invalid order by clause: %v", rob)
}
// TODO(xichen): Protect against overly aggressive limits.
func (q *UnparsedQuery) parseLimit() (int, error) {
if err := q.validateLimit(); err != nil {
return 0, err
}
if q.Limit != nil && *q.Limit >= 0 {
return *q.Limit, nil
}
if len(q.GroupBy) == 0 {
return defaultRawQuerySizeLimit, nil
}
return defaultGroupedQuerySizeLimit, nil
}
func (q UnparsedQuery) validateLimit() error {
if q.Limit != nil && *q.Limit <= 0 {
return fmt.Errorf("invalid query result limit: %d", *q.Limit)
}
return nil
}
// parseField parses a concatenated field name (e.g., foo.bar.baz)
// into an array of field path segments (e.g., []string{"foo", "bar", "baz"})
// given the field path separator.
func parseField(fieldName string, separator byte) []string {
return strings.Split(fieldName, string(separator))
}