1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-21 01:21:34 +02:00
ferret/pkg/runtime/expressions/clauses/collect_selector.go
Tim Voronov 549b4abd3b
Feature/#5 collect keyword alt (#141)
Implemented COLLECT key word
2018-10-24 21:30:05 -04:00

65 lines
1.5 KiB
Go

package clauses
import "github.com/MontFerret/ferret/pkg/runtime/core"
type (
CollectSelector struct {
variable string
expression core.Expression
}
CollectAggregateSelector struct {
variable string
aggregators []core.Expression
reducer core.Function
}
)
func NewCollectSelector(variable string, exp core.Expression) (*CollectSelector, error) {
if variable == "" {
return nil, core.Error(core.ErrMissedArgument, "selector variable")
}
if exp == nil {
return nil, core.Error(core.ErrMissedArgument, "selector reducer")
}
return &CollectSelector{variable, exp}, nil
}
func (selector *CollectSelector) Variable() string {
return selector.variable
}
func (selector *CollectSelector) Expression() core.Expression {
return selector.expression
}
func NewCollectAggregateSelector(variable string, aggr []core.Expression, reducer core.Function) (*CollectAggregateSelector, error) {
if variable == "" {
return nil, core.Error(core.ErrMissedArgument, "selector variable")
}
if reducer == nil {
return nil, core.Error(core.ErrMissedArgument, "selector reducer")
}
if aggr == nil {
return nil, core.Error(core.ErrMissedArgument, "selector aggregators")
}
return &CollectAggregateSelector{variable, aggr, reducer}, nil
}
func (selector *CollectAggregateSelector) Variable() string {
return selector.variable
}
func (selector *CollectAggregateSelector) Expression() core.Function {
return selector.reducer
}
func (selector *CollectAggregateSelector) Aggregators() []core.Expression {
return selector.aggregators
}