From 952302611bf9cbcec6a8cbb83b86eacbd878cd0e Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Sun, 22 Feb 2015 22:25:27 -0800 Subject: [PATCH] Simple change so "SHOW TAG VALUES" is as expected This change only covers the case where a values for a single tag key is requested, since there is a question whether anything else should be supported. --- database.go | 8 +++++--- httpd/handler_test.go | 14 +++++++------- server.go | 7 +++++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/database.go b/database.go index 97cfa9a83af..04e7868d964 100644 --- a/database.go +++ b/database.go @@ -1367,7 +1367,7 @@ func (m *Measurement) tagKeys() []string { return keys } -func (m *Measurement) tagValuesByKeyAndSeriesID(tagKeys []string, ids seriesIDs) stringSet { +func (m *Measurement) tagValuesByKeyAndSeriesID(tagKeys []string, ids seriesIDs) (stringSet, stringSet) { // If no tag keys were passed, get all tag keys for the measurement. if len(tagKeys) == 0 { for k := range m.seriesByTagKeyValue { @@ -1375,7 +1375,8 @@ func (m *Measurement) tagValuesByKeyAndSeriesID(tagKeys []string, ids seriesIDs) } } - // Make a set to hold all tag values found. + // Make a set to hold all tag keys and values found. + tKeys := newStringSet() tagValues := newStringSet() // Iterate all series to collect tag values. @@ -1389,12 +1390,13 @@ func (m *Measurement) tagValuesByKeyAndSeriesID(tagKeys []string, ids seriesIDs) // from this series, if they exist. for _, tagKey := range tagKeys { if tagVal, ok := s.Tags[tagKey]; ok { + tKeys.add(tagKey) tagValues.add(tagVal) } } } - return tagValues + return tKeys, tagValues } type stringSet map[string]struct{} diff --git a/httpd/handler_test.go b/httpd/handler_test.go index 91f5468e58e..b73efc1718f 100644 --- a/httpd/handler_test.go +++ b/httpd/handler_test.go @@ -2036,7 +2036,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "cpu", - Columns: []string{"tagValue"}, + Columns: []string{"host"}, Values: [][]interface{}{ str2iface([]string{"server01"}), str2iface([]string{"server02"}), @@ -2044,7 +2044,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { }, { Name: "gpu", - Columns: []string{"tagValue"}, + Columns: []string{"host"}, Values: [][]interface{}{ str2iface([]string{"server02"}), str2iface([]string{"server03"}), @@ -2064,7 +2064,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "cpu", - Columns: []string{"tagValue"}, + Columns: []string{"host"}, Values: [][]interface{}{ str2iface([]string{"server01"}), str2iface([]string{"server02"}), @@ -2084,7 +2084,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "cpu", - Columns: []string{"tagValue"}, + Columns: []string{"host"}, Values: [][]interface{}{ str2iface([]string{"server01"}), }, @@ -2103,7 +2103,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "gpu", - Columns: []string{"tagValue"}, + Columns: []string{"host"}, Values: [][]interface{}{ str2iface([]string{"server03"}), }, @@ -2122,7 +2122,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "gpu", - Columns: []string{"tagValue"}, + Columns: []string{"region"}, Values: [][]interface{}{ str2iface([]string{"caeast"}), }, @@ -2141,7 +2141,7 @@ func TestHandler_serveShowTagValues(t *testing.T) { Series: []*influxql.Row{ { Name: "cpu", - Columns: []string{"tagValue"}, + Columns: []string{"host", "region"}, Values: [][]interface{}{ str2iface([]string{"server01"}), str2iface([]string{"uswest"}), diff --git a/server.go b/server.go index a0e48154312..d6a176224c3 100644 --- a/server.go +++ b/server.go @@ -2147,11 +2147,14 @@ func (s *Server) executeShowTagValuesStatement(stmt *influxql.ShowTagValuesState ids = m.seriesIDs } - tagValues := m.tagValuesByKeyAndSeriesID(stmt.TagKeys, ids) + tagKeys, tagValues := m.tagValuesByKeyAndSeriesID(stmt.TagKeys, ids) + + keys := tagKeys.list() + sort.Strings(keys) r := &influxql.Row{ Name: m.Name, - Columns: []string{"tagValue"}, + Columns: keys, } vals := tagValues.list()