Skip to content

Commit

Permalink
Simple change so "SHOW TAG VALUES" is as expected
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
otoolep committed Feb 23, 2015
1 parent 6412ed8 commit 9523026
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 5 additions & 3 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,15 +1367,16 @@ 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 {
tagKeys = append(tagKeys, k)
}
}

// 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.
Expand All @@ -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{}
Expand Down
14 changes: 7 additions & 7 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2036,15 +2036,15 @@ 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"}),
},
},
{
Name: "gpu",
Columns: []string{"tagValue"},
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server02"}),
str2iface([]string{"server03"}),
Expand All @@ -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"}),
Expand All @@ -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"}),
},
Expand All @@ -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"}),
},
Expand All @@ -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"}),
},
Expand All @@ -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"}),
Expand Down
7 changes: 5 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9523026

Please sign in to comment.