diff --git a/pkg/query_expr/delete_asset_expr.go b/pkg/query_expr/delete_asset_expr.go index ec224628..cdcc12d3 100644 --- a/pkg/query_expr/delete_asset_expr.go +++ b/pkg/query_expr/delete_asset_expr.go @@ -2,6 +2,7 @@ package queryexpr import ( "fmt" + "strings" "github.com/goto/compass/core/asset" generichelper "github.com/goto/compass/pkg/generic_helper" @@ -29,11 +30,11 @@ func (d DeleteAssetExpr) Validate() error { return fmt.Errorf("must exists these identifiers: refreshed_at, type, and service") } - getOperator := func(jsonTag string) string { - return identifiersWithOperator[jsonTag] + isOperatorEqualsOrIn := func(jsonTag string) bool { + return identifiersWithOperator[jsonTag] == "==" || strings.ToUpper(identifiersWithOperator[jsonTag]) == "IN" } - if getOperator("type") != "==" || getOperator("service") != "==" { - return fmt.Errorf("identifier type and service must be equals operator (==)") + if !isOperatorEqualsOrIn("type") || !isOperatorEqualsOrIn("service") { + return fmt.Errorf("identifier type and service must be equals (==) or IN operator") } identifiers := generichelper.GetMapKeys(identifiersWithOperator) diff --git a/pkg/query_expr/query_expr.go b/pkg/query_expr/query_expr.go index bb471c05..7680efd4 100644 --- a/pkg/query_expr/query_expr.go +++ b/pkg/query_expr/query_expr.go @@ -2,6 +2,7 @@ package queryexpr import ( "fmt" + "strings" "github.com/expr-lang/expr" "github.com/expr-lang/expr/ast" @@ -34,13 +35,26 @@ func ValidateAndGetQueryFromExpr(exprStr ExprStr) (string, error) { // Visit is implementation Visitor interface from expr-lang/expr lib, used by ast.Walk func (s *ExprVisitor) Visit(node *ast.Node) { //nolint:gocritic - if n, ok := (*node).(*ast.BinaryNode); ok { + switch n := (*node).(type) { + case *ast.BinaryNode: if left, ok := (n.Left).(*ast.IdentifierNode); ok { s.IdentifiersWithOperator[left.Value] = n.Operator } if right, ok := (n.Right).(*ast.IdentifierNode); ok { s.IdentifiersWithOperator[right.Value] = n.Operator } + case *ast.UnaryNode: + if binaryNode, ok := (n.Node).(*ast.BinaryNode); ok { + if strings.ToUpper(binaryNode.Operator) == "IN" { + notInOperator := "NOT IN" + if left, ok := (binaryNode.Left).(*ast.IdentifierNode); ok { + s.IdentifiersWithOperator[left.Value] = notInOperator + } + if right, ok := (binaryNode.Right).(*ast.IdentifierNode); ok { + s.IdentifiersWithOperator[right.Value] = notInOperator + } + } + } } }