projectPlan.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 planner
  15. import "github.com/lf-edge/ekuiper/pkg/ast"
  16. type ProjectPlan struct {
  17. baseLogicalPlan
  18. isAggregate bool
  19. allWildcard bool
  20. sendMeta bool
  21. fields ast.Fields
  22. colNames [][]string
  23. aliasNames []string
  24. exprNames []string
  25. wildcardEmitters map[string]bool
  26. aliasFields ast.Fields
  27. exprFields ast.Fields
  28. }
  29. func (p ProjectPlan) Init() *ProjectPlan {
  30. p.allWildcard = false
  31. p.wildcardEmitters = make(map[string]bool)
  32. for _, field := range p.fields {
  33. if field.AName != "" {
  34. p.aliasFields = append(p.aliasFields, field)
  35. p.aliasNames = append(p.aliasNames, field.AName)
  36. } else {
  37. switch ft := field.Expr.(type) {
  38. case *ast.Wildcard:
  39. p.allWildcard = true
  40. case *ast.FieldRef:
  41. if ft.Name == "*" {
  42. p.wildcardEmitters[string(ft.StreamName)] = true
  43. } else {
  44. p.colNames = append(p.colNames, []string{ft.Name, string(ft.StreamName)})
  45. }
  46. default:
  47. p.exprNames = append(p.exprNames, field.Name)
  48. p.exprFields = append(p.exprFields, field)
  49. }
  50. }
  51. }
  52. p.baseLogicalPlan.self = &p
  53. return &p
  54. }
  55. func (p *ProjectPlan) PruneColumns(fields []ast.Expr) error {
  56. f := getFields(p.fields)
  57. return p.baseLogicalPlan.PruneColumns(append(fields, f...))
  58. }