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 60
/
vars.go
60 lines (49 loc) · 1.86 KB
/
vars.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
60
package validators
import (
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 validateOutputVar(n c.NodeBuilder, paramName string, errs errors.CompileErrors) (
param *flyte.Variable, ok bool) {
if outputs, effectiveOk := validateEffectiveOutputParameters(n, errs.NewScope()); effectiveOk {
var paramFound bool
if param, paramFound = findVariableByName(outputs, paramName); !paramFound {
errs.Collect(errors.NewVariableNameNotFoundErr(n.GetId(), n.GetId(), paramName))
}
}
return param, !errs.HasErrors()
}
func validateInputVar(n c.NodeBuilder, paramName string, requireParamType bool, errs errors.CompileErrors) (param *flyte.Variable, ok bool) {
if n.GetInterface() == nil {
return nil, false
}
if param, ok = findVariableByName(n.GetInterface().GetInputs(), paramName); ok {
return
}
if !requireParamType {
if containsBindingByVariableName(n.GetInputs(), paramName) {
return
}
}
errs.Collect(errors.NewVariableNameNotFoundErr(n.GetId(), n.GetId(), paramName))
return
}
func validateVarType(nodeID c.NodeID, paramName string, param *flyte.Variable,
expectedType *flyte.LiteralType, errs errors.CompileErrors) (ok bool) {
if param.GetType().String() != expectedType.String() {
errs.Collect(errors.NewMismatchingTypesErr(nodeID, paramName, param.GetType().String(), expectedType.String()))
}
return !errs.HasErrors()
}
// Validate parameters have their required attributes set
func validateVariables(nodeID c.NodeID, params *flyte.VariableMap, errs errors.CompileErrors) {
for paramName, param := range params.Variables {
if len(paramName) == 0 {
errs.Collect(errors.NewValueRequiredErr(nodeID, "paramName"))
}
if param.Type == nil {
errs.Collect(errors.NewValueRequiredErr(nodeID, "param.Type"))
}
}
}