funcValuer.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2021-2022 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 xsql
  15. import (
  16. "github.com/lf-edge/ekuiper/pkg/errorx"
  17. )
  18. // FunctionValuer ONLY use NewFunctionValuer function to initialize
  19. type FunctionValuer struct {
  20. runtime *funcRuntime
  21. }
  22. // Should only be called by stream to make sure a single instance for an operation
  23. func NewFunctionValuer(p *funcRuntime) *FunctionValuer {
  24. fv := &FunctionValuer{
  25. runtime: p,
  26. }
  27. return fv
  28. }
  29. func (*FunctionValuer) Value(_, _ string) (interface{}, bool) {
  30. return nil, false
  31. }
  32. func (*FunctionValuer) Meta(_, _ string) (interface{}, bool) {
  33. return nil, false
  34. }
  35. func (*FunctionValuer) AppendAlias(string, interface{}) bool {
  36. return false
  37. }
  38. func (*FunctionValuer) AliasValue(string) (interface{}, bool) {
  39. return nil, false
  40. }
  41. func (fv *FunctionValuer) Call(name string, funcId int, args []interface{}) (interface{}, bool) {
  42. nf, fctx, err := fv.runtime.Get(name, funcId)
  43. switch err {
  44. case errorx.NotFoundErr:
  45. return nil, false
  46. case nil:
  47. // do nothing, continue
  48. default:
  49. return err, false
  50. }
  51. return ExecFunc(name, nf, args, fctx)
  52. }