-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[pkg/telemetryquerylanguage] Add ordering inequalities to comparisons #12491
Comments
@TylerHelmuth ^ thoughts? |
We definitely need this. I think your idea about returning false is correct for mismatching types. Maybe we could write out a log when that happens?
Agreed, that's what Factory functions are good for. Can you add the "nil" and "Bytes" literals to your table? |
Also, I think "Missing" is the same as the literal "nil" case. If a Getter returns nil it should be treated the same as nil. I don't think we should assume |
@TylerHelmuth updated. If this seems OK, feel free to assign it to me. I should be able to do it early next week. |
@kentquirk assigned. For int to float and float to int, we may not be able to do that coercion. Sometimes comparison is done between 2 Getters and we don't actually know the type returned by the Getter until data is processing. We might want to enforce the use of Factories instead of doing type checking and conversion during the hot path. Interested to see what you come up with. |
Pinging code owners: @TylerHelmuth @kentquirk |
@TylerHelmuth I have been implementing this, and I've made a few decisions in the details
Please see the draft PR in progress linked below. |
I think this makes sense. When the PR is ready let me know and I'll take an in-depth look. |
Is your feature request related to a problem? Please describe.
Currently, TQL supports strict equality ('==') and inequality ('!='). It would be useful to support ordering comparisons as well -- specifically, ('<'), ('>'), ('<='), and ('>=').
Adding them to the grammar is pretty simple, but it's slightly trickier to extend the expression evaluators.
Describe the solution you'd like
We need to define the semantics appropriately for comparing two values that may potentially be different base types. The semantics should be symmetric (
a < b
should give the identical result tob > a
). Also, there really can't be the concept of an error -- the condition just has to return a boolean result.We propose that comparisons between different types always evaluate to false. Anything else can be fixed with type coercion functions.
The details:
Describe alternatives you've considered
Alternatives are:
Compare(http.return, 400, ">") == true
. I think this is unnecessarily wordy.Within this proposal, we could try harder to coerce things into compatible types. For example, when comparing a string to a numeric value, we could try to parse the string as a numeric value. This would allow, say, comparing an http return of "500" to 500. Personally, I'd rather fix this with explicit type conversion functions like
int("500")
. Similarly, bools could be coerced to numeric values (0 and 1, or 0 and -1) withint()
orfloat()
functions.The text was updated successfully, but these errors were encountered: