This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
condition.go
59 lines (53 loc) · 2.24 KB
/
condition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package validators
import (
"fmt"
flyte "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
c "github.com/flyteorg/flytepropeller/pkg/compiler/common"
"github.com/flyteorg/flytepropeller/pkg/compiler/errors"
)
func validateOperand(node c.NodeBuilder, paramName string, operand *flyte.Operand,
requireParamType bool, errs errors.CompileErrors) (literalType *flyte.LiteralType, ok bool) {
if operand == nil {
errs.Collect(errors.NewValueRequiredErr(node.GetId(), paramName))
} else if operand.GetPrimitive() != nil {
// no validation
literalType = literalTypeForPrimitive(operand.GetPrimitive())
} else if len(operand.GetVar()) > 0 {
if node.GetInterface() != nil {
if param, paramOk := validateInputVar(node, operand.GetVar(), requireParamType, errs.NewScope()); paramOk {
if param != nil {
literalType = param.GetType()
}
}
} else {
errs.Collect(errors.NewValueRequiredErr(node.GetId(), operand.GetVar()))
}
} else {
errs.Collect(errors.NewValueRequiredErr(node.GetId(), fmt.Sprintf("%v.%v", paramName, "Val")))
}
return literalType, !errs.HasErrors()
}
func ValidateBooleanExpression(w c.WorkflowBuilder, node c.NodeBuilder, expr *flyte.BooleanExpression, requireParamType bool, errs errors.CompileErrors) (ok bool) {
if expr == nil {
errs.Collect(errors.NewBranchNodeHasNoCondition(node.GetId()))
} else {
if expr.GetComparison() != nil {
op1Type, op1Valid := validateOperand(node, "RightValue",
expr.GetComparison().GetRightValue(), requireParamType, errs.NewScope())
op2Type, op2Valid := validateOperand(node, "LeftValue",
expr.GetComparison().GetLeftValue(), requireParamType, errs.NewScope())
if op1Valid && op2Valid && op1Type != nil && op2Type != nil {
if op1Type.String() != op2Type.String() {
errs.Collect(errors.NewMismatchingTypesErr(node.GetId(), "RightValue",
op1Type.String(), op2Type.String()))
}
}
} else if expr.GetConjunction() != nil {
ValidateBooleanExpression(w, node, expr.GetConjunction().LeftExpression, requireParamType, errs.NewScope())
ValidateBooleanExpression(w, node, expr.GetConjunction().RightExpression, requireParamType, errs.NewScope())
} else {
errs.Collect(errors.NewValueRequiredErr(node.GetId(), "Expr"))
}
}
return !errs.HasErrors()
}