Remove dimensions from field wildcards
When a wildcard is specified for the field but not the dimensions, the dimensions get added to the list of fields as part of `RewriteWildcards()`. But when a dimension was given with no wildcard, the dimension didn't get removed from the wildcard in the fields section. This teaches the rewriter to disclude dimensions explicitly included from being expanded as a field. Now this statement when a measurement has one tag named host and a field named value: SELECT * FROM cpu GROUP BY host Would expand to this: SELECT value FROM cpu GROUP BY host Instead of this: SELECT host, value FROM cpu GROUP BY host If you want the latter behavior, you can include it like this: SELECT host, * FROM cpu GROUP BY host Fixes #5770.pull/5798/head
parent
50753de032
commit
f7ef382596
|
@ -944,7 +944,7 @@ func (s *SelectStatement) RewriteWildcards(ic IteratorCreator) (*SelectStatement
|
|||
return s, nil
|
||||
}
|
||||
|
||||
// Retrieve a list of unqiue field and dimensions.
|
||||
// Retrieve a list of unique field and dimensions.
|
||||
fieldSet, dimensionSet, err := ic.FieldDimensions(s.Sources)
|
||||
if err != nil {
|
||||
return s, err
|
||||
|
@ -952,6 +952,16 @@ func (s *SelectStatement) RewriteWildcards(ic IteratorCreator) (*SelectStatement
|
|||
|
||||
// If there are no dimension wildcards then merge dimensions to fields.
|
||||
if !hasDimensionWildcard {
|
||||
// Remove the dimensions present in the group by so they don't get added as fields.
|
||||
for _, d := range s.Dimensions {
|
||||
switch expr := d.Expr.(type) {
|
||||
case *VarRef:
|
||||
if _, ok := dimensionSet[expr.Val]; ok {
|
||||
delete(dimensionSet, expr.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k := range dimensionSet {
|
||||
fieldSet[k] = struct{}{}
|
||||
}
|
||||
|
|
|
@ -356,16 +356,22 @@ func TestSelectStatement_RewriteWildcards(t *testing.T) {
|
|||
// Parser fundamentally prohibits multiple query sources
|
||||
|
||||
// Query wildcard with explicit
|
||||
// {
|
||||
// stmt: `SELECT *,value1 FROM cpu`,
|
||||
// rewrite: `SELECT value1, value2, value1 FROM cpu`,
|
||||
// },
|
||||
{
|
||||
stmt: `SELECT *,value1 FROM cpu`,
|
||||
rewrite: `SELECT host, region, value1, value2, value1 FROM cpu`,
|
||||
},
|
||||
|
||||
// Query multiple wildcards
|
||||
// {
|
||||
// stmt: `SELECT *,* FROM cpu`,
|
||||
// rewrite: `SELECT value1,value2,value1,value2 FROM cpu`,
|
||||
// },
|
||||
{
|
||||
stmt: `SELECT *,* FROM cpu`,
|
||||
rewrite: `SELECT host, region, value1, value2, host, region, value1, value2 FROM cpu`,
|
||||
},
|
||||
|
||||
// Query wildcards with group by
|
||||
{
|
||||
stmt: `SELECT * FROM cpu GROUP BY host`,
|
||||
rewrite: `SELECT region, value1, value2 FROM cpu GROUP BY host`,
|
||||
},
|
||||
|
||||
// No GROUP BY wildcards
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue