github.com/MontFerret/ferret@v0.18.0/pkg/runtime/expressions/clauses/collect_selector.go (about) 1 package clauses 2 3 import "github.com/MontFerret/ferret/pkg/runtime/core" 4 5 type ( 6 CollectSelector struct { 7 variable string 8 expression core.Expression 9 } 10 11 CollectAggregateSelector struct { 12 variable string 13 aggregators []core.Expression 14 reducer core.Function 15 } 16 ) 17 18 func NewCollectSelector(variable string, exp core.Expression) (*CollectSelector, error) { 19 if variable == "" { 20 return nil, core.Error(core.ErrMissedArgument, "selector variable") 21 } 22 23 if exp == nil { 24 return nil, core.Error(core.ErrMissedArgument, "selector reducer") 25 } 26 27 return &CollectSelector{variable, exp}, nil 28 } 29 30 func (selector *CollectSelector) Variable() string { 31 return selector.variable 32 } 33 34 func (selector *CollectSelector) Expression() core.Expression { 35 return selector.expression 36 } 37 38 func NewCollectAggregateSelector(variable string, aggr []core.Expression, reducer core.Function) (*CollectAggregateSelector, error) { 39 if variable == "" { 40 return nil, core.Error(core.ErrMissedArgument, "selector variable") 41 } 42 43 if reducer == nil { 44 return nil, core.Error(core.ErrMissedArgument, "selector reducer") 45 } 46 47 if aggr == nil { 48 return nil, core.Error(core.ErrMissedArgument, "selector aggregators") 49 } 50 51 return &CollectAggregateSelector{variable, aggr, reducer}, nil 52 } 53 54 func (selector *CollectAggregateSelector) Variable() string { 55 return selector.variable 56 } 57 58 func (selector *CollectAggregateSelector) Expression() core.Function { 59 return selector.reducer 60 } 61 62 func (selector *CollectAggregateSelector) Aggregators() []core.Expression { 63 return selector.aggregators 64 }