promql-engine
promql-engine copied to clipboard
Push boolean operations into scanners
Certain PromQL expression can be considered as (sample) selectors and can be evaluated directly in scanners.
One example is:
sum(kube_pod_info == 1)
For this query, we could apply == 1 directly into the vector_selector (maybe we should rename this to vector_scanner) and avoid emitting samples which do not match that binary operation.
As far as I can understand, the ability to consider certain PromQL expressions as sample selectors and evaluate them directly in scanners is to optimize the query execution process. By applying the binary operation directly in the vector selector (or scanner), unnecessary samples that do not match the binary operation can be avoided, leading to more efficient query evaluation. As a potential optimization, does implementing a custom logical operator injected at the instantiation of the engine to handle the specific PromQL expressions that can be directly evaluated in scanners feels right to you? Should I try to solve this issue (I may need some help though)? @fpetkovski
Hi @harsh-ps-2003, thank you for looking into this. Instead of a new operator, I would suggest adding a filtering function to the vector scanner which would take in a step vector and produce a new step vector with filtered samples.
following your suggestion @fpetkovski I did the following changes in vector selector :
// Implementation of the filtering function.
func filterBinaryOpEqual(v model.StepVector, value float64) model.StepVector {
filtered := model.StepVector{}
// Iterate over the samples in the StepVector.
for i, sample := range v.Samples {
if sample == value {
// Append the matching sample to the filtered StepVector.
filtered.AppendSample(nil, v.SampleIDs[i], sample)
}
}
return filtered
}
to filter the samples through vector scanner. But I dont know how to test whether my code is working or not! Any directions?
I suggest that you add a new test case in this test and then we can see if your change works.
Feel free to raise a PR with the new test and your change.
I tried to solve the issue, but it seems that I am unable to do so. Still I am making a draft PR so that you could see what am I messing up.