app/vmselect/promql: refactor implementations for and and unless binary operations, so they are closer to or implementation

This commit is contained in:
Aliaksandr Valialkin 2020-07-09 13:05:42 +03:00
parent 2d9b3ad5b3
commit 256fd9a87e

View file

@ -290,12 +290,14 @@ func binaryOpAnd(bfa *binaryOpFuncArg) ([]*timeseries, error) {
if tssLeft == nil { if tssLeft == nil {
continue continue
} }
for i := range tssLeft[0].Values { // Add gaps to tssLeft if there are gaps at valuesRight.
if !isAllNaNs(tssRight, i) { valuesRight := tssRight[0].Values
continue
}
for _, tsLeft := range tssLeft { for _, tsLeft := range tssLeft {
tsLeft.Values[i] = nan valuesLeft := tsLeft.Values
for i, v := range valuesRight {
if math.IsNaN(v) {
valuesLeft[i] = nan
}
} }
} }
tssLeft = removeNaNs(tssLeft) tssLeft = removeNaNs(tssLeft)
@ -340,12 +342,14 @@ func binaryOpUnless(bfa *binaryOpFuncArg) ([]*timeseries, error) {
rvs = append(rvs, tssLeft...) rvs = append(rvs, tssLeft...)
continue continue
} }
for i := range tssLeft[0].Values { // Add gaps to tssLeft if the are no gaps at valuesRight.
if isAllNaNs(tssRight, i) { valuesRight := tssRight[0].Values
continue
}
for _, tsLeft := range tssLeft { for _, tsLeft := range tssLeft {
tsLeft.Values[i] = nan valuesLeft := tsLeft.Values
for i, v := range valuesRight {
if !math.IsNaN(v) {
valuesLeft[i] = nan
}
} }
} }
tssLeft = removeNaNs(tssLeft) tssLeft = removeNaNs(tssLeft)
@ -354,15 +358,6 @@ func binaryOpUnless(bfa *binaryOpFuncArg) ([]*timeseries, error) {
return rvs, nil return rvs, nil
} }
func isAllNaNs(tss []*timeseries, idx int) bool {
for _, ts := range tss {
if !math.IsNaN(ts.Values[idx]) {
return false
}
}
return true
}
func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*timeseries) (map[string][]*timeseries, map[string][]*timeseries) { func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*timeseries) (map[string][]*timeseries, map[string][]*timeseries) {
groupTags := be.GroupModifier.Args groupTags := be.GroupModifier.Args
groupOp := strings.ToLower(be.GroupModifier.Op) groupOp := strings.ToLower(be.GroupModifier.Op)