static_executor.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package function
  15. import (
  16. "fmt"
  17. "github.com/lf-edge/ekuiper/pkg/api"
  18. "github.com/lf-edge/ekuiper/pkg/ast"
  19. )
  20. type funcExecutor struct{}
  21. func (f *funcExecutor) ValidateWithName(args []ast.Expr, name string) error {
  22. fs, ok := builtins[name]
  23. if !ok {
  24. return fmt.Errorf("validate function %s error: unknown name", name)
  25. }
  26. var eargs []ast.Expr
  27. for _, arg := range args {
  28. if t, ok := arg.(ast.Expr); ok {
  29. eargs = append(eargs, t)
  30. } else {
  31. // should never happen
  32. return fmt.Errorf("receive invalid arg %v", arg)
  33. }
  34. }
  35. // TODO pass in ctx
  36. return fs.val(nil, eargs)
  37. }
  38. func (f *funcExecutor) Validate(_ []interface{}) error {
  39. return fmt.Errorf("unknow name")
  40. }
  41. func (f *funcExecutor) Exec(_ []interface{}, _ api.FunctionContext) (interface{}, bool) {
  42. return fmt.Errorf("unknow name"), false
  43. }
  44. func (f *funcExecutor) ExecWithName(args []interface{}, ctx api.FunctionContext, name string) (interface{}, bool) {
  45. fs, ok := builtins[name]
  46. if !ok {
  47. return fmt.Errorf("unknow name"), false
  48. }
  49. return fs.exec(ctx, args)
  50. }
  51. func (f *funcExecutor) IsAggregate() bool {
  52. return false
  53. }
  54. func (f *funcExecutor) GetFuncType(name string) ast.FuncType {
  55. fs, ok := builtins[name]
  56. if !ok {
  57. return ast.FuncTypeUnknown
  58. }
  59. return fs.fType
  60. }
  61. var (
  62. staticFuncExecutor = &funcExecutor{}
  63. )