funcValuer.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2021 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 (fv *FunctionValuer) Call(name string, args []interface{}) (interface{}, bool) {
  39. nf, fctx, err := fv.runtime.Get(name)
  40. switch err {
  41. case errorx.NotFoundErr:
  42. return nil, false
  43. case nil:
  44. // do nothing, continue
  45. default:
  46. return err, false
  47. }
  48. return ExecFunc(name, nf, args, fctx)
  49. }