|
@@ -52,13 +52,11 @@ func registerStrFunc() {
|
|
builtins["endswith"] = builtinFunc{
|
|
builtins["endswith"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil || args[1] == nil {
|
|
|
|
- return false, true
|
|
|
|
- }
|
|
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
return strings.HasSuffix(arg0, arg1), true
|
|
return strings.HasSuffix(arg0, arg1), true
|
|
},
|
|
},
|
|
- val: ValidateTwoStrArg,
|
|
|
|
|
|
+ val: ValidateTwoStrArg,
|
|
|
|
+ check: returnFalseIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["indexof"] = builtinFunc{
|
|
builtins["indexof"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
@@ -80,29 +78,27 @@ func registerStrFunc() {
|
|
return len(v), true
|
|
return len(v), true
|
|
case map[string]interface{}:
|
|
case map[string]interface{}:
|
|
return len(v), true
|
|
return len(v), true
|
|
|
|
+ case nil:
|
|
|
|
+ return 0, true
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
return utf8.RuneCountInString(arg0), true
|
|
return utf8.RuneCountInString(arg0), true
|
|
},
|
|
},
|
|
- val: ValidateOneArg,
|
|
|
|
|
|
+ val: ValidateOneArg,
|
|
|
|
+ check: return0IfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["lower"] = builtinFunc{
|
|
builtins["lower"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return strings.ToLower(arg0), true
|
|
return strings.ToLower(arg0), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["lpad"] = builtinFunc{
|
|
builtins["lpad"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -110,18 +106,17 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return strings.Repeat(" ", arg1) + arg0, true
|
|
return strings.Repeat(" ", arg1) + arg0, true
|
|
},
|
|
},
|
|
- val: ValidateOneStrOneInt,
|
|
|
|
|
|
+ val: ValidateOneStrOneInt,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["ltrim"] = builtinFunc{
|
|
builtins["ltrim"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return strings.TrimLeftFunc(arg0, unicode.IsSpace), true
|
|
return strings.TrimLeftFunc(arg0, unicode.IsSpace), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["numbytes"] = builtinFunc{
|
|
builtins["numbytes"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
@@ -129,14 +124,12 @@ func registerStrFunc() {
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return len(arg0), true
|
|
return len(arg0), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: return0IfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["format_time"] = builtinFunc{
|
|
builtins["format_time"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0, err := cast.InterfaceToTime(args[0], "")
|
|
arg0, err := cast.InterfaceToTime(args[0], "")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err, false
|
|
return err, false
|
|
@@ -161,13 +154,11 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["regexp_matches"] = builtinFunc{
|
|
builtins["regexp_matches"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil || args[1] == nil {
|
|
|
|
- return false, true
|
|
|
|
- }
|
|
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
if matched, err := regexp.MatchString(arg1, arg0); err != nil {
|
|
if matched, err := regexp.MatchString(arg1, arg0); err != nil {
|
|
return err, false
|
|
return err, false
|
|
@@ -175,14 +166,12 @@ func registerStrFunc() {
|
|
return matched, true
|
|
return matched, true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- val: ValidateTwoStrArg,
|
|
|
|
|
|
+ val: ValidateTwoStrArg,
|
|
|
|
+ check: returnFalseIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["regexp_replace"] = builtinFunc{
|
|
builtins["regexp_replace"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil || args[1] == nil || args[2] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0, arg1, arg2 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1]), cast.ToStringAlways(args[2])
|
|
arg0, arg1, arg2 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1]), cast.ToStringAlways(args[2])
|
|
if re, err := regexp.Compile(arg1); err != nil {
|
|
if re, err := regexp.Compile(arg1); err != nil {
|
|
return err, false
|
|
return err, false
|
|
@@ -201,13 +190,11 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["regexp_substr"] = builtinFunc{
|
|
builtins["regexp_substr"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil || args[1] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
if re, err := regexp.Compile(arg1); err != nil {
|
|
if re, err := regexp.Compile(arg1); err != nil {
|
|
return err, false
|
|
return err, false
|
|
@@ -215,14 +202,12 @@ func registerStrFunc() {
|
|
return re.FindString(arg0), true
|
|
return re.FindString(arg0), true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- val: ValidateTwoStrArg,
|
|
|
|
|
|
+ val: ValidateTwoStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["rpad"] = builtinFunc{
|
|
builtins["rpad"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -230,25 +215,21 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return arg0 + strings.Repeat(" ", arg1), true
|
|
return arg0 + strings.Repeat(" ", arg1), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrOneInt,
|
|
|
|
|
|
+ val: ValidateOneStrOneInt,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["rtrim"] = builtinFunc{
|
|
builtins["rtrim"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return strings.TrimRightFunc(arg0, unicode.IsSpace), true
|
|
return strings.TrimRightFunc(arg0, unicode.IsSpace), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["substring"] = builtinFunc{
|
|
builtins["substring"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
arg1, err := cast.ToInt(args[1], cast.STRICT)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -312,24 +293,20 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["startswith"] = builtinFunc{
|
|
builtins["startswith"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return false, true
|
|
|
|
- }
|
|
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
return strings.HasPrefix(arg0, arg1), true
|
|
return strings.HasPrefix(arg0, arg1), true
|
|
},
|
|
},
|
|
- val: ValidateTwoStrArg,
|
|
|
|
|
|
+ val: ValidateTwoStrArg,
|
|
|
|
+ check: returnFalseIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["split_value"] = builtinFunc{
|
|
builtins["split_value"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil || args[1] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
arg0, arg1 := cast.ToStringAlways(args[0]), cast.ToStringAlways(args[1])
|
|
ss := strings.Split(arg0, arg1)
|
|
ss := strings.Split(arg0, arg1)
|
|
v, _ := cast.ToInt(args[2], cast.STRICT)
|
|
v, _ := cast.ToInt(args[2], cast.STRICT)
|
|
@@ -360,27 +337,24 @@ func registerStrFunc() {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["trim"] = builtinFunc{
|
|
builtins["trim"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return strings.TrimSpace(arg0), true
|
|
return strings.TrimSpace(arg0), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
builtins["upper"] = builtinFunc{
|
|
builtins["upper"] = builtinFunc{
|
|
fType: ast.FuncTypeScalar,
|
|
fType: ast.FuncTypeScalar,
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
|
|
- if args[0] == nil {
|
|
|
|
- return nil, true
|
|
|
|
- }
|
|
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
arg0 := cast.ToStringAlways(args[0])
|
|
return strings.ToUpper(arg0), true
|
|
return strings.ToUpper(arg0), true
|
|
},
|
|
},
|
|
- val: ValidateOneStrArg,
|
|
|
|
|
|
+ val: ValidateOneStrArg,
|
|
|
|
+ check: returnNilIfHasAnyNil,
|
|
}
|
|
}
|
|
}
|
|
}
|