Sort wildcard expresion field names for consistent output
parent
55c0e4434f
commit
932b6ddc81
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -654,6 +655,8 @@ func (s *SelectStatement) RewriteWildcards(fields Fields, dimensions Dimensions)
|
|||
for _, f := range s.Fields {
|
||||
switch f.Expr.(type) {
|
||||
case *Wildcard:
|
||||
// Sort wildcard fields for consistent output
|
||||
sort.Sort(fields)
|
||||
rwFields = append(rwFields, fields...)
|
||||
default:
|
||||
rwFields = append(rwFields, f)
|
||||
|
@ -1573,6 +1576,11 @@ func (f *Field) String() string {
|
|||
return fmt.Sprintf("%s AS %s", f.Expr.String(), f.Alias)
|
||||
}
|
||||
|
||||
// Sort Interface for Field
|
||||
func (f Fields) Len() int { return len(f) }
|
||||
func (f Fields) Less(i, j int) bool { return f[i].Name() < f[j].Name() }
|
||||
func (f Fields) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||
|
||||
// Dimensions represents a list of dimensions.
|
||||
type Dimensions []*Dimension
|
||||
|
||||
|
|
|
@ -1741,7 +1741,8 @@ func TestServer_ExecuteWildcardQuery(t *testing.T) {
|
|||
results := s.ExecuteQuery(MustParseQuery(`SELECT * FROM cpu`), "foo", nil)
|
||||
if res := results.Results[0]; res.Err != nil {
|
||||
t.Fatalf("unexpected error during SELECT *: %s", res.Err)
|
||||
} else if s := mustMarshalJSON(res); s != `{"series":[{"name":"cpu","columns":["time","value","val-x"],"values":[["2000-01-01T00:00:00Z",10,null],["2000-01-01T00:00:10Z",null,20],["2000-01-01T00:00:20Z",30,40]]}]}` {
|
||||
} else if s, e := mustMarshalJSON(res), `{"series":[{"name":"cpu","columns":["time","val-x","value"],"values":[["2000-01-01T00:00:00Z",null,10],["2000-01-01T00:00:10Z",20,null],["2000-01-01T00:00:20Z",40,30]]}]}`; s != e {
|
||||
t.Logf("expected %s\n", e)
|
||||
t.Fatalf("unexpected results during SELECT *: %s", s)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue