defend against select *,value
parent
62df7152c6
commit
82ae461378
42
server.go
42
server.go
|
@ -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
|
// If this is a wildcard statement, expand this to use the fields
|
||||||
// This is temporary until we move other parts of the system further
|
// This is temporary until we move other parts of the system further
|
||||||
if len(stmt.Fields) == 1 {
|
isWildcard := false
|
||||||
if _, ok := stmt.Fields[0].Expr.(*influxql.Wildcard); ok {
|
for _, f := range stmt.Fields {
|
||||||
if measurement, ok := stmt.Source.(*influxql.Measurement); ok {
|
if _, ok := f.Expr.(*influxql.Wildcard); ok {
|
||||||
segments, err := influxql.SplitIdent(measurement.Name)
|
isWildcard = true
|
||||||
if err != nil {
|
break
|
||||||
return nil, fmt.Errorf("unable to parse measurement %s", measurement.Name)
|
}
|
||||||
}
|
}
|
||||||
db, m := segments[0], segments[2]
|
|
||||||
if s.databases[db].measurements[m] == nil {
|
if len(stmt.Fields) != 1 && isWildcard {
|
||||||
return nil, fmt.Errorf("measurement %s does not exist.", measurement.Name)
|
return nil, fmt.Errorf("unsupported query: %s. currently only single wildcard is supported.", stmt.String())
|
||||||
}
|
}
|
||||||
var fields influxql.Fields
|
|
||||||
for _, f := range s.databases[db].measurements[m].Fields {
|
if isWildcard {
|
||||||
fields = append(fields, &influxql.Field{Expr: &influxql.VarRef{Val: f.Name}})
|
if measurement, ok := stmt.Source.(*influxql.Measurement); ok {
|
||||||
}
|
segments, err := influxql.SplitIdent(measurement.Name)
|
||||||
stmt.Fields = fields
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue