Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect misquoted tag values and return an error #22754

Merged
merged 5 commits into from
Oct 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ func (s *Store) TagKeys(ctx context.Context, auth query.FineAuthorizer, shardIDs
return nil, err
}

filterExpr = fixBadQuoteTagValueClause(filterExpr)

// Get all the shards we're interested in.
is := IndexSet{Indexes: make([]Index, 0, len(shardIDs))}
s.mu.RLock()
Expand Down Expand Up @@ -1822,6 +1824,27 @@ func isTagKeyClause(e influxql.Expr) (bool, error) {
return false, nil
}

func fixBadQuoteTagValueClause(e influxql.Expr) influxql.Expr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I'd prefer that semantics we don't support become an error instead of hiding the problem by returning a false.

switch e := e.(type) {
case *influxql.BinaryExpr:
switch e.Op {
case influxql.EQ, influxql.NEQ:
_, lOk := e.LHS.(*influxql.VarRef)
_, rOk := e.RHS.(*influxql.VarRef)
if lOk && rOk {
return &influxql.BooleanLiteral{Val: false}
}
case influxql.OR, influxql.AND:
e.LHS = fixBadQuoteTagValueClause(e.LHS)
e.RHS = fixBadQuoteTagValueClause(e.RHS)
return e
}
case *influxql.ParenExpr:
return fixBadQuoteTagValueClause(e.Expr)
}
return e
}

// TagValues returns the tag keys and values for the provided shards, where the
// tag values satisfy the provided condition.
func (s *Store) TagValues(ctx context.Context, auth query.FineAuthorizer, shardIDs []uint64, cond influxql.Expr) ([]TagValues, error) {
Expand Down