rule_query.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 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. //go:build rpc || !core
  15. // +build rpc !core
  16. package processor
  17. import (
  18. "github.com/lf-edge/ekuiper/internal/topo"
  19. "github.com/lf-edge/ekuiper/internal/topo/node"
  20. "github.com/lf-edge/ekuiper/internal/topo/planner"
  21. )
  22. func (p *RuleProcessor) ExecQuery(ruleid, sql string) (*topo.Topo, error) {
  23. if tp, err := planner.PlanWithSourcesAndSinks(p.getDefaultRule(ruleid, sql), nil, []*node.SinkNode{node.NewSinkNode("sink_memory_log", "logToMemory", nil)}); err != nil {
  24. return nil, err
  25. } else {
  26. go func() {
  27. select {
  28. case err := <-tp.Open():
  29. if err != nil {
  30. log.Infof("closing query for error: %v", err)
  31. tp.GetContext().SetError(err)
  32. tp.Cancel()
  33. } else {
  34. log.Info("closing query")
  35. }
  36. }
  37. }()
  38. return tp, nil
  39. }
  40. }