diff --git a/src/query/models/tags.go b/src/query/models/tags.go index a32348fe58..7f5faeca18 100644 --- a/src/query/models/tags.go +++ b/src/query/models/tags.go @@ -49,9 +49,17 @@ func EmptyTags() Tags { } // ID returns a byte slice representation of the tags, using the generation -// strategy from . +// strategy from the tag options. func (t Tags) ID() []byte { schemeType := t.Opts.IDSchemeType() + if len(t.Tags) == 0 { + if schemeType == TypeQuoted { + return []byte("{}") + } + + return []byte("") + } + switch schemeType { case TypeLegacy: return t.legacyID() diff --git a/src/query/models/tags_test.go b/src/query/models/tags_test.go index 56594f8008..024e224753 100644 --- a/src/query/models/tags_test.go +++ b/src/query/models/tags_test.go @@ -386,6 +386,24 @@ func buildTags(b *testing.B, count, length int, opts TagOptions, escape bool) Ta return NewTags(count, opts).AddTags(tags) } +func TestEmptyTags(t *testing.T) { + tests := []struct { + idType IDSchemeType + expected string + }{ + {TypeLegacy, ""}, + {TypePrependMeta, ""}, + {TypeGraphite, ""}, + {TypeQuoted, "{}"}, + } + + for _, tt := range tests { + tags := NewTags(0, NewTagOptions().SetIDSchemeType(tt.idType)) + id := tags.ID() + assert.Equal(t, []byte(tt.expected), id) + } +} + var tagBenchmarks = []struct { name string tagCount, tagLength int