feat #3523: parse WITH in SHOW MEASUREMENTS
parent
e73c37088f
commit
a1b0f53108
|
@ -1953,6 +1953,9 @@ func (s *DropContinuousQueryStatement) RequiredPrivileges() ExecutionPrivileges
|
|||
|
||||
// ShowMeasurementsStatement represents a command for listing measurements.
|
||||
type ShowMeasurementsStatement struct {
|
||||
// Measurement name or regex.
|
||||
Source Source
|
||||
|
||||
// An expression evaluated on data point.
|
||||
Condition Expr
|
||||
|
||||
|
|
|
@ -1011,6 +1011,29 @@ func (p *Parser) parseShowMeasurementsStatement() (*ShowMeasurementsStatement, e
|
|||
stmt := &ShowMeasurementsStatement{}
|
||||
var err error
|
||||
|
||||
// Parse optional WITH clause.
|
||||
if tok, _, _ := p.scanIgnoreWhitespace(); tok == WITH {
|
||||
// Parse required MEASUREMENT token.
|
||||
if err := p.parseTokens([]Token{MEASUREMENT}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Parse required operator: = or =~.
|
||||
tok, pos, lit := p.scanIgnoreWhitespace()
|
||||
switch tok {
|
||||
case EQ, EQREGEX:
|
||||
// Parse required source (measurement name or regex).
|
||||
if stmt.Source, err = p.parseSource(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, newParseError(tokstr(tok, lit), []string{"=", "=~"}, pos)
|
||||
}
|
||||
} else {
|
||||
// Not a WITH clause so put the token back.
|
||||
p.unscan()
|
||||
}
|
||||
|
||||
// Parse condition: "WHERE EXPR".
|
||||
if stmt.Condition, err = p.parseCondition(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -751,6 +751,24 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
// SHOW MEASUREMENTS WITH MEASUREMENT = cpu
|
||||
{
|
||||
s: `SHOW MEASUREMENTS WITH MEASUREMENT = cpu`,
|
||||
stmt: &influxql.ShowMeasurementsStatement{
|
||||
Source: &influxql.Measurement{Name: "cpu"},
|
||||
},
|
||||
},
|
||||
|
||||
// SHOW MEASUREMENTS WITH MEASUREMENT =~ /regex/
|
||||
{
|
||||
s: `SHOW MEASUREMENTS WITH MEASUREMENT =~ /[cg]pu/`,
|
||||
stmt: &influxql.ShowMeasurementsStatement{
|
||||
Source: &influxql.Measurement{
|
||||
Regex: &influxql.RegexLiteral{Val: regexp.MustCompile(`[cg]pu`)},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// SHOW RETENTION POLICIES
|
||||
{
|
||||
s: `SHOW RETENTION POLICIES ON mydb`,
|
||||
|
|
Loading…
Reference in New Issue