fix #2644: make SHOW TAG KEYS FROM /<regex>/ work
parent
0f0a50b2a6
commit
fe99177fb3
|
@ -1358,6 +1358,7 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
},
|
||||
|
||||
{
|
||||
name: "show tag keys",
|
||||
reset: true,
|
||||
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [
|
||||
{"measurement": "cpu", "tags": {"host": "server01"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
|
@ -1365,18 +1366,27 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
|
|||
{"measurement": "cpu", "tags": {"host": "server01", "region": "useast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"measurement": "cpu", "tags": {"host": "server02", "region": "useast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"measurement": "gpu", "tags": {"host": "server02", "region": "useast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"measurement": "gpu", "tags": {"host": "server03", "region": "caeast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}}
|
||||
{"measurement": "gpu", "tags": {"host": "server03", "region": "caeast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}},
|
||||
{"measurement": "disk", "tags": {"host": "server03", "region": "caeast"},"time": "2009-11-10T23:00:00Z","fields": {"value": 100}}
|
||||
]}`,
|
||||
query: "SHOW TAG KEYS",
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["tagKey"],"values":[["host"],["region"]]},{"name":"gpu","columns":["tagKey"],"values":[["host"],["region"]]}]}]}`,
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["tagKey"],"values":[["host"],["region"]]},{"name":"disk","columns":["tagKey"],"values":[["host"],["region"]]},{"name":"gpu","columns":["tagKey"],"values":[["host"],["region"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "show tag keys from",
|
||||
query: "SHOW TAG KEYS FROM cpu",
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["tagKey"],"values":[["host"],["region"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "show tag keys from regex",
|
||||
query: "SHOW TAG KEYS FROM /[cg]pu/",
|
||||
queryDb: "%DB%",
|
||||
expected: `{"results":[{"series":[{"name":"cpu","columns":["tagKey"],"values":[["host"],["region"]]},{"name":"gpu","columns":["tagKey"],"values":[["host"],["region"]]}]}]}`,
|
||||
},
|
||||
{
|
||||
name: "show tag keys measurement not found",
|
||||
query: "SHOW TAG KEYS FROM bad",
|
||||
queryDb: "%DB%",
|
||||
expectPattern: `measurement not found: bad.*`,
|
||||
|
|
|
@ -1692,8 +1692,8 @@ func (s *ShowDiagnosticsStatement) RequiredPrivileges() ExecutionPrivileges {
|
|||
|
||||
// ShowTagKeysStatement represents a command for listing tag keys.
|
||||
type ShowTagKeysStatement struct {
|
||||
// Data source that fields are extracted from.
|
||||
Source Source
|
||||
// Data sources that fields are extracted from.
|
||||
Sources Sources
|
||||
|
||||
// An expression evaluated on data point.
|
||||
Condition Expr
|
||||
|
@ -1714,9 +1714,9 @@ func (s *ShowTagKeysStatement) String() string {
|
|||
var buf bytes.Buffer
|
||||
_, _ = buf.WriteString("SHOW TAG KEYS")
|
||||
|
||||
if s.Source != nil {
|
||||
if s.Sources != nil {
|
||||
_, _ = buf.WriteString(" FROM ")
|
||||
_, _ = buf.WriteString(s.Source.String())
|
||||
_, _ = buf.WriteString(s.Sources.String())
|
||||
}
|
||||
if s.Condition != nil {
|
||||
_, _ = buf.WriteString(" WHERE ")
|
||||
|
@ -2350,7 +2350,7 @@ func Walk(v Visitor, node Node) {
|
|||
Walk(v, n.Condition)
|
||||
|
||||
case *ShowTagKeysStatement:
|
||||
Walk(v, n.Source)
|
||||
Walk(v, n.Sources)
|
||||
Walk(v, n.Condition)
|
||||
Walk(v, n.SortFields)
|
||||
|
||||
|
|
|
@ -849,7 +849,7 @@ func (p *Parser) parseShowTagKeysStatement() (*ShowTagKeysStatement, error) {
|
|||
|
||||
// Parse optional source.
|
||||
if tok, _, _ := p.scanIgnoreWhitespace(); tok == FROM {
|
||||
if stmt.Source, err = p.parseSource(); err != nil {
|
||||
if stmt.Sources, err = p.parseSources(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -2772,8 +2772,14 @@ func (s *Server) executeShowTagKeysStatement(stmt *influxql.ShowTagKeysStatement
|
|||
return &Result{Err: ErrDatabaseNotFound(database)}
|
||||
}
|
||||
|
||||
// Expand regex expressions in the FROM clause.
|
||||
sources, err := s.expandSources(stmt.Sources)
|
||||
if err != nil {
|
||||
return &Result{Err: err}
|
||||
}
|
||||
|
||||
// Get the list of measurements we're interested in.
|
||||
measurements, err := measurementsFromSourceOrDB(stmt.Source, db)
|
||||
measurements, err := measurementsFromSourcesOrDB(db, sources...)
|
||||
if err != nil {
|
||||
return &Result{Err: err}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue