From 6044e2468abad0292f192cf7eda21eb8841db751 Mon Sep 17 00:00:00 2001 From: Raj Date: Fri, 24 Nov 2023 09:49:01 +0530 Subject: [PATCH] chore: do a nil check for all but == and != ops --- .../queryBuilderToExpr/queryBuilderToExpr.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go b/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go index b6cb8fa59a5..45bcc694059 100644 --- a/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go +++ b/pkg/query-service/queryBuilderToExpr/queryBuilderToExpr.go @@ -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{ @@ -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