aggregation

package
v1.0.0-beta.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(input jsoniter.RawMessage) (expression.Expr, error)

Unmarshal to unmarshal an aggregation object.

func UnmarshalAggObject

func UnmarshalAggObject(input jsoniter.RawMessage) (expression.Expr, error)

UnmarshalAggObject unmarshal the input to the aggregation. Note the return after the first check, this is mainly because an aggregation object can have nested objects but top level it will be one expression.

Types

type AccumulatorFactory

type AccumulatorFactory struct {
	Avg *AccumulatorOp `json:"$avg,omitempty"`
	Min *AccumulatorOp `json:"$min,omitempty"`
	Max *AccumulatorOp `json:"$max,omitempty"`
	Sum *AccumulatorOp `json:"$sum,omitempty"`
}

AccumulatorFactory to return the object of the accumulator type.

func (*AccumulatorFactory) Get

type AccumulatorOp

type AccumulatorOp struct {
	Type string
	Agg  expression.Expr
}

AccumulatorOp is a type of aggregation that can also be use in the group by to group values into subsets.

func (*AccumulatorOp) Apply

func (a *AccumulatorOp) Apply(document jsoniter.RawMessage)

func (*AccumulatorOp) String

func (a *AccumulatorOp) String() string

func (*AccumulatorOp) UnmarshalJSON

func (a *AccumulatorOp) UnmarshalJSON(input []byte) error

type Aggregation

type Aggregation interface {
	Apply(document jsoniter.RawMessage)
}

Aggregation operators either can pass a single expression or an array of expression. The below is an example of how a caller can pass aggregation,

{ $aggregation: <expression> }

OR

{ $aggregation: [ <expression1>, <expression2> ... ] }

As an example, for sum across two fields the grammar would be,

{
	"$sum": {
		"$multiply": ["$price", "$quantity"]
	}
}

More examples,

{
	"$sum": "$qty"
}

{ "$sum": [ "$final", "$midterm" ] }}.

type ArithmeticFactory

type ArithmeticFactory struct {
	Add      *ArithmeticOp `json:"$add,omitempty"`
	Multiply *ArithmeticOp `json:"$multiply,omitempty"`
}

ArithmeticFactory to return the object of the arithmeticOp type.

func (*ArithmeticFactory) Get

func (a *ArithmeticFactory) Get() Aggregation

type ArithmeticOp

type ArithmeticOp struct {
	Type string
	Agg  expression.Expr
}

func (*ArithmeticOp) Apply

func (a *ArithmeticOp) Apply(document jsoniter.RawMessage)

func (*ArithmeticOp) String

func (a *ArithmeticOp) String() string

func (*ArithmeticOp) UnmarshalJSON

func (a *ArithmeticOp) UnmarshalJSON(input []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL