Skip to content

Commit

Permalink
custom errors for distinct vs. count distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
corylanou committed May 20, 2015
1 parent 68f4b4c commit 5e9f706
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/influxd/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,13 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
name: "count distinct select tag",
query: `SELECT count(distinct host) FROM cpu`,
queryDb: "%DB%",
expected: `{"results":[{"error":"host isn't a field on measurement cpu"}]}`,
expected: `{"results":[{"error":"host isn't a field on measurement cpu; count(distinct) on tags isn't yet supported"}]}`,
},
{
name: "count distinct as call select tag",
query: `SELECT count(distinct(host)) FROM cpu`,
queryDb: "%DB%",
expected: `{"results":[{"error":"host isn't a field on measurement cpu"}]}`,
expected: `{"results":[{"error":"host isn't a field on measurement cpu; count(distinct) on tags isn't yet supported"}]}`,
},
{
reset: true,
Expand Down
12 changes: 10 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ func (l *LocalMapper) Begin(c *influxql.Call, startingTime int64, chunkSize int)
l.chunkSize = chunkSize
l.tmin = startingTime

var isCountDistinct bool

// determine if this is a raw data query with a single field, multiple fields, or an aggregate
var fieldName string
if c == nil { // its a raw data query
Expand All @@ -400,21 +402,27 @@ func (l *LocalMapper) Begin(c *influxql.Call, startingTime int64, chunkSize int)
if c.Name != "count" {
return fmt.Errorf("aggregate call didn't contain a field %s", c.String())
}
isCountDistinct = true
fieldName = lit.Val
default:
return fmt.Errorf("aggregate call didn't contain a field %s", c.String())
}

isCountDistinct = isCountDistinct || (c.Name == "count" && nested.Name == "distinct")
}

// set up the field info if a specific field was set for this mapper
if fieldName != "" {
f := l.decoder.FieldByName(fieldName)
if f == nil {
if c.Name == "distinct" {
switch {
case c.Name == "distinct":
return fmt.Errorf("%s isn't a field on measurement %s; to query the unique values for a tag use SHOW TAG VALUES FROM %s WITH KEY = %q", fieldName, l.job.MeasurementName, l.job.MeasurementName, fieldName)
case isCountDistinct:
return fmt.Errorf("%s isn't a field on measurement %s; count(distinct) on tags isn't yet supported", fieldName, l.job.MeasurementName)
default:
return fmt.Errorf("%s isn't a field on measurement %s", fieldName, l.job.MeasurementName)
}
return fmt.Errorf("%s isn't a field on measurement %s", fieldName, l.job.MeasurementName)
}
l.fieldID = f.ID
l.fieldName = f.Name
Expand Down

0 comments on commit 5e9f706

Please sign in to comment.