Skip to content

Commit

Permalink
chore: do a nil check for all but == and != ops
Browse files Browse the repository at this point in the history
  • Loading branch information
raj-k-singh committed Nov 24, 2023
1 parent ec96604 commit 6044e24
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
expr "github.com/antonmedv/expr"
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

var logOperatorsToExpr = map[v3.FilterOperator]string{
Expand Down Expand Up @@ -65,18 +64,11 @@ func Parse(filters *v3.FilterSet) (string, error) {
filter = fmt.Sprintf("%s %s %s", exprFormattedValue(v.Key.Key), logOperatorsToExpr[v.Operator], getTypeName(v.Key.Type))
default:
filter = fmt.Sprintf("%s %s %s", name, logOperatorsToExpr[v.Operator], exprFormattedValue(v.Value))
}

if slices.Contains(
[]v3.FilterOperator{
v3.FilterOperatorContains,
v3.FilterOperatorNotContains,
v3.FilterOperatorRegex,
v3.FilterOperatorNotRegex,
},
v.Operator,
) {
filter = fmt.Sprintf("%s != nil && %s", name, filter)
// Avoid running operators on nil values
if v.Operator != v3.FilterOperatorEqual && v.Operator != v3.FilterOperatorNotEqual {
filter = fmt.Sprintf("%s != nil && %s", name, filter)
}
}

// check if the filter is a correct expression language
Expand Down

0 comments on commit 6044e24

Please sign in to comment.