fix(storage/reads): update sortKey sorting method to use null byte as delimeter

pull/17634/head
Faith Chikwekwe 2020-04-06 14:42:43 -07:00
parent 84386b884a
commit edc1a7413d
2 changed files with 45 additions and 1 deletions

View File

@ -247,7 +247,8 @@ func (g *groupResultSet) groupBySort() (int, error) {
nr.SortKey = make([]byte, 0, l)
for _, v := range vals {
nr.SortKey = append(nr.SortKey, v...)
nr.SortKey = append(nr.SortKey, ',')
// separate sort key values with ascii null character
nr.SortKey = append(nr.SortKey, '\000')
}
seriesRows = append(seriesRows, &nr)

View File

@ -83,6 +83,49 @@ group:
tag key : _m,tag0,tag1
partition key: 00011,1
series: _m=cpu,tag0=00011,tag1=1
`,
},
{
name: "group by tags key sort collision",
cur: &sliceSeriesCursor{
rows: newSeriesRows(
"cpu,tag0=a,tag1=b",
"cpu,tag0=a*,tag1=b",
"cpu,tag0=a*",
)},
group: datatypes.GroupBy,
keys: []string{"tag0", "tag1"},
exp: `group:
tag key : _m,tag0,tag1
partition key: a,b
series: _m=cpu,tag0=a,tag1=b
group:
tag key : _m,tag0,tag1
partition key: a*,b
series: _m=cpu,tag0=a*,tag1=b
group:
tag key : _m,tag0
partition key: a*,<nil>
series: _m=cpu,tag0=a*
`,
},
{
name: "group by tags missing tag",
cur: &sliceSeriesCursor{
rows: newSeriesRows(
"cpu,tag0=a,tag1=b",
"cpu,tag1=b",
)},
group: datatypes.GroupBy,
keys: []string{"tag0", "tag1"},
exp: `group:
tag key : _m,tag0,tag1
partition key: a,b
series: _m=cpu,tag0=a,tag1=b
group:
tag key : _m,tag1
partition key: <nil>,b
series: _m=cpu,tag1=b
`,
},
{