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 a regression when math was used with selectors #8168

Merged
merged 1 commit into from
Mar 28, 2017

Conversation

jsternberg
Copy link
Contributor

@jsternberg jsternberg commented Mar 20, 2017

If there were multiple selectors and math, the query engine would
mistakenly think it was the only selector in the query and would not
match their timestamps.

Fixed the query engine to pass whether the selector should be treated as
a selector so queries like max(value) * 1, min(value) * 1 will match
the timestamps of the result.

Fixes #8167.

  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

@jsternberg jsternberg force-pushed the js-8167-math-with-multiple-selectors branch from f010b95 to 4eb1953 Compare March 20, 2017 17:36
If there were multiple selectors and math, the query engine would
mistakenly think it was the only selector in the query and would not
match their timestamps.

Fixed the query engine to pass whether the selector should be treated as
a selector so queries like `max(value) * 1, min(value) * 1` will match
the timestamps of the result.
@jsternberg jsternberg force-pushed the js-8167-math-with-multiple-selectors branch from 4eb1953 to b14c292 Compare March 27, 2017 19:12
@jsternberg
Copy link
Contributor Author

@rbetts proposed for backporting to 1.2.

if err != nil {
return nil, err
}
return buildRHSTransformIterator(lhs, rhs, expr.Op, b.opt)
} else if lhs, ok := expr.LHS.(Literal); ok {
rhs, err := buildExprIterator(expr.RHS, b.ic, b.sources, b.opt, IsSelector(expr.RHS))
rhs, err := buildExprIterator(expr.RHS, b.ic, b.sources, b.opt, b.selector)
Copy link
Contributor

Choose a reason for hiding this comment

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

The current implementation of IsSelector:

func IsSelector(expr Expr) bool {
	if call, ok := expr.(*Call); ok {
		switch call.Name {
		case "first", "last", "min", "max", "percentile", "sample", "top", "bottom":
			return true
		}
	}
	return false
}

I'm concerned about the other uses of IsSelector being broken in the same way it was here – missing a Call in a binary expression, etc. Is there a separate issue to track/audit the other uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IsSelector wasn't broken here. It was just improperly used. IsSelector correctly identified the expression was a selector, but it was supposed to recognize an earlier conclusion by the query engine not to treat the selectors as selectors.

The reason is because max(), when it's treated as a selector, uses the time of the point it selects. When it's treated as an aggregate, it normalizes the time to be the beginning of the current interval. When we deal with any expression where there are multiple selectors (including binary expressions or separately selected), it's not supposed to treat the selectors as selectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand now - IsSelector is working as intended. Fine by me to merge.

@jsternberg jsternberg merged commit 2410946 into master Mar 28, 2017
@jsternberg jsternberg deleted the js-8167-math-with-multiple-selectors branch March 28, 2017 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants