-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 2 commits
4643eba
72ee1f3
31d17de
46327a6
c9cfa50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1654,6 +1654,9 @@ func (s *Store) TagKeys(ctx context.Context, auth query.FineAuthorizer, shardIDs | |||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
if err = isBadQuoteTagValueClause(filterExpr); err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
// Get all the shards we're interested in. | ||||||
is := IndexSet{Indexes: make([]Index, 0, len(shardIDs))} | ||||||
|
@@ -1822,6 +1825,31 @@ func isTagKeyClause(e influxql.Expr) (bool, error) { | |||||
return false, nil | ||||||
} | ||||||
|
||||||
func isBadQuoteTagValueClause(e influxql.Expr) error { | ||||||
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 fmt.Errorf("bad WHERE clause. tag value must be inside single quotes: %s", e.String()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should emphasize in the error that this is only a metaquery restriction, since normal selects are OK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to mention single quotes so they know how to fix it. I don't think the fact that single quotes give literals and double quotes give fields and tags is very obvious. I also don't like "bad WHERE clause for metaquery. one term must be a string literal tag value within single quotes: %s" The user will know which term should be the tag value, presumably. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me, though I'd slightly prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was formatting with period based on another message in that file: "cannot delete data. DB contains shards using both inmem and tsi1 indexes. Please convert all shards to use the same index type to delete data." Maybe I should have made a wider search for compound error statements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. compromise, because I hate two colons in a singe sentence. semi-colon. |
||||||
} | ||||||
case influxql.OR, influxql.AND: | ||||||
if err := isBadQuoteTagValueClause(e.LHS); err != nil { | ||||||
return err | ||||||
} else if err = isBadQuoteTagValueClause(e.RHS); err != nil { | ||||||
return err | ||||||
} else { | ||||||
return nil | ||||||
} | ||||||
} | ||||||
case *influxql.ParenExpr: | ||||||
return isBadQuoteTagValueClause(e.Expr) | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
// 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) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should put in there permanently, but do any tests fail if we put this check on
SELECT
as well? might highlight a case we missed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SELECT ... WHERE
supports the syntax this disallows, so this will err on legal queries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the test failures where this test breaks correct queries in
SELECT