Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bug): Remove warnings in native plugin manager #1418

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions internal/binder/function/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package function
import (
"github.com/lf-edge/ekuiper/internal/binder"
"github.com/lf-edge/ekuiper/pkg/api"
"github.com/lf-edge/ekuiper/pkg/ast"
"github.com/lf-edge/ekuiper/pkg/errorx"
)

Expand All @@ -25,15 +26,6 @@ var ( // init once and read only
funcFactoriesNames []string
)

type FuncType int

const (
FuncTypeUnknown FuncType = iota - 1
FuncTypeScalar
FuncTypeAgg
FuncTypeCols
)

func init() {
f := binder.FactoryEntry{
Name: "built-in",
Expand Down Expand Up @@ -92,31 +84,31 @@ func ConvName(name string) (string, bool) {
}

type multiAggFunc interface {
GetFuncType(name string) FuncType
GetFuncType(name string) ast.FuncType
}

func IsAggFunc(funcName string) bool {
f, _ := Function(funcName)
if f != nil {
if mf, ok := f.(multiAggFunc); ok {
return mf.GetFuncType(funcName) == FuncTypeAgg
return mf.GetFuncType(funcName) == ast.FuncTypeAgg
} else {
return f.IsAggregate()
}
}
return false
}

func GetFuncType(funcName string) FuncType {
func GetFuncType(funcName string) ast.FuncType {
f, _ := Function(funcName)
if f != nil {
if mf, ok := f.(multiAggFunc); ok {
return mf.GetFuncType(funcName)
}
if f.IsAggregate() {
return FuncTypeAgg
return ast.FuncTypeAgg
}
return FuncTypeScalar
return ast.FuncTypeScalar
}
return FuncTypeUnknown
return ast.FuncTypeUnknown
}
14 changes: 7 additions & 7 deletions internal/binder/function/funcs_agg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func registerAggFunc() {
builtins["avg"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
arg0 := args[0].([]interface{})
c := getCount(arg0)
Expand Down Expand Up @@ -52,15 +52,15 @@ func registerAggFunc() {
val: ValidateOneNumberArg,
}
builtins["count"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
arg0 := args[0].([]interface{})
return getCount(arg0), true
},
val: ValidateOneArg,
}
builtins["max"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
arg0 := args[0].([]interface{})
if len(arg0) > 0 {
Expand Down Expand Up @@ -101,7 +101,7 @@ func registerAggFunc() {
val: ValidateOneNumberArg,
}
builtins["min"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
arg0 := args[0].([]interface{})
if len(arg0) > 0 {
Expand Down Expand Up @@ -142,7 +142,7 @@ func registerAggFunc() {
val: ValidateOneNumberArg,
}
builtins["sum"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
arg0 := args[0].([]interface{})
if len(arg0) > 0 {
Expand Down Expand Up @@ -171,14 +171,14 @@ func registerAggFunc() {
val: ValidateOneNumberArg,
}
builtins["collect"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
return args[0], true
},
val: ValidateOneArg,
}
builtins["deduplicate"] = builtinFunc{
fType: FuncTypeAgg,
fType: ast.FuncTypeAgg,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
v1, ok1 := args[0].([]interface{})
v2, ok2 := args[1].([]interface{})
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/function/funcs_cols.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func wrapColFunc(colFunc ColFunc) funcExe {

func registerColsFunc() {
builtins["changed_cols"] = builtinFunc{
fType: FuncTypeCols,
fType: ast.FuncTypeCols,
exec: wrapColFunc(changedFunc),
val: func(_ api.FunctionContext, args []ast.Expr) error {
if len(args) <= 2 {
Expand Down
50 changes: 25 additions & 25 deletions internal/binder/function/funcs_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func registerMathFunc() {
builtins["abs"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, ok := args[0].(int); ok {
t := float64(v)
Expand All @@ -39,7 +39,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["acos"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Acos(v), true
Expand All @@ -50,7 +50,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["asin"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Asin(v), true
Expand All @@ -61,7 +61,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["atan"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Atan(v), true
Expand All @@ -72,7 +72,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["atan2"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v1, e := toF64(args[0]); e == nil {
if v2, e1 := toF64(args[1]); e1 == nil {
Expand All @@ -87,7 +87,7 @@ func registerMathFunc() {
val: ValidateTwoNumberArg,
}
builtins["bitand"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
v1, ok1 := args[0].(int)
v2, ok2 := args[1].(int)
Expand All @@ -100,7 +100,7 @@ func registerMathFunc() {
val: ValidateTwoIntArg,
}
builtins["bitor"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
v1, ok1 := args[0].(int)
v2, ok2 := args[1].(int)
Expand All @@ -113,7 +113,7 @@ func registerMathFunc() {
val: ValidateTwoIntArg,
}
builtins["bitxor"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
v1, ok1 := args[0].(int)
v2, ok2 := args[1].(int)
Expand All @@ -126,7 +126,7 @@ func registerMathFunc() {
val: ValidateTwoIntArg,
}
builtins["bitnot"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
v1, ok1 := args[0].(int)
if ok1 {
Expand All @@ -146,7 +146,7 @@ func registerMathFunc() {
},
}
builtins["ceil"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Ceil(v), true
Expand All @@ -157,7 +157,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["cos"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Cos(v), true
Expand All @@ -168,7 +168,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["cosh"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Cosh(v), true
Expand All @@ -179,7 +179,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["exp"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Exp(v), true
Expand All @@ -190,7 +190,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["ln"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Log2(v), true
Expand All @@ -201,7 +201,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["log"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Log10(v), true
Expand All @@ -212,7 +212,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["mod"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
if v1, e1 := toF64(args[1]); e == nil {
Expand All @@ -227,7 +227,7 @@ func registerMathFunc() {
val: ValidateTwoNumberArg,
}
builtins["power"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v1, e := toF64(args[0]); e == nil {
if v2, e2 := toF64(args[1]); e2 == nil {
Expand All @@ -242,14 +242,14 @@ func registerMathFunc() {
val: ValidateTwoNumberArg,
}
builtins["rand"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
return rand.Float64(), true
},
val: ValidateOneArg,
}
builtins["round"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Round(v), true
Expand All @@ -260,7 +260,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["sign"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
if v > 0 {
Expand All @@ -277,7 +277,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["sin"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Sin(v), true
Expand All @@ -288,7 +288,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["sinh"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Sinh(v), true
Expand All @@ -299,7 +299,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["sqrt"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Sqrt(v), true
Expand All @@ -310,7 +310,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["tan"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Tan(v), true
Expand All @@ -321,7 +321,7 @@ func registerMathFunc() {
val: ValidateOneNumberArg,
}
builtins["tanh"] = builtinFunc{
fType: FuncTypeScalar,
fType: ast.FuncTypeScalar,
exec: func(ctx api.FunctionContext, args []interface{}) (interface{}, bool) {
if v, e := toF64(args[0]); e == nil {
return math.Tanh(v), true
Expand Down
Loading