Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple change so "SHOW TAG VALUES" is as expected #1689

Merged
merged 1 commit into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1367,16 +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) map[string]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.
tagValues := newStringSet()
// Mapping between tag keys to all existing tag values.
tagValues := make(map[string]stringSet, 0)

// Iterate all series to collect tag values.
for _, id := range ids {
Expand All @@ -1389,7 +1389,10 @@ 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 {
tagValues.add(tagVal)
if _, ok = tagValues[tagKey]; !ok {
tagValues[tagKey] = newStringSet()
}
tagValues[tagKey].add(tagVal)
}
}
}
Expand Down
37 changes: 18 additions & 19 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2035,18 +2035,11 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "cpu",
Columns: []string{"tagValue"},
Name: "hostTagValues",
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server01"}),
str2iface([]string{"server02"}),
},
},
{
Name: "gpu",
Columns: []string{"tagValue"},
Values: [][]interface{}{
str2iface([]string{"server02"}),
str2iface([]string{"server03"}),
},
},
Expand All @@ -2063,8 +2056,8 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "cpu",
Columns: []string{"tagValue"},
Name: "hostTagValues",
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server01"}),
str2iface([]string{"server02"}),
Expand All @@ -2083,8 +2076,8 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "cpu",
Columns: []string{"tagValue"},
Name: "hostTagValues",
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server01"}),
},
Expand All @@ -2102,8 +2095,8 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "gpu",
Columns: []string{"tagValue"},
Name: "hostTagValues",
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server03"}),
},
Expand All @@ -2121,8 +2114,8 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "gpu",
Columns: []string{"tagValue"},
Name: "regionTagValues",
Columns: []string{"region"},
Values: [][]interface{}{
str2iface([]string{"caeast"}),
},
Expand All @@ -2140,10 +2133,16 @@ func TestHandler_serveShowTagValues(t *testing.T) {
{
Series: []*influxql.Row{
{
Name: "cpu",
Columns: []string{"tagValue"},
Name: "hostTagValues",
Columns: []string{"host"},
Values: [][]interface{}{
str2iface([]string{"server01"}),
},
},
{
Name: "regionTagValues",
Columns: []string{"region"},
Values: [][]interface{}{
str2iface([]string{"uswest"}),
},
},
Expand Down
22 changes: 16 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2126,9 +2126,10 @@ func (s *Server) executeShowTagValuesStatement(stmt *influxql.ShowTagValuesState

// Make result.
result := &Result{
Series: make(influxql.Rows, 0, len(measurements)),
Series: make(influxql.Rows, 0),
}

tagValues := make(map[string]stringSet)
for _, m := range measurements {
var ids seriesIDs

Expand All @@ -2148,14 +2149,22 @@ func (s *Server) executeShowTagValuesStatement(stmt *influxql.ShowTagValuesState
ids = m.seriesIDs
}

tagValues := m.tagValuesByKeyAndSeriesID(stmt.TagKeys, ids)
for k, v := range m.tagValuesByKeyAndSeriesID(stmt.TagKeys, ids) {
_, ok := tagValues[k]
if !ok {
tagValues[k] = v
}
tagValues[k] = tagValues[k].union(v)
}
}

for k, v := range tagValues {
r := &influxql.Row{
Name: m.Name,
Columns: []string{"tagValue"},
Name: k + "TagValues",
Columns: []string{k},
}

vals := tagValues.list()
vals := v.list()
sort.Strings(vals)

for _, val := range vals {
Expand All @@ -2166,6 +2175,7 @@ func (s *Server) executeShowTagValuesStatement(stmt *influxql.ShowTagValuesState
result.Series = append(result.Series, r)
}

sort.Sort(result.Series)
return result
}

Expand Down Expand Up @@ -2613,7 +2623,7 @@ func (s *Server) processor(client MessagingClient, done chan struct{}) {

// Result represents a resultset returned from a single statement.
type Result struct {
Series []*influxql.Row
Series influxql.Rows
Err error
}

Expand Down