checkAgg.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package ast
  2. // IsAggregate check if an expression is aggregate with the binding alias info
  3. func IsAggregate(expr Expr) (r bool) {
  4. WalkFunc(expr, func(n Node) bool {
  5. switch f := n.(type) {
  6. case *Call:
  7. if ok := FuncFinderSingleton().IsAggFunc(f); ok {
  8. r = true
  9. return false
  10. }
  11. case *FieldRef:
  12. if f.IsAggregate() {
  13. r = true
  14. return false
  15. }
  16. }
  17. return true
  18. })
  19. return
  20. }
  21. func IsAggStatement(stmt *SelectStatement) bool {
  22. if stmt.Dimensions != nil {
  23. ds := stmt.Dimensions.GetGroups()
  24. if ds != nil && len(ds) > 0 {
  25. return true
  26. }
  27. }
  28. r := false
  29. WalkFunc(stmt.Fields, func(n Node) bool {
  30. switch f := n.(type) {
  31. case *Call:
  32. if ok := FuncFinderSingleton().IsAggFunc(f); ok {
  33. r = true
  34. return false
  35. }
  36. }
  37. return true
  38. })
  39. return r
  40. }
  41. func HasAggFuncs(node Node) bool {
  42. if node == nil {
  43. return false
  44. }
  45. var r = false
  46. WalkFunc(node, func(n Node) bool {
  47. if f, ok := n.(*Call); ok {
  48. if ok := FuncFinderSingleton().IsAggFunc(f); ok {
  49. r = true
  50. return false
  51. }
  52. }
  53. return true
  54. })
  55. return r
  56. }