aggregations

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package aggregations provides aggregation pipelines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPushdownQuery added in v0.9.4

func GetPushdownQuery(stagesDocs []any) (match *types.Document, sort *types.Document)

GetPushdownQuery gets pushdown query ($match and $sort) for aggregation.

If the first two stages are either $match, $sort, or a combination of them, we can push them down. In this case, we return the first match and sort statements to pushdown. If $match stage is not present, match is returned as nil. If $sort stage is not present, sort is returned as nil.

func SumNumbers added in v1.7.0

func SumNumbers(vs ...any) any

SumNumbers accumulate numbers and returns the result of summation. The result has the same type as the input, except when the result cannot be presented accurately. Then int32 is converted to int64, and int64 is converted to float64. It ignores non-number values. For empty `vs`, it returns int32(0). This should only be used for aggregation, aggregation does not return error on overflow.

Types

type Expression added in v1.2.0

type Expression struct {
	*ExpressionOpts
	// contains filtered or unexported fields
}

Expression is an expression constructed from field value.

func NewExpression added in v1.2.0

func NewExpression(expression string) (*Expression, error)

NewExpression creates a new instance by checking expression string.

func NewExpressionWithOpts added in v1.2.0

func NewExpressionWithOpts(expression string, opts *ExpressionOpts) (*Expression, error)

NewExpressionWithOpts creates a new instance by checking expression string. It can take additional opts that specify how expressions should be evaluated.

func (*Expression) Evaluate added in v1.2.0

func (e *Expression) Evaluate(doc *types.Document) (any, error)

Evaluate gets the value at the path. It returns error if the path does not exists.

func (*Expression) GetExpressionSuffix added in v1.2.0

func (e *Expression) GetExpressionSuffix() string

GetExpressionSuffix returns suffix of pathExpression.

type ExpressionError added in v1.2.0

type ExpressionError struct {
	// contains filtered or unexported fields
}

ExpressionError describes an error that occurs while evaluating expression.

func (*ExpressionError) Code added in v1.2.0

Code returns the ExpressionError code.

func (*ExpressionError) Error added in v1.2.0

func (e *ExpressionError) Error() string

Error implements the error interface.

type ExpressionErrorCode added in v1.2.0

type ExpressionErrorCode int

ExpressionErrorCode represents Expression error code.

const (

	// ErrNotExpression indicates that field is not an expression.
	ErrNotExpression ExpressionErrorCode

	// ErrInvalidExpression indicates that expression is invalid.
	ErrInvalidExpression

	// ErrEmptyFieldPath indicates that field path expression is empty.
	ErrEmptyFieldPath

	// ErrUndefinedVariable indicates that variable name is not defined.
	ErrUndefinedVariable

	// ErrEmptyVariable indicates that variable name is empty.
	ErrEmptyVariable
)

func (ExpressionErrorCode) String added in v1.2.0

func (i ExpressionErrorCode) String() string

type ExpressionOpts added in v1.2.0

type ExpressionOpts struct {

	// IgnoreArrays disables checking arrays for provided key.
	// So expression {"$v.foo"} won't match {"v":[{"foo":42}]}
	IgnoreArrays bool // defaults to false
}

ExpressionOpts represents options used to modify behavior of Expression functions.

type Stage

type Stage interface {
	// Process applies an aggregate stage on documents from iterator.
	Process(ctx context.Context, iter types.DocumentsIterator, closer *iterator.MultiCloser) (types.DocumentsIterator, error)
}

Stage is a common interface for all aggregation stages.

Directories

Path Synopsis
Package operators provides aggregation operators.
Package operators provides aggregation operators.
accumulators
Package accumulators provides aggregation accumulator operators.
Package accumulators provides aggregation accumulator operators.
Package stages provides aggregation stages.
Package stages provides aggregation stages.
projection
Package projection provides projection for aggregations.
Package projection provides projection for aggregations.

Jump to

Keyboard shortcuts

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