Skip to content

Commit 310c42e

Browse files
authored
Merge pull request influxdata#8834 from influxdata/js-1.3-marshaling-backport
Fix group by marshaling in the IteratorOptions
2 parents 820470d + 71f1223 commit 310c42e

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

influxql/iterator.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ type IteratorOptions struct {
695695
// and close as soon as possible.
696696
InterruptCh <-chan struct{}
697697

698-
// Authorizer can limit acccess to data
698+
// Authorizer can limit access to data
699699
Authorizer Authorizer
700700
}
701701

@@ -1025,15 +1025,17 @@ func encodeIteratorOptions(opt *IteratorOptions) *internal.IteratorOptions {
10251025
}
10261026

10271027
// Convert and encode aux fields as variable references.
1028-
pb.Fields = make([]*internal.VarRef, len(opt.Aux))
1029-
pb.Aux = make([]string, len(opt.Aux))
1030-
for i, ref := range opt.Aux {
1031-
pb.Fields[i] = encodeVarRef(ref)
1032-
pb.Aux[i] = ref.Val
1028+
if opt.Aux != nil {
1029+
pb.Fields = make([]*internal.VarRef, len(opt.Aux))
1030+
pb.Aux = make([]string, len(opt.Aux))
1031+
for i, ref := range opt.Aux {
1032+
pb.Fields[i] = encodeVarRef(ref)
1033+
pb.Aux[i] = ref.Val
1034+
}
10331035
}
10341036

10351037
// Encode group by dimensions from a map.
1036-
if pb.GroupBy != nil {
1038+
if opt.GroupBy != nil {
10371039
dimensions := make([]string, 0, len(opt.GroupBy))
10381040
for dim := range opt.GroupBy {
10391041
dimensions = append(dimensions, dim)
@@ -1069,7 +1071,6 @@ func decodeIteratorOptions(pb *internal.IteratorOptions) (*IteratorOptions, erro
10691071
Interval: decodeInterval(pb.GetInterval()),
10701072
Dimensions: pb.GetDimensions(),
10711073
Fill: FillOption(pb.GetFill()),
1072-
FillValue: pb.GetFillValue(),
10731074
StartTime: pb.GetStartTime(),
10741075
EndTime: pb.GetEndTime(),
10751076
Ascending: pb.GetAscending(),
@@ -1105,9 +1106,9 @@ func decodeIteratorOptions(pb *internal.IteratorOptions) (*IteratorOptions, erro
11051106
for i, ref := range fields {
11061107
opt.Aux[i] = decodeVarRef(ref)
11071108
}
1108-
} else {
1109-
opt.Aux = make([]VarRef, len(pb.GetAux()))
1110-
for i, name := range pb.GetAux() {
1109+
} else if aux := pb.GetAux(); aux != nil {
1110+
opt.Aux = make([]VarRef, len(aux))
1111+
for i, name := range aux {
11111112
opt.Aux[i] = VarRef{Val: name}
11121113
}
11131114
}
@@ -1134,6 +1135,11 @@ func decodeIteratorOptions(pb *internal.IteratorOptions) (*IteratorOptions, erro
11341135
opt.GroupBy = dimensions
11351136
}
11361137

1138+
// Set the fill value, if set.
1139+
if pb.FillValue != nil {
1140+
opt.FillValue = pb.GetFillValue()
1141+
}
1142+
11371143
// Set condition, if set.
11381144
if pb.Condition != nil {
11391145
expr, err := ParseExpr(pb.GetCondition())

influxql/iterator_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,17 +1303,22 @@ func TestIteratorOptions_MarshalBinary(t *testing.T) {
13031303
Offset: 20 * time.Minute,
13041304
},
13051305
Dimensions: []string{"region", "host"},
1306-
Fill: influxql.NumberFill,
1307-
FillValue: float64(100),
1308-
Condition: MustParseExpr(`foo = 'bar'`),
1309-
StartTime: 1000,
1310-
EndTime: 2000,
1311-
Ascending: true,
1312-
Limit: 100,
1313-
Offset: 200,
1314-
SLimit: 300,
1315-
SOffset: 400,
1316-
Dedupe: true,
1306+
GroupBy: map[string]struct{}{
1307+
"region": {},
1308+
"host": {},
1309+
"cluster": {},
1310+
},
1311+
Fill: influxql.NumberFill,
1312+
FillValue: float64(100),
1313+
Condition: MustParseExpr(`foo = 'bar'`),
1314+
StartTime: 1000,
1315+
EndTime: 2000,
1316+
Ascending: true,
1317+
Limit: 100,
1318+
Offset: 200,
1319+
SLimit: 300,
1320+
SOffset: 400,
1321+
Dedupe: true,
13171322
}
13181323

13191324
// Marshal to binary.

0 commit comments

Comments
 (0)