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

feat: Add WITH KEY to show tag keys #20793

Merged
merged 3 commits into from
Feb 25, 2021
Merged

Conversation

lesam
Copy link
Contributor

@lesam lesam commented Feb 22, 2021

Closes #15993

  • CHANGELOG.md updated with a link to the PR (not the Issue)
  • Well-formatted commit messages
  • Rebased/mergeable
  • Tests pass
  • http/swagger.yml updated (if modified Go structs or API)
  • Feature flagged (if modified API)
  • Documentation updated or issue created (provide link to issue/pr)
  • Signed CLA (if not already signed)

@lesam lesam changed the title Fix tag keys Add WITH KEY to show tag keys Feb 22, 2021
tests/server_test.go Outdated Show resolved Hide resolved
indexSet := IndexSet{Indexes: []Index{index}, SeriesFile: s.sfile}
return indexSet.MeasurementTagKeyValuesByExpr(auth, name, key, expr, keysSorted)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@lesam lesam changed the title Add WITH KEY to show tag keys feat: Add WITH KEY to show tag keys Feb 22, 2021
// position of the tag key in the keys argument.
//
// N.B tagValuesByKeyAndExpr relies on keys being sorted in ascending
// lexicographic order.
func (is IndexSet) TagValuesByKeyAndExpr(auth query.Authorizer, name []byte, keys []string, expr influxql.Expr, fieldset *MeasurementFieldSet) ([]map[string]struct{}, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dead

@@ -1663,7 +1656,7 @@ func (s *Store) TagKeys(auth query.Authorizer, shardIDs []uint64, cond influxql.
for _, name := range names {

// Build keyset over all indexes for measurement.
tagKeySet, err := is.MeasurementTagKeysByExpr(name, nil)
tagKeySet, err := is.MeasurementTagKeysByExpr(name, tagKeyExpr)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same behaviour as 'show tag value with key'

@@ -1845,7 +1859,7 @@ func (s *Store) TagValues(auth query.Authorizer, shardIDs []uint64, cond influxq
// filter.
for _, name := range names {
// Determine a list of keys from condition.
keySet, err := is.MeasurementTagKeysByExpr(name, cond)
keySet, err := is.MeasurementTagKeysByExpr(name, tagKeyExpr)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This worked before because we always had a _tagKey field (enforced by the parser). But if you don't have any binary expressions with _tagKey but you do have a non-nil expression this returns an empty set.


nextResult := mergeTagValues(idxBuf, allResults[i:j+1]...)
i = j + 1
for _, r := range allResults {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably this used to be needed before iterators over IndexSet? Now the merge is done within the iterator.

// seriesByExprIterator doesn't handle
lit, ok := e.Expr.(*influxql.BooleanLiteral)
if !ok {
return nil, fmt.Errorf("Expression too complex for metaquery: %v", e.Expr)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this new error condition.

benbjohnson
benbjohnson previously approved these changes Feb 22, 2021
tsdb/exprs.go Outdated
passExpr = ExprsToConjunction(passSlice...)
failExpr = ExprsToConjunction(failSlice...)
return passExpr, failExpr, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The function looks fine but we use the term "partition" in a lot of places in the code and this partitioning seems unrelated to any of those. I'm not sure what better word would work but it's something to consider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. We use the same term in the flux code though (PartitionPredicate)

idxBuf := make([][2]int, 0, len(is.Indexes))
for i < len(allResults) {
result := make([]TagValues, 0, maxMeasurements)
for _, r := range allResults {
// check for timeouts
select {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this merge conflict with @davidby-influx 's PR merged yesterday.

@lesam lesam force-pushed the fix-tag-keys branch 2 times, most recently from c229e94 to e53e9db Compare February 24, 2021 12:35
query/statement_rewriter.go Outdated Show resolved Hide resolved
tsdb/exprs.go Outdated Show resolved Hide resolved
// seriesByExprIterator doesn't handle
lit, ok := e.Expr.(*influxql.BooleanLiteral)
if !ok {
return nil, fmt.Errorf("Expression too complex for metaquery: %v", e.Expr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if there is a more informative error message we could give the user here. "Meta queries don't support..."?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the exact rules are unfortunately, and I'm worried this would be hard to maintain if we add more support in the various places we partially evaluate the query.

@lesam lesam merged commit 17b9ea8 into influxdata:master-1.x Feb 25, 2021
},
&Query{
name: "show tag keys from regex with key in",
command: "SHOW TAG KEYS FROM /[cg]pu/ WITH KEY IN (host, region) ",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good example query

chengshiwen pushed a commit to chengshiwen/influxdb that referenced this pull request Sep 1, 2024
* fix: Change from RewriteExpr to PartitionExpr

Also remove some dead code

* feat: WITH KEY implementation

* feat: query rewriting for WITH KEY in SHOW TAG KEYS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants