defend against select *,value

pull/1540/head
Cory LaNou 2015-02-09 17:57:03 -07:00
parent 62df7152c6
commit 82ae461378
1 changed files with 26 additions and 16 deletions

View File

@ -1850,23 +1850,33 @@ func (s *Server) planSelectStatement(stmt *influxql.SelectStatement, database st
// If this is a wildcard statement, expand this to use the fields
// This is temporary until we move other parts of the system further
if len(stmt.Fields) == 1 {
if _, ok := stmt.Fields[0].Expr.(*influxql.Wildcard); ok {
if measurement, ok := stmt.Source.(*influxql.Measurement); ok {
segments, err := influxql.SplitIdent(measurement.Name)
if err != nil {
return nil, fmt.Errorf("unable to parse measurement %s", measurement.Name)
}
db, m := segments[0], segments[2]
if s.databases[db].measurements[m] == nil {
return nil, fmt.Errorf("measurement %s does not exist.", measurement.Name)
}
var fields influxql.Fields
for _, f := range s.databases[db].measurements[m].Fields {
fields = append(fields, &influxql.Field{Expr: &influxql.VarRef{Val: f.Name}})
}
stmt.Fields = fields
isWildcard := false
for _, f := range stmt.Fields {
if _, ok := f.Expr.(*influxql.Wildcard); ok {
isWildcard = true
break
}
}
if len(stmt.Fields) != 1 && isWildcard {
return nil, fmt.Errorf("unsupported query: %s. currently only single wildcard is supported.", stmt.String())
}
if isWildcard {
if measurement, ok := stmt.Source.(*influxql.Measurement); ok {
segments, err := influxql.SplitIdent(measurement.Name)
if err != nil {
return nil, fmt.Errorf("unable to parse measurement %s", measurement.Name)
}
db, m := segments[0], segments[2]
if s.databases[db].measurements[m] == nil {
return nil, fmt.Errorf("measurement %s does not exist.", measurement.Name)
}
var fields influxql.Fields
for _, f := range s.databases[db].measurements[m].Fields {
fields = append(fields, &influxql.Field{Expr: &influxql.VarRef{Val: f.Name}})
}
stmt.Fields = fields
}
}